fix: remove recipes
This commit is contained in:
Binary file not shown.
@@ -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) -> {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Recipe> getEntries(CraftingDataPacket self) {return null;}
|
||||
|
||||
@Inject
|
||||
public static void addShapelessRecipe(CraftingDataPacket self, ShapelessRecipe[] recipes) {
|
||||
final List<Recipe> 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<Recipe> entries = getEntries(self);
|
||||
|
||||
for(ShapedRecipe recipe : recipes)
|
||||
if(!NativeWorkbench.canRemoveRecipe(recipe.getId()))
|
||||
entries.add(recipe);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<UUID> 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<Recipe> 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<Recipe> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user