diff --git a/iclibs/Nukkit-MOT-SNAPSHOT.jar b/iclibs/Nukkit-MOT-SNAPSHOT.jar index 49ab9041..a931edd4 100644 Binary files a/iclibs/Nukkit-MOT-SNAPSHOT.jar and b/iclibs/Nukkit-MOT-SNAPSHOT.jar differ diff --git a/src/main/java/com/reider745/Main.java b/src/main/java/com/reider745/Main.java index 1d5181c6..6f385e26 100644 --- a/src/main/java/com/reider745/Main.java +++ b/src/main/java/com/reider745/Main.java @@ -111,7 +111,6 @@ public class Main { add("com.reider745.hooks.AndroidHooks"); add("com.reider745.hooks.GlobalBanList"); add("com.reider745.hooks.network.NetworkHooks"); - add("com.reider745.hooks.network.CraftingDataPacketHooks"); add("com.reider745.hooks.world.LevelHooks"); add("com.reider745.hooks.world.BiomesHooks"); loader.addRebuildField("com.reider745.hooks.world.LevelHooks", (ctClass, field) -> { diff --git a/src/main/java/com/reider745/event/EventListener.java b/src/main/java/com/reider745/event/EventListener.java index c48d8e80..07006d8f 100644 --- a/src/main/java/com/reider745/event/EventListener.java +++ b/src/main/java/com/reider745/event/EventListener.java @@ -531,11 +531,7 @@ public class EventListener implements Listener { int inventorySize = (int) Math.sqrt(grid.getSize()); if(player.craftingType == Player.CRAFTING_SMALL || player.craftingType == Player.CRAFTING_BIG) { - if (!NativeWorkbench.canRemoveRecipe(event.getTransaction().getRecipe().getId())) - consumeEvent(event, () -> NativeCallback.onWorkbenchCraft(grid, playerUid, inventorySize)); - else { - event.setCancelled(); - } + consumeEvent(event, () -> NativeCallback.onWorkbenchCraft(grid, playerUid, inventorySize)); } } diff --git a/src/main/java/com/reider745/hooks/network/CraftingDataPacketHooks.java b/src/main/java/com/reider745/hooks/network/CraftingDataPacketHooks.java deleted file mode 100644 index 21d4fa37..00000000 --- a/src/main/java/com/reider745/hooks/network/CraftingDataPacketHooks.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.reider745.hooks.network; - -import cn.nukkit.network.protocol.CraftingDataPacket; -import cn.nukkit.recipe.Recipe; -import cn.nukkit.recipe.impl.ShapedRecipe; -import cn.nukkit.recipe.impl.ShapelessRecipe; -import com.reider745.api.hooks.annotation.Hooks; -import com.reider745.api.hooks.annotation.Inject; -import com.reider745.api.hooks.annotation.ShadowGetField; -import com.zhekasmirnov.apparatus.mcpe.NativeWorkbench; - -import java.util.List; - -@Hooks(className = "cn.nukkit.network.protocol.CraftingDataPacket") -public class CraftingDataPacketHooks { - @ShadowGetField(field = "entries") - public static List getEntries(CraftingDataPacket self) {return null;} - - @Inject - public static void addShapelessRecipe(CraftingDataPacket self, ShapelessRecipe[] recipes) { - final List entries = getEntries(self); - - for(ShapelessRecipe recipe : recipes) - if(!NativeWorkbench.canRemoveRecipe(recipe.getId())) - entries.add(recipe); - } - - @Inject - public static void addShapedRecipe(CraftingDataPacket self, ShapedRecipe[] recipes) { - final List entries = getEntries(self); - - for(ShapedRecipe recipe : recipes) - if(!NativeWorkbench.canRemoveRecipe(recipe.getId())) - entries.add(recipe); - } -} diff --git a/src/main/java/com/reider745/network/CraftingTransactionPacket.java b/src/main/java/com/reider745/network/CraftingTransactionPacket.java index db36718b..9605847e 100644 --- a/src/main/java/com/reider745/network/CraftingTransactionPacket.java +++ b/src/main/java/com/reider745/network/CraftingTransactionPacket.java @@ -17,19 +17,10 @@ public class CraftingTransactionPacket implements HookClass { @Inject(type = TypeHook.BEFORE_REPLACE) public static void sendInventories(CraftingTransaction transaction) { - if (transaction.getSource().protocol >= ProtocolInfo.v1_16_0) { - for (InventoryAction action : transaction.getActionList()) { - if (action instanceof SlotChangeAction) { - SlotChangeAction sca = (SlotChangeAction) action; - sca.getInventory().sendSlot(sca.getSlot(), transaction.getSource()); - } - } - } else { - for (Inventory inventory : transaction.getInventories()) { - inventory.sendContents(transaction.getSource()); - if (inventory instanceof PlayerInventory) { - ((PlayerInventory) inventory).sendArmorContents(transaction.getSource()); - } + for (InventoryAction action : transaction.getActionList()) { + if (action instanceof SlotChangeAction) { + SlotChangeAction sca = (SlotChangeAction) action; + sca.getInventory().sendSlot(sca.getSlot(), transaction.getSource()); } } } diff --git a/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java b/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java index fa9bd63b..b3a2ceb1 100644 --- a/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java +++ b/src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java @@ -1,6 +1,5 @@ package com.zhekasmirnov.apparatus.mcpe; -import cn.nukkit.Server; import cn.nukkit.item.Item; import cn.nukkit.item.RuntimeItemMapping; import cn.nukkit.item.RuntimeItems; @@ -18,10 +17,7 @@ import com.reider745.hooks.item.ItemUtils; import com.zhekasmirnov.apparatus.adapter.innercore.game.item.ItemStack; import com.zhekasmirnov.horizon.runtime.logger.Logger; import com.zhekasmirnov.innercore.api.NativeItemInstanceExtra; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.mozilla.javascript.StackStyle; -import java.lang.reflect.Method; import java.util.*; public class NativeWorkbench { @@ -34,13 +30,8 @@ public class NativeWorkbench { } } - private static final List removedRecipes = new ObjectArrayList<>(); private static boolean isFinalLoad = false; - public static boolean canRemoveRecipe(UUID uuid){ - return removedRecipes.contains(uuid); - } - private static class RecipeRemove implements IApply { public int resultId, resultCount, resultData; @@ -50,26 +41,21 @@ public class NativeWorkbench { this.resultData = resultData; } - private static Collection getRecipes(){ - return ReflectHelper.getField(RecipeRegistry.class, "RECIPES"); - } - @Override public IApply apply(RuntimeItemMapping mapping) { final Item itemInstance = ItemUtils.get(this.resultId, this.resultCount, this.resultData); - final Collection recipes = getRecipes(); - boolean removeRecipe = false; - for(Recipe recipe : recipes){ + UUID recipeUuid = null; + for(Recipe recipe : RecipeRegistry.getRecipes()){ if(recipe instanceof CraftingRecipe craftingRecipe && recipe.getResult().equals(itemInstance)){ - removedRecipes.add(craftingRecipe.getId()); - removeRecipe = true; - break; + recipeUuid = craftingRecipe.getId(); } } - if(!removeRecipe) + if(recipeUuid == null || !RecipeRegistry.removeRecipe(recipeUuid)){ Logger.warning("Not remove recipe " + itemInstance); + } + return this; } }