diff --git a/src/main/java/com/reider745/commands/TpsCommand.java b/src/main/java/com/reider745/commands/TpsCommand.java index 6926a79d..d63eab15 100644 --- a/src/main/java/com/reider745/commands/TpsCommand.java +++ b/src/main/java/com/reider745/commands/TpsCommand.java @@ -3,9 +3,12 @@ package com.reider745.commands; import cn.nukkit.command.Command; import cn.nukkit.command.CommandSender; +import java.util.Arrays; + public class TpsCommand extends Command { public static long[] innerCoreTimes = new long[20]; public static long[] nukkitTimes = new long[20]; + public TpsCommand() { super("tps"); } @@ -15,29 +18,36 @@ public class TpsCommand extends Command { if(!commandSender.isOp()) return false; - long innerCoreSum = 0; - for(long time : innerCoreTimes) - if(time != 0) - innerCoreSum += Math.min(20, 1000 / time); - else{ - commandSender.sendMessage("Not enough information"); - return true; - } + try{ + float aboba1 = 0, aboba2 = 0; + long innerCoreSum = 0; + for(long time : innerCoreTimes) + if(time != 0) { + innerCoreSum += Math.min(20, 1000 / time); + aboba1++; + } - long nukkitSum = 0; - for(long time : nukkitTimes) - if(time != 0) - nukkitSum += Math.min(20, 1000 / time); - else{ - commandSender.sendMessage("Not enough information"); - return true; - } + long nukkitSum = 0; + for(long time : nukkitTimes) + if(time != 0) { + nukkitSum += Math.min(20, 1000 / time); + aboba2++; + } - if(innerCoreSum != 0 && nukkitSum != 0) { - commandSender.sendMessage("Inner core tps: " + (innerCoreSum / 20.0f)); - commandSender.sendMessage("Nukkit tps: " + (nukkitSum / 20.0f)); - }else + if(innerCoreSum != 0) + commandSender.sendMessage("Inner core tps: " + (innerCoreSum / aboba1)); + else + commandSender.sendMessage("Inner core tps: 20.0"); + + if(nukkitSum != 0) + commandSender.sendMessage("Nukkit tps: " + (nukkitSum / aboba2)); + else + commandSender.sendMessage("Nukkit tps: 20.0"); + }catch (Exception e){ commandSender.sendMessage("Not enough information"); + commandSender.sendMessage(Arrays.toString(innerCoreTimes)); + commandSender.sendMessage(Arrays.toString(nukkitTimes)); + } return true; } diff --git a/src/main/java/com/reider745/hooks/ServerHooks.java b/src/main/java/com/reider745/hooks/ServerHooks.java index 9d713f7d..d42795d1 100644 --- a/src/main/java/com/reider745/hooks/ServerHooks.java +++ b/src/main/java/com/reider745/hooks/ServerHooks.java @@ -76,10 +76,11 @@ public class ServerHooks implements HookClass { } private static long start_pre = 0; + private static int indexTime = 0; @Inject public static void checkTickUpdates(Server server, int tick) { - int indexTime = server.getTick() % 20; + indexTime = (indexTime + 1) % 20; TpsCommand.nukkitTimes[indexTime] = System.currentTimeMillis() - start_pre; try { diff --git a/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java b/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java index adb1c265..75e4ec62 100644 --- a/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java +++ b/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java @@ -158,11 +158,16 @@ public class NativeWorkbench { if (accepted) { craftingManager.registerRecipe(InnerCoreServer.RECIPES_PROTOCOL, new ShapelessRecipe(result, ingredients)); } + + if(NativeWorkbench.craftingManager != null) + craftingManager.rebuildPacket(); } } } private static final ArrayList recipes = new ArrayList<>(); + private static RuntimeItemMapping runtimeItemMapping = null; + private static CraftingManager craftingManager = null; private static void addShapedRecipe(int resultId, int resultCount, int resultData, NativeItemInstanceExtra resultExtra, String[] pattern, int[] ingredients) { @@ -174,7 +179,12 @@ public class NativeWorkbench { final HashMap ingredients_ = new HashMap<>(); for (int i = 0; i < ingredients.length; i += 3) ingredients_.put((char) ingredients[i], new ItemStack(ingredients[i + 1], 1, ingredients[i + 2])); - recipes.add(new RecipeRegistry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_)); + + final RecipeRegistry recipe = new RecipeRegistry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_); + if(craftingManager != null) + recipe.apply(runtimeItemMapping, craftingManager); + else + recipes.add(recipe); } public static void addShapedRecipe(ItemStack result, String[] pattern, int[] ingredients) { @@ -188,7 +198,11 @@ public class NativeWorkbench { return; } - recipes.add(new RecipeRegistry(resultId, resultCount, resultData, resultExtra, ingredients)); + final RecipeRegistry recipe = new RecipeRegistry(resultId, resultCount, resultData, resultExtra, ingredients); + if(craftingManager != null) + recipe.apply(runtimeItemMapping, craftingManager); + else + recipes.add(recipe); } public static void addShapelessRecipe(ItemStack result, int[] ingredients) { @@ -197,16 +211,21 @@ public class NativeWorkbench { public static void removeRecipeByResult(int resultId, int resultCount, int resultData) { - recipes.add(new RecipeRemove(resultId, resultCount, resultData)); + final RecipeRemove recipe = new RecipeRemove(resultId, resultCount, resultData); + if(craftingManager != null) + recipe.apply(runtimeItemMapping, craftingManager); + else + recipes.add(recipe); } public static void init() { - final RuntimeItemMapping mapping = RuntimeItems.getMapping(InnerCoreServer.PROTOCOL); + runtimeItemMapping = RuntimeItems.getMapping(InnerCoreServer.PROTOCOL); final CraftingManager craftingManager = Server.getInstance().getCraftingManager(); for (IApply recipe : recipes) - recipe.apply(mapping, craftingManager); + recipe.apply(runtimeItemMapping, craftingManager); recipes.clear(); craftingManager.rebuildPacket(); + NativeWorkbench.craftingManager = craftingManager; } } diff --git a/src/main/resources/zotecore.yml b/src/main/resources/zotecore.yml index 3cdba55d..68fd3def 100644 --- a/src/main/resources/zotecore.yml +++ b/src/main/resources/zotecore.yml @@ -6,7 +6,7 @@ pack-version-code: 160 # Sets the list of mods and configs to load, you can specify # name, folder name of a modpack from /modpacks or a path. -# modpack: StoneBlock +# modpack: LoveZote # Use vanilla crafting table interface, instead of custom one. # Attention: currently not recommended and recipes dislayed with bugs.