From 48dd7bedeade6e7d4c7f1f3d315448c729a339fd Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 10 Feb 2025 02:44:28 -0500 Subject: [PATCH] New Anvil Recipe System --- src/api | 2 +- .../npcs/controllers/SyncController.java | 42 +++ .../npcs/network/enums/EnumSyncType.java | 3 +- .../request/recipe/RecipeGetPacket.java | 16 +- .../request/recipe/RecipeRemovePacket.java | 22 +- .../request/recipe/RecipeSavePacket.java | 14 +- .../java/noppes/npcs/NoppesUtilServer.java | 23 +- .../gui/global/GuiNpcManageRecipes.java | 262 ++++++++++++++---- .../client/gui/player/GuiAnvilRecipes.java | 102 +++++-- .../npcs/containers/ContainerAnvilRepair.java | 24 +- .../containers/ContainerManageRecipes.java | 204 ++++++++------ .../npcs/controllers/RecipeController.java | 6 +- .../npcs/controllers/data/RecipeAnvil.java | 68 ++++- .../controllers/data/RecipeCarpentry.java | 17 +- .../assets/customnpcs/lang/en_US.lang | 8 +- 15 files changed, 592 insertions(+), 221 deletions(-) diff --git a/src/api b/src/api index 17d165e62..f91f9b43b 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 17d165e62846b73b13f82af0e93b84704db4e11a +Subproject commit f91f9b43ba47a6bc1f6970537792b3b8ce49f4b8 diff --git a/src/main/java/kamkeel/npcs/controllers/SyncController.java b/src/main/java/kamkeel/npcs/controllers/SyncController.java index a98a10755..b7a77c83e 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncController.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncController.java @@ -62,6 +62,13 @@ public class SyncController { carpentryNBT() ), player); + PacketHandler.Instance.sendToPlayer(new SyncPacket( + EnumSyncType.ANVIL_RECIPES, + EnumSyncAction.RELOAD, + -1, + anvilNBT() + ), player); + DBCAddon.instance.syncPlayer(player); syncPlayerData(player, false); } @@ -88,6 +95,17 @@ public class SyncController { return compound; } + public static NBTTagCompound anvilNBT(){ + RecipeController controller = RecipeController.Instance; + NBTTagList list = new NBTTagList(); + NBTTagCompound compound = new NBTTagCompound(); + for(RecipeAnvil recipe : controller.anvilRecipes.values()){ + list.appendTag(recipe.writeNBT()); + } + compound.setTag("recipes", list); + return compound; + } + public static NBTTagCompound factionsNBT(){ NBTTagList list = new NBTTagList(); NBTTagCompound compound = new NBTTagCompound(); @@ -201,6 +219,15 @@ public class SyncController { )); } + public static void syncAllAnvilRecipes() { + PacketHandler.Instance.sendToAll(new SyncPacket( + EnumSyncType.ANVIL_RECIPES, + EnumSyncAction.RELOAD, + -1, + anvilNBT() + )); + } + @SideOnly(Side.CLIENT) public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) { switch (enumSyncType){ @@ -325,6 +352,21 @@ public class SyncController { RecipeController.syncRecipes = new HashMap(); break; } + case ANVIL_RECIPES: { + NBTTagList list = fullCompound.getTagList("recipes", 10); + if(list == null) + return; + + for(int i = 0; i < list.tagCount(); i++) + { + RecipeAnvil recipe = RecipeAnvil.read(list.getCompoundTagAt(i)); + RecipeController.syncAnvilRecipes.put(recipe.id, recipe); + } + + RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes; + RecipeController.syncAnvilRecipes = new HashMap(); + break; + } } } diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java b/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java index e573f5346..6d9ba1d34 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java @@ -9,5 +9,6 @@ public enum EnumSyncType { PLAYERDATA, MAGIC, WORKBENCH_RECIPES, - CARPENTRY_RECIPES + CARPENTRY_RECIPES, + ANVIL_RECIPES, } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeGetPacket.java index 16f52b62b..8f5eaf57d 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeGetPacket.java @@ -13,6 +13,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import java.io.IOException; @@ -21,9 +22,11 @@ public final class RecipeGetPacket extends AbstractPacket { public static String packetName = "Request|RecipeGet"; private int recipeId; + private boolean isAnvil = false; - public RecipeGetPacket(int recipeId) { + public RecipeGetPacket(int recipeId, boolean anvil) { this.recipeId = recipeId; + this.isAnvil = anvil; } public RecipeGetPacket() {} @@ -43,6 +46,7 @@ public final class RecipeGetPacket extends AbstractPacket { @Override public void sendData(ByteBuf out) throws IOException { out.writeInt(recipeId); + out.writeBoolean(this.isAnvil); } @Override @@ -52,7 +56,13 @@ public final class RecipeGetPacket extends AbstractPacket { if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player)) return; int id = in.readInt(); - RecipeCarpentry recipe = RecipeController.Instance.getRecipe(id); - NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe); + boolean anvil = in.readBoolean(); + if(anvil){ + RecipeAnvil recipe = RecipeController.Instance.getAnvilRecipe(id); + NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, recipe); + } else { + RecipeCarpentry recipe = RecipeController.Instance.getRecipe(id); + NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe); + } } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeRemovePacket.java index cd8ab6136..0df707054 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeRemovePacket.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import java.io.IOException; @@ -22,13 +23,14 @@ public final class RecipeRemovePacket extends AbstractPacket { public static String packetName = "Request|RecipeRemove"; private int recipeId; + private boolean isAnvil; - public RecipeRemovePacket(int recipeId) { + public RecipeRemovePacket(int recipeId, boolean isAnvil) { this.recipeId = recipeId; + this.isAnvil = isAnvil; } - public RecipeRemovePacket() { - } + public RecipeRemovePacket() {} @Override public Enum getType() { @@ -49,6 +51,7 @@ public final class RecipeRemovePacket extends AbstractPacket { @Override public void sendData(ByteBuf out) throws IOException { out.writeInt(recipeId); + out.writeBoolean(isAnvil); } @Override @@ -58,8 +61,15 @@ public final class RecipeRemovePacket extends AbstractPacket { if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player)) return; int id = in.readInt(); - RecipeCarpentry recipe = RecipeController.Instance.delete(id); - NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4); - NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, new RecipeCarpentry("")); + boolean anvil = in.readBoolean(); + if(anvil){ + RecipeAnvil recipe = RecipeController.Instance.deleteAnvil(id); + NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, 1); + NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, new RecipeAnvil()); + } else { + RecipeCarpentry recipe = RecipeController.Instance.delete(id); + NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4); + NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, new RecipeCarpentry("")); + } } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeSavePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeSavePacket.java index 5e5719810..cc6f69d87 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeSavePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/recipe/RecipeSavePacket.java @@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import java.io.IOException; @@ -58,9 +59,16 @@ public final class RecipeSavePacket extends AbstractPacket { return; if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player)) return; + NBTTagCompound compound = ByteBufUtils.readNBT(in); - RecipeCarpentry recipe = RecipeController.Instance.saveRecipe(compound); - NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4); - NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe); + if(compound.hasKey("IsAnvil")){ + RecipeAnvil recipe = RecipeController.Instance.saveAnvilRecipe(compound); + NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, 1); + NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, recipe); + } else { + RecipeCarpentry recipe = RecipeController.Instance.saveRecipe(compound); + NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4); + NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe); + } } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 3b4ddfbfd..1794d3ec0 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -592,11 +592,15 @@ public class NoppesUtilServer { for(RecipeCarpentry recipe : RecipeController.Instance.globalRecipes.values()){ map.put(recipe.name, recipe.id); } - } + } else if (size == 4){ + for(RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()){ + map.put(recipe.name, recipe.id); + } + } else{ - for(RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()){ - map.put(recipe.name, recipe.id); - } + for(RecipeAnvil recipe : RecipeController.Instance.anvilRecipes.values()){ + map.put(recipe.name, recipe.id); + } } sendScrollData(player, map); } @@ -730,6 +734,17 @@ public class NoppesUtilServer { GuiDataPacket.sendGuiData((EntityPlayerMP)player, recipe.writeNBT()); } + public static void setRecipeAnvilGui(EntityPlayerMP player, RecipeAnvil recipe){ + if(recipe == null) + return; + if(!(player.openContainer instanceof ContainerManageRecipes)) + return; + + ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer; + container.setRecipe(recipe); + GuiDataPacket.sendGuiData((EntityPlayerMP)player, recipe.writeNBT()); + } + public static void sendBank(EntityPlayerMP player,Bank bank) { NBTTagCompound compound = new NBTTagCompound(); bank.writeEntityToNBT(compound); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java index 6fc87a9d0..cae37149e 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java @@ -9,11 +9,14 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.containers.ContainerManageRecipes; +import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; @@ -23,9 +26,10 @@ import java.util.HashMap; import java.util.List; import java.util.Vector; -public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IScrollData, IGuiData, ICustomScrollListener,ITextfieldListener{ - private GuiCustomScroll scroll; - private HashMap data = new HashMap(); +public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IScrollData, IGuiData, ICustomScrollListener, ITextfieldListener, ISubGuiListener { + public static int tab = 1; + public GuiCustomScroll scroll; + public HashMap data = new HashMap(); private ContainerManageRecipes container; private String selected = null; private ResourceLocation slot; @@ -39,6 +43,7 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS setBackground("inventorymenu.png"); slot = getResource("slot.png"); ySize = 200; + tab = 1; } @Override @@ -47,49 +52,91 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS if(scroll == null) scroll = new GuiCustomScroll(this,0,0); - scroll.setSize(130, 180); - scroll.guiLeft = guiLeft + 172; - scroll.guiTop = guiTop + 8; + scroll.setSize(130, 150); + scroll.guiLeft = guiLeft + 280; + scroll.guiTop = guiTop + 38; addScroll(scroll); - this.addButton(new GuiNpcButton(0,guiLeft + 306, guiTop + 10, 84, 20, "menu.global")); - this.addButton(new GuiNpcButton(1,guiLeft + 306, guiTop + 32, 84, 20, "tile.npcCarpentyBench.name")); - this.getButton(0).setEnabled(container.width == 4); - this.getButton(1).setEnabled(container.width == 3); + int y = guiTop + 10; - this.addButton(new GuiNpcButton(3,guiLeft + 306, guiTop + 60, 84, 20, "gui.add")); - this.addButton(new GuiNpcButton(4,guiLeft + 306, guiTop + 82, 84, 20, "gui.remove")); + this.addButton(new GuiButtonBiDirectional(0,guiLeft + 280, y, 130, 20, new String[]{"menu.global", "tile.npcCarpentyBench.name", "tile.anvil.name"}, tab)); - this.addLabel(new GuiNpcLabel(0, "gui.ignoreDamage", guiLeft + 86, guiTop + 32)); - this.addButton(new GuiNpcButtonYesNo(5,guiLeft + 114, guiTop + 40, 50, 20, container.recipe.ignoreDamage)); + y+= 106; - this.addLabel(new GuiNpcLabel(1, "gui.ignoreNBT", guiLeft + 86, guiTop + 82)); - this.addButton(new GuiNpcButtonYesNo(6,guiLeft + 114, guiTop + 90, 50, 20, container.recipe.ignoreNBT)); + this.addButton(new GuiNpcButton(3,guiLeft + 226, y += 22, 50, 20, "gui.add")); + this.addButton(new GuiNpcButton(4,guiLeft + 226, y += 22, 50, 20, "gui.remove")); + this.addButton(new GuiNpcButton(10,guiLeft + 226, y += 30, 50, 20, "gui.copy")); - this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); - this.getTextField(0).enabled = false; - this.getButton(5).setEnabled(false); - this.getButton(6).setEnabled(false); + if (container.width != 1) { + int buttonPos = guiTop + 72; + this.addLabel(new GuiNpcLabel(0, "gui.ignoreDamage", guiLeft + 131, buttonPos)); + this.addButton(new GuiNpcButtonYesNo(5, guiLeft + 235, buttonPos - 5, 40, 20, container.recipe.ignoreDamage)); + this.addLabel(new GuiNpcLabel(1, "gui.ignoreNBT", guiLeft + 131, buttonPos += 22)); + this.addButton(new GuiNpcButtonYesNo(6, guiLeft + 235, buttonPos - 5, 40, 20, container.recipe.ignoreNBT)); + this.getButton(5).setEnabled(false); + this.getButton(6).setEnabled(false); - this.addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 172, guiTop + 8 + 3 + 180, 130, 20, search)); + this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); + this.getTextField(0).enabled = false; + } else { + int buttonPos = guiTop + 50; + this.addLabel(new GuiNpcLabel(0, "gui.ignoreMatDamage", guiLeft + 131, buttonPos)); + this.addButton(new GuiNpcButtonYesNo(7, guiLeft + 235, buttonPos - 5, 40, 20, container.recipeAnvil.ignoreRepairMaterialDamage)); + + + this.addLabel(new GuiNpcLabel(1, "gui.ignoreMatNBT", guiLeft + 131, buttonPos += 22)); + this.addButton(new GuiNpcButtonYesNo(8, guiLeft + 235, buttonPos - 5, 40, 20, container.recipeAnvil.ignoreRepairMaterialNBT)); + + this.addLabel(new GuiNpcLabel(11, "gui.repairPercent", guiLeft + 8, buttonPos)); + this.addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 90, buttonPos - 5, 35, 20, container.recipeAnvil.getRepairPercentage() + "")); + this.getTextField(1).floatsOnly = true; + this.getTextField(1).setMinMaxDefaultFloat(1, 100, container.recipeAnvil.getRepairPercentage()); + this.getTextField(1).enabled = false; + + this.addLabel(new GuiNpcLabel(2, "gui.ignoreItemNBT", guiLeft + 131, buttonPos += 22)); + this.addButton(new GuiNpcButtonYesNo(9, guiLeft + 235, buttonPos - 5, 40, 20, container.recipeAnvil.ignoreRepairItemNBT)); + + this.addLabel(new GuiNpcLabel(12, "gui.xpCost", guiLeft + 8, buttonPos)); + this.addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 70, buttonPos - 5, 55, 20, container.recipeAnvil.getXpCost() + "")); + this.getTextField(2).integersOnly = true; + this.getTextField(2).setMinMaxDefault(0, Integer.MAX_VALUE, container.recipeAnvil.getXpCost()); + this.getTextField(2).enabled = false; + + this.getButton(7).setEnabled(false); + this.getButton(8).setEnabled(false); + this.getButton(9).setEnabled(false); + + this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipeAnvil.name)); + this.getTextField(0).enabled = false; + } + this.addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 280, guiTop + 8 + 3 + 180, 130, 20, search)); } @Override protected void actionPerformed(GuiButton guibutton){ GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0){ - getTextField(55).setText(""); - search = ""; - scroll.clear(); - save(); - NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,3,0,0); - } - if(button.id == 1){ - getTextField(55).setText(""); - search = ""; - scroll.clear(); - save(); - NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,4,0,0); + GuiButtonBiDirectional buttonBiDirectional = (GuiButtonBiDirectional) button; + tab = buttonBiDirectional.getValue(); + if(tab == 0){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); + save(); + NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,3,0,0); + } else if (tab == 1){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); + save(); + NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,4,0,0); + } else { + getTextField(55).setText(""); + search = ""; + scroll.clear(); + save(); + NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,1,0,0); + } } if(button.id == 3){ save(); @@ -97,13 +144,21 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS String name = "New"; while(data.containsKey(name)) name += "_"; - RecipeCarpentry recipe = new RecipeCarpentry(name); - recipe.isGlobal = container.width == 3; - PacketClient.sendClient(new RecipeSavePacket(recipe.writeNBT())); + + if(container.width == 1){ + RecipeAnvil recipe = new RecipeAnvil(); + recipe.name = name; + PacketClient.sendClient(new RecipeSavePacket(recipe.writeNBT())); + } + else { + RecipeCarpentry recipe = new RecipeCarpentry(name); + recipe.isGlobal = container.width == 3; + PacketClient.sendClient(new RecipeSavePacket(recipe.writeNBT())); + } } if(button.id == 4){ if(data.containsKey(scroll.getSelected())){ - PacketClient.sendClient(new RecipeRemovePacket(data.get(scroll.getSelected()))); + PacketClient.sendClient(new RecipeRemovePacket(data.get(scroll.getSelected()), container.width == 1)); scroll.clear(); } } @@ -113,6 +168,15 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS if(button.id == 6){ container.recipe.ignoreNBT = button.getValue() == 1; } + if (button.id == 7) { + container.recipeAnvil.ignoreRepairMaterialDamage = button.getValue() == 1; + } + if (button.id == 8) { + container.recipeAnvil.ignoreRepairMaterialNBT = button.getValue() == 1; + } + if (button.id == 9) { + container.recipeAnvil.ignoreRepairItemNBT = button.getValue() == 1; + } } @Override @@ -142,18 +206,49 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS return list; } - @Override - public void setGuiData(NBTTagCompound compound) { - RecipeCarpentry recipe = RecipeCarpentry.read(compound); - getTextField(0).setText(recipe.name); - container.setRecipe(recipe); - this.getTextField(0).enabled = true; - this.getButton(5).setEnabled(true); - this.getButton(5).setDisplay(recipe.ignoreDamage?1:0); - this.getButton(6).setEnabled(true); - this.getButton(6).setDisplay(recipe.ignoreNBT?1:0); - setSelected(recipe.name); - } + @Override + public void setGuiData(NBTTagCompound compound) { + if (compound.hasKey("IsAnvil")) { + RecipeAnvil recipe = RecipeAnvil.read(compound); + getTextField(0).setText(recipe.name); + getTextField(1).setText(recipe.getRepairPercentage() + ""); + getTextField(2).setText(recipe.getXpCost() + ""); + container.setRecipe(recipe); + + setSelected(recipe.name); + getTextField(0).enabled = true; + getTextField(1).enabled = true; + getTextField(2).enabled = true; + + container.width = 1; + + GuiNpcButtonYesNo btnMatDamage = (GuiNpcButtonYesNo)this.getButton(7); + GuiNpcButtonYesNo btnMatNBT = (GuiNpcButtonYesNo)this.getButton(8); + GuiNpcButtonYesNo btnItemNBT = (GuiNpcButtonYesNo)this.getButton(9); + if (btnMatDamage != null) { + btnMatDamage.setDisplay(recipe.ignoreRepairMaterialDamage ? 1 : 0); + btnMatDamage.setEnabled(true); + } + if (btnMatNBT != null) { + btnMatNBT.setDisplay(recipe.ignoreRepairMaterialNBT ? 1 : 0); + btnMatNBT.setEnabled(true); + } + if (btnItemNBT != null) { + btnItemNBT.setDisplay(recipe.ignoreRepairItemNBT ? 1 : 0); + btnItemNBT.setEnabled(true); + } + } else { + RecipeCarpentry recipe = RecipeCarpentry.read(compound); + getTextField(0).setText(recipe.name); + container.setRecipe(recipe); + this.getTextField(0).enabled = true; + this.getButton(5).setEnabled(true); + this.getButton(5).setDisplay(recipe.ignoreDamage ? 1 : 0); + this.getButton(6).setEnabled(true); + this.getButton(6).setDisplay(recipe.ignoreNBT ? 1 : 0); + setSelected(recipe.name); + } + } @Override protected void drawGuiContainerBackgroundLayer(float f, int x, int y){ @@ -166,16 +261,29 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS drawTexturedModalRect(guiLeft + i*18 + 7, guiTop + j*18 + 34, 0, 0, 18, 18); } } - drawTexturedModalRect(guiLeft + 86, guiTop + 60, 0, 0, 18, 18); + + if(container.width == 1){ + drawTexturedModalRect(guiLeft + 101, guiTop + 34, 0, 0, 18, 18); + this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.material"), guiLeft + 28, guiTop + 38, CustomNpcResourceListener.DefaultTextColor); + } else { + drawTexturedModalRect(guiLeft + 86, guiTop + 60, 0, 0, 18, 18); + } } @Override public void setData(Vector list, HashMap data) { String name = scroll.getSelected(); this.data = data; scroll.setList(getSearchList()); + this.getTextField(0).enabled = name != null; - this.getTextField(0).enabled = name != null; - this.getButton(5).setEnabled(name != null); + if(container.width == 1){ + this.getButton(7).setEnabled(name != null); + this.getButton(8).setEnabled(name != null); + this.getButton(9).setEnabled(name != null); + } else { + this.getButton(5).setEnabled(name != null); + this.getButton(6).setEnabled(name != null); + } if(name != null) scroll.setSelected(name); @@ -191,7 +299,11 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { save(); selected = scroll.getSelected(); - PacketClient.sendClient(new RecipeGetPacket(data.get(selected))); + if(container.width == 1){ + PacketClient.sendClient(new RecipeGetPacket(data.get(selected), true)); + } else { + PacketClient.sendClient(new RecipeGetPacket(data.get(selected), false)); + } } @Override @@ -199,7 +311,11 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS GuiNpcTextField.unfocus(); if(selected != null && data.containsKey(selected)){ container.saveRecipe(); - PacketClient.sendClient(new RecipeSavePacket(container.recipe.writeNBT())); + if(container.width == 1){ + PacketClient.sendClient(new RecipeSavePacket(container.recipeAnvil.writeNBT())); + } else { + PacketClient.sendClient(new RecipeSavePacket(container.recipe.writeNBT())); + } } } @@ -208,13 +324,39 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS if(guiNpcTextField.id == 0){ String name = guiNpcTextField.getText(); if(!name.isEmpty() && !data.containsKey(name)){ - String old = container.recipe.name; - data.remove(container.recipe.name); - container.recipe.name = name; - data.put(container.recipe.name, container.recipe.id); - selected = name; - scroll.replace(old,container.recipe.name); + if(container.width == 1){ + String old = container.recipeAnvil.name; + data.remove(container.recipeAnvil.name); + container.recipeAnvil.name = name; + data.put(container.recipeAnvil.name, container.recipeAnvil.id); + selected = name; + scroll.replace(old,container.recipeAnvil.name); + } else { + String old = container.recipe.name; + data.remove(container.recipe.name); + container.recipe.name = name; + data.put(container.recipe.name, container.recipe.id); + selected = name; + scroll.replace(old,container.recipe.name); + } } } + if(guiNpcTextField.id == 1){ + float percent = guiNpcTextField.getFloat(); + if(container.width == 1){ + container.recipeAnvil.repairPercentage = percent; + } + } + if(guiNpcTextField.id == 2){ + int xpCost = guiNpcTextField.getInteger(); + if(container.width == 1){ + container.recipeAnvil.xpCost = xpCost; + } + } } + + @Override + public void subGuiClosed(SubGuiInterface subgui){ + + } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java b/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java index d0ba2533c..6d9e17667 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java @@ -3,6 +3,7 @@ package noppes.npcs.client.gui.player; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import noppes.npcs.client.CustomNpcResourceListener; @@ -109,6 +110,28 @@ public class GuiAnvilRecipes extends GuiNPCInterface { updateButton(); } + private static class ItemOverlayData { + public final int x, y; + public final ItemStack item; + public ItemOverlayData(int x, int y, ItemStack item) { + this.x = x; + this.y = y; + this.item = item; + } + } + + private static class TextOverlayData { + public final int x, y, width, height; + public final String text; + public TextOverlayData(int x, int y, int width, int height, String text) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.text = text; + } + } + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); @@ -117,22 +140,25 @@ public class GuiAnvilRecipes extends GuiNPCInterface { lblPage.label = (page + 1) + "/" + MathHelper.ceiling_float_int(recipes.size() / 8.0F); lblPage.x = guiLeft + (xSize - Minecraft.getMinecraft().fontRenderer.getStringWidth(lblPage.label)) / 2; - // Determine which recipes to show. int recipesPerPage = 8; int startIndex = page * recipesPerPage; int endIndex = Math.min(recipes.size(), startIndex + recipesPerPage); - // Set base positions: first column X and first row Y. + // Base positions relative to guiLeft and guiTop. int baseX = guiLeft + 4; - int baseY = guiTop + 28; // first row Y = 28 + int baseY = guiTop + 28; // first row = guiTop + 28 int colSpacing = 124; // horizontal spacing between columns - int rowSpacing = 35; // vertical spacing so row1 becomes 28+35 = 63 + int rowSpacing = 35; // vertical spacing so row1 = guiTop + 28 + 35 + + // Create lists to collect overlay data. + List itemOverlays = new ArrayList(); + List textOverlays = new ArrayList(); for (int i = startIndex; i < endIndex; i++) { RecipeAnvil recipe = recipes.get(i); int localIndex = i - startIndex; // 0 to 7 - int col = localIndex / 4; // 0 for left column, 1 for right column - int row = localIndex % 4; // 0 to 3 + int col = localIndex / 4; // 0 for left column, 1 for right column + int row = localIndex % 4; // rows 0..3 int slotX = baseX + col * colSpacing; int slotY = baseY + row * rowSpacing; @@ -147,59 +173,91 @@ public class GuiAnvilRecipes extends GuiNPCInterface { // Draw the item-to-repair at 50% durability. ItemStack toRepair = recipe.itemToRepair; + ItemStack halfItem = null; if (toRepair != null) { - ItemStack halfItem = toRepair.copy(); + halfItem = toRepair.copy(); if (halfItem.isItemStackDamageable()) { int halfDamage = halfItem.getMaxDamage() / 2; halfItem.setItemDamage(halfDamage); } drawItem(halfItem, slotX + 1, slotY + 1, mouseX, mouseY); + // Instead of drawing overlay immediately, add to list. + if (func_146978_c((slotX+1) - guiLeft, (slotY+1) - guiTop, 16, 16, mouseX, mouseY)) { + itemOverlays.add(new ItemOverlayData(slotX+1, slotY+1, halfItem)); + } } + // Draw the repair material. ItemStack material = recipe.repairMaterial; if (material != null) { drawItem(material, slotX + 23, slotY + 1, mouseX, mouseY); + if (func_146978_c((slotX+23) - guiLeft, (slotY+1) - guiTop, 16, 16, mouseX, mouseY)) { + itemOverlays.add(new ItemOverlayData(slotX+23, slotY+1, material)); + } } // Draw the output item fully repaired (damage = 0). - // For first column, output X = guiLeft+103; second column, output X = guiLeft+229. int outputX = (col == 0) ? (guiLeft + 103) : (guiLeft + 229); + ItemStack fullOutput = null; if (recipe.itemToRepair != null) { - ItemStack fullOutput = recipe.itemToRepair.copy(); + fullOutput = recipe.itemToRepair.copy(); if (fullOutput.isItemStackDamageable()) { fullOutput.setItemDamage(0); } drawItem(fullOutput, outputX, slotY, mouseX, mouseY); + if (func_146978_c(outputX - guiLeft, slotY - guiTop, 16, 16, mouseX, mouseY)) { + itemOverlays.add(new ItemOverlayData(outputX, slotY, fullOutput)); + } } // Draw the percentage text. - // We want the "middle right" for the first column to be at 68. - // So for column 0, centerX is fixed at 68; for column 1, centerX is 68 + colSpacing. + int percentCenterX = (col == 0) ? (guiLeft + 57) : (guiLeft + 57 + colSpacing); String percentText = Math.round(recipe.getRepairPercentage()) + "%"; - int textWidth = fontRendererObj.getStringWidth(percentText); - int centerX = (col == 0) ? guiLeft + 57 : (guiLeft + 57 + colSpacing); - int textX = centerX - (textWidth / 2); - int textY = slotY + 4 + row; - fontRendererObj.drawString(percentText, textX, textY, CustomNpcResourceListener.DefaultTextColor); + int percentWidth = fontRendererObj.getStringWidth(percentText); + int percentTextX = percentCenterX - (percentWidth / 2); + int percentTextY = slotY + 4 + row; + fontRendererObj.drawString(percentText, percentTextX, percentTextY, CustomNpcResourceListener.DefaultTextColor); + // Add text overlay for percentage with the full unrounded value. + if (func_146978_c(percentTextX - guiLeft, percentTextY - guiTop, percentWidth, fontRendererObj.FONT_HEIGHT, mouseX, mouseY)) { + textOverlays.add(new TextOverlayData(percentTextX, percentTextY, percentWidth, fontRendererObj.FONT_HEIGHT, String.valueOf(recipe.getRepairPercentage()))); + } // Draw XP cost with scaling. String xpCostStr = formatXpCost(recipe.getXpCost()); int digitCount = xpCostStr.length(); - // Scale factor: for 1 digit = 1.0, for 2 digits = 0.9, for 3 digits = 0.8. float xpScale = 1.0F - 0.1F * (digitCount - 1); - // Get raw text width. int rawTextWidth = fontRendererObj.getStringWidth(xpCostStr); int scaledTextWidth = (int)(rawTextWidth * xpScale); - int xpCenterX = (col == 0) ? (guiLeft + 76) : (guiLeft + 78 + colSpacing); - int xpTextX = xpCenterX - (scaledTextWidth / 2); - int xpTextY = slotY - 4 + row; // adjust as needed - + int xpCenterX = (col == 0) ? (guiLeft + 76) : (guiLeft + 76 + colSpacing); + int xpTextX = xpCenterX - (scaledTextWidth / 2) + col; + int xpTextY = slotY - 4 + row; GL11.glPushMatrix(); GL11.glTranslatef(xpTextX, xpTextY, 0); GL11.glScalef(xpScale, xpScale, 1.0F); fontRendererObj.drawString(xpCostStr, 0, 0, 0x4ac26a); GL11.glPopMatrix(); + // Add text overlay for XP cost with the full (unformatted) number. + int xpBoxWidth = scaledTextWidth; + int xpBoxHeight = fontRendererObj.FONT_HEIGHT; + if (func_146978_c(xpTextX - guiLeft, xpTextY - guiTop, xpBoxWidth, xpBoxHeight, mouseX, mouseY)) { + textOverlays.add(new TextOverlayData(xpTextX, xpTextY, xpBoxWidth, xpBoxHeight, String.valueOf(recipe.getXpCost()))); + } } + + for (ItemOverlayData iod : itemOverlays) { + this.renderToolTip(iod.item, mouseX, mouseY); + } + + for (TextOverlayData tod : textOverlays) { + this.drawHoveringText(java.util.Arrays.asList(tod.text), mouseX, mouseY, this.fontRendererObj); + } + } + protected boolean func_146978_c(int p_146978_1_, int p_146978_2_, int p_146978_3_, int p_146978_4_, int p_146978_5_, int p_146978_6_) { + int k1 = this.guiLeft; + int l1 = this.guiTop; + p_146978_5_ -= k1; + p_146978_6_ -= l1; + return p_146978_5_ >= p_146978_1_ - 1 && p_146978_5_ < p_146978_1_ + p_146978_3_ + 1 && p_146978_6_ >= p_146978_2_ - 1 && p_146978_6_ < p_146978_2_ + p_146978_4_ + 1; } private String formatXpCost(int xp) { diff --git a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java index df2badcc9..355294a47 100644 --- a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java +++ b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java @@ -77,38 +77,38 @@ public class ContainerAnvilRepair extends Container { "Test", new ItemStack(Items.iron_pickaxe), new ItemStack(Items.paper), - 4, - 3)); + 50, + 23)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "Okay", new ItemStack(Items.diamond_pickaxe), new ItemStack(Items.paper), - 4, - 3)); + 21, + 10)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "Bob", new ItemStack(Items.golden_pickaxe), new ItemStack(Items.paper), - 4, - 3)); + 1200, + 40)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "Dude", new ItemStack(Items.iron_chestplate), new ItemStack(Items.paper), - 4, - 3)); + 40000, + 23)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "Oas", new ItemStack(Items.golden_pickaxe), new ItemStack(Items.diamond), - 4, - 3)); + 12, + 1)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "awd", new ItemStack(Items.golden_sword), new ItemStack(Items.gold_ingot), - 4, - 3)); + 80, + 14)); RecipeController.Instance.addAnvilRecipe(new RecipeAnvil( "fawd", new ItemStack(Items.bow), diff --git a/src/main/java/noppes/npcs/containers/ContainerManageRecipes.java b/src/main/java/noppes/npcs/containers/ContainerManageRecipes.java index a881df2ce..88a3c7851 100644 --- a/src/main/java/noppes/npcs/containers/ContainerManageRecipes.java +++ b/src/main/java/noppes/npcs/containers/ContainerManageRecipes.java @@ -6,6 +6,7 @@ import net.minecraft.inventory.InventoryBasic; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import java.util.ArrayList; @@ -16,6 +17,7 @@ public class ContainerManageRecipes extends Container { private InventoryBasic craftingMatrix; public RecipeCarpentry recipe; + public RecipeAnvil recipeAnvil; public int size; public int width; private boolean init = false; @@ -25,14 +27,21 @@ public class ContainerManageRecipes extends Container this.width = size; craftingMatrix = new InventoryBasic("crafting", false, this.size + 1); recipe = new RecipeCarpentry(""); - addSlotToContainer(new Slot(craftingMatrix,0,87,61)); + recipeAnvil = new RecipeAnvil(); + + if(width == 1){ + addSlotToContainer(new Slot(craftingMatrix,0,102,35)); + } + else { + addSlotToContainer(new Slot(craftingMatrix,0,87,61)); + } for(int i = 0; i < size;i++){ for(int j = 0; j < size;j++){ addSlotToContainer(new Slot(craftingMatrix, i * width + j + 1,j*18 + 8, i*18 + 35)); } } - + for(int i1 = 0; i1 < 3; i1++) { for(int l1 = 0; l1 < 9; l1++) @@ -57,7 +66,7 @@ public class ContainerManageRecipes extends Container public boolean canInteractWith(EntityPlayer entityplayer) { return true; } - + public void setRecipe(RecipeCarpentry recipe) { craftingMatrix.setInventorySlotContents(0,recipe.getRecipeOutput()); for(int i = 0; i < width;i++){ @@ -70,85 +79,116 @@ public class ContainerManageRecipes extends Container } this.recipe = recipe; } - public void saveRecipe(){ - int nextChar = 0; - char[] chars = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'}; - Map nameMapping = new HashMap(); - int firstRow = width,lastRow = 0,firstColumn = width,lastColumn = 0; - boolean seenRow = false; - for(int i = 0; i < width;i++){ - boolean seenColumn = false; - for(int j = 0; j < width;j++){ - ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1); - if(item == null){ - continue; - }else{ - if(!seenColumn && j < firstColumn){ - firstColumn = j; - } - if(j > lastColumn) - lastColumn = j; - - seenColumn = true; - } - Character letter = null; - for(ItemStack mapped : nameMapping.keySet()){ - if(NoppesUtilPlayer.compareItems(mapped, item, recipe.ignoreDamage, recipe.ignoreNBT)) - letter = nameMapping.get(mapped); - } - if(letter == null){ - letter = chars[nextChar]; - nextChar++; - nameMapping.put(item, letter); - } - } - if(seenColumn){ - if(!seenRow){ - firstRow = i; - lastRow = i; - seenRow = true; - } - else{ - lastRow = i; - } - } - - } - ArrayList recipe = new ArrayList(); - for(int i = 0; i < width;i++){ - if(i < firstRow || i > lastRow) - continue; - String row = ""; - for(int j = 0; j < width;j++){ - if(j < firstColumn|| j > lastColumn) - continue; - ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1); - if(item == null){ - row += " "; - continue; - } + public void setRecipe(RecipeAnvil recipe) { + if (recipe.itemToRepair != null) { + ItemStack output = recipe.itemToRepair.copy(); + if (output.isItemStackDamageable()) { + output.setItemDamage(0); + } + craftingMatrix.setInventorySlotContents(0, output); + } else { + craftingMatrix.setInventorySlotContents(0, null); + } - for(ItemStack mapped : nameMapping.keySet()){ - if(NoppesUtilPlayer.compareItems(mapped, item, false, false)){ - row += nameMapping.get(mapped); - } - } - - } - recipe.add(row); - } - if(nameMapping.isEmpty()){ - RecipeCarpentry r = new RecipeCarpentry(this.recipe.name); - r.copy(this.recipe); - this.recipe = r; - return; - } - for(ItemStack mapped : nameMapping.keySet()){ - Character letter = nameMapping.get(mapped); - recipe.add(letter); - recipe.add(mapped); - } - this.recipe = RecipeCarpentry.saveRecipe(this.recipe, craftingMatrix.getStackInSlot(0), recipe.toArray()); - } + craftingMatrix.setInventorySlotContents(1, recipe.repairMaterial); + for (int i = 2; i < craftingMatrix.getSizeInventory(); i++) { + craftingMatrix.setInventorySlotContents(i, null); + } + + this.recipeAnvil = recipe; + } + + public void saveRecipe(){ + if(width == 1){ + ItemStack output = craftingMatrix.getStackInSlot(0); + ItemStack repairMat = craftingMatrix.getStackInSlot(1); + if(output == null || repairMat == null){ + return; + } + + RecipeAnvil r = new RecipeAnvil(); + r.copy(this.recipeAnvil); + r.name = this.recipeAnvil.name; + r.itemToRepair = output.copy(); + r.repairMaterial = repairMat.copy(); + this.recipeAnvil = RecipeAnvil.saveRecipe(r, output, repairMat); + return; + } else { + // Carpentry Recipe save (existing code) + int nextChar = 0; + char[] chars = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'}; + Map nameMapping = new HashMap(); + int firstRow = width, lastRow = 0, firstColumn = width, lastColumn = 0; + boolean seenRow = false; + for (int i = 0; i < width; i++) { + boolean seenColumn = false; + for (int j = 0; j < width; j++) { + ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1); + if (item == null) { + continue; + } else { + if (!seenColumn && j < firstColumn) { + firstColumn = j; + } + if (j > lastColumn) + lastColumn = j; + seenColumn = true; + } + Character letter = null; + for (ItemStack mapped : nameMapping.keySet()) { + if (NoppesUtilPlayer.compareItems(mapped, item, recipe.ignoreDamage, recipe.ignoreNBT)) + letter = nameMapping.get(mapped); + } + if (letter == null) { + letter = chars[nextChar]; + nextChar++; + nameMapping.put(item, letter); + } + } + if (seenColumn) { + if (!seenRow) { + firstRow = i; + lastRow = i; + seenRow = true; + } else { + lastRow = i; + } + } + } + ArrayList recipeList = new ArrayList(); + for (int i = 0; i < width; i++) { + if (i < firstRow || i > lastRow) + continue; + String row = ""; + for (int j = 0; j < width; j++) { + if (j < firstColumn || j > lastColumn) + continue; + ItemStack item = craftingMatrix.getStackInSlot(i * width + j + 1); + if (item == null) { + row += " "; + continue; + } + for (ItemStack mapped : nameMapping.keySet()) { + if (NoppesUtilPlayer.compareItems(mapped, item, false, false)) { + row += nameMapping.get(mapped); + } + } + } + recipeList.add(row); + } + if (nameMapping.isEmpty()) { + RecipeCarpentry r = new RecipeCarpentry(this.recipe.name); + r.copy(this.recipe); + this.recipe = r; + return; + } + for (ItemStack mapped : nameMapping.keySet()) { + Character letter = nameMapping.get(mapped); + recipeList.add(letter); + recipeList.add(mapped); + } + this.recipe = RecipeCarpentry.saveRecipe(this.recipe, craftingMatrix.getStackInSlot(0), recipeList.toArray()); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/RecipeController.java b/src/main/java/noppes/npcs/controllers/RecipeController.java index 3eaea1fac..39894ce4d 100644 --- a/src/main/java/noppes/npcs/controllers/RecipeController.java +++ b/src/main/java/noppes/npcs/controllers/RecipeController.java @@ -219,13 +219,13 @@ public class RecipeController implements IRecipeHandler { RecipeAnvil current = getAnvilRecipe(recipe.id); if(current != null && !current.name.equals(recipe.name)){ - while(containsRecipeName(recipe.name)) + while(containsAnvilRecipeName(recipe.name)) recipe.name += "_"; } if(recipe.id == -1){ recipe.id = getUniqueAnvilId(); - while(containsRecipeName(recipe.name)) + while(containsAnvilRecipeName(recipe.name)) recipe.name += "_"; } @@ -288,7 +288,7 @@ public class RecipeController implements IRecipeHandler { RecipeAnvil anvilRecipe = anvilRecipes.remove(recipe.id); if(anvilRecipe != null) - // SyncController.syncAllWorkbenchRecipes(); + SyncController.syncAllAnvilRecipes(); saveCategories(); return recipe; diff --git a/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java b/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java index e153fe3a8..02f7919a7 100644 --- a/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java +++ b/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java @@ -2,21 +2,25 @@ package noppes.npcs.controllers.data; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.api.handler.data.IAnvilRecipe; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.api.handler.data.IAnvilRecipe; +import noppes.npcs.controllers.data.Availability; public class RecipeAnvil implements IAnvilRecipe { public int id = -1; public String name = ""; public Availability availability = new Availability(); - public boolean ignoreNBT = false; + + public boolean ignoreRepairItemNBT = false; + public boolean ignoreRepairMaterialNBT = false; + public boolean ignoreRepairMaterialDamage = false; public ItemStack itemToRepair; public ItemStack repairMaterial; - private int xpCost; - private float repairPercentage; + public int xpCost; + public float repairPercentage; private boolean isAnvil = true; @@ -39,6 +43,9 @@ public class RecipeAnvil implements IAnvilRecipe { recipe.repairPercentage = compound.getFloat("RepairPercentage"); recipe.itemToRepair = NoppesUtilServer.readItem(compound.getCompoundTag("ItemToRepair")); recipe.repairMaterial = NoppesUtilServer.readItem(compound.getCompoundTag("RepairMaterial")); + recipe.ignoreRepairMaterialNBT = compound.getBoolean("IgnoreRepairMatNBT"); + recipe.ignoreRepairItemNBT = compound.getBoolean("IgnoreRepairItemNBT"); + recipe.ignoreRepairMaterialDamage = compound.getBoolean("IgnoreRepairMatDamage"); recipe.isAnvil = true; return recipe; } @@ -50,12 +57,20 @@ public class RecipeAnvil implements IAnvilRecipe { compound.setTag("Availability", availability.writeToNBT(new NBTTagCompound())); compound.setInteger("XPCost", xpCost); compound.setFloat("RepairPercentage", repairPercentage); - compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound())); - compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound())); + if(itemToRepair != null){ + compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound())); + } + if(repairMaterial != null){ + compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound())); + } + compound.setBoolean("IgnoreRepairMatNBT", ignoreRepairMaterialNBT); + compound.setBoolean("IgnoreRepairItemNBT", ignoreRepairItemNBT); + compound.setBoolean("IgnoreRepairMatDamage", ignoreRepairMaterialDamage); compound.setBoolean("IsAnvil", true); return compound; } + @Override public int getXpCost() { return xpCost; } @@ -65,24 +80,18 @@ public class RecipeAnvil implements IAnvilRecipe { return repairPercentage; } - /** - * Checks that both input ItemStacks are non-null and match the recipe’s defined items. - */ @Override public boolean matches(ItemStack inputItem, ItemStack inputRepairMaterial) { if (inputItem == null || inputRepairMaterial == null) return false; - if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, false)) { + if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, this.ignoreRepairItemNBT)) { return false; } - if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, false, false)) { + if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, this.ignoreRepairMaterialDamage, this.ignoreRepairMaterialNBT)) { return false; } return true; } - /** - * Returns a repaired copy of the input item by reducing its damage. - */ @Override public ItemStack getResult(ItemStack inputItem) { if (inputItem == null) @@ -108,4 +117,35 @@ public class RecipeAnvil implements IAnvilRecipe { public int getID() { return this.id; } + + public static RecipeAnvil saveRecipe(RecipeAnvil recipe, ItemStack output, ItemStack repairMaterial) { + if (output != null) { + recipe.itemToRepair = output.copy(); + if (recipe.itemToRepair.isItemStackDamageable()) { + recipe.itemToRepair.setItemDamage(0); + } + } else { + recipe.itemToRepair = null; + } + recipe.repairMaterial = (repairMaterial == null ? null : repairMaterial.copy()); + return recipe; + } + + public boolean isValid() { + return itemToRepair != null && repairMaterial != null; + } + + /** + * Creates and returns a deep copy of this RecipeAnvil. + */ + public void copy(RecipeAnvil recipe) { + this.id = recipe.id; + this.name = recipe.name; + this.availability = recipe.availability; + this.ignoreRepairMaterialDamage = recipe.ignoreRepairMaterialDamage; + this.ignoreRepairItemNBT = recipe.ignoreRepairItemNBT; + this.ignoreRepairMaterialNBT = recipe.ignoreRepairMaterialNBT; + this.repairPercentage = recipe.repairPercentage;; + this.xpCost = recipe.xpCost; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/RecipeCarpentry.java b/src/main/java/noppes/npcs/controllers/data/RecipeCarpentry.java index 3c1607a2a..809d59df4 100644 --- a/src/main/java/noppes/npcs/controllers/data/RecipeCarpentry.java +++ b/src/main/java/noppes/npcs/controllers/data/RecipeCarpentry.java @@ -23,7 +23,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe { public boolean isGlobal = false; public boolean ignoreDamage = false; public boolean ignoreNBT = false; - + public RecipeCarpentry(int width, int height, ItemStack[] recipe, ItemStack result){ super(width, height, recipe, result); @@ -32,9 +32,9 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe { super(0, 0, new ItemStack[0], null); this.name = name; } - + public static RecipeCarpentry read(NBTTagCompound compound){ - RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"), + RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"), NBTTags.getItemStackArray(compound.getTagList("Materials", 10)), NoppesUtilServer.readItem(compound.getCompoundTag("Item"))); recipe.name = compound.getString("Name"); recipe.id = compound.getInteger("ID"); @@ -42,7 +42,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe { recipe.ignoreDamage = compound.getBoolean("IgnoreDamage"); recipe.ignoreNBT = compound.getBoolean("IgnoreNBT"); recipe.isGlobal = compound.getBoolean("Global"); - + return recipe; } @@ -188,15 +188,14 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe { var15[var9] = null; } } - RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack); + RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack); newrecipe.copy(recipe); if(var5 == 4 || var6 == 4) newrecipe.isGlobal = false; - - - + return newrecipe; } + public void copy(RecipeCarpentry recipe) { this.id = recipe.id; this.name = recipe.name; @@ -205,7 +204,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe { this.ignoreDamage = recipe.ignoreDamage; this.ignoreNBT = recipe.ignoreNBT; } - + public ItemStack getCraftingItem(int i){ if(recipeItems == null || i >= recipeItems.length) return null; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 26d319480..9b4d8afa5 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -88,8 +88,14 @@ gui.sunlight=Sunlight gui.always=Always gui.untilclose=UntilClose gui.whenavailable=OnTheMove -gui.ignoreDamage=Ignore damage +gui.ignoreDamage=Ignore Damage gui.ignoreNBT=Ignore NBT +gui.ignoreMatDamage=Ignore Material DMG +gui.ignoreMatNBT=Ignore Material NBT +gui.ignoreItemNBT=Ignore Item NBT +gui.repairPercent=Repair % +gui.material=Material +gui.xpCost=XP Cost gui.recordHistory=Record History gui.minrange=MinimumRange gui.engagedistance=EngageDistance