diff --git a/resources/assets/tinker/textures/gui/icons.png b/resources/assets/tinker/textures/gui/icons.png index 38ffb143e89..a1cd9908b94 100644 Binary files a/resources/assets/tinker/textures/gui/icons.png and b/resources/assets/tinker/textures/gui/icons.png differ diff --git a/src/main/java/tconstruct/library/client/GuiElement.java b/src/main/java/tconstruct/library/client/GuiElement.java new file mode 100644 index 00000000000..f5d977e3849 --- /dev/null +++ b/src/main/java/tconstruct/library/client/GuiElement.java @@ -0,0 +1,15 @@ +package tconstruct.library.client; + +public class GuiElement { + public final int buttonIconX; + public final int buttonIconY; + public final String domain; + public final String texture; + + public GuiElement(int buttonIconX, int buttonIconY, String domain, String texture) { + this.buttonIconX = buttonIconX; + this.buttonIconY = buttonIconY; + this.domain = domain; + this.texture = texture; + } +} diff --git a/src/main/java/tconstruct/library/client/StencilGuiElement.java b/src/main/java/tconstruct/library/client/StencilGuiElement.java new file mode 100644 index 00000000000..0a2f406cc75 --- /dev/null +++ b/src/main/java/tconstruct/library/client/StencilGuiElement.java @@ -0,0 +1,11 @@ +package tconstruct.library.client; + +public class StencilGuiElement extends GuiElement { + public final int stencilIndex; + + public StencilGuiElement(int buttonIconX, int buttonIconY, int stencilIndex, String domain, String texture) { + super(buttonIconX, buttonIconY, domain, texture); + + this.stencilIndex = stencilIndex; + } +} diff --git a/src/main/java/tconstruct/library/client/TConstructClientRegistry.java b/src/main/java/tconstruct/library/client/TConstructClientRegistry.java index 35762d31bc2..2469834deed 100644 --- a/src/main/java/tconstruct/library/client/TConstructClientRegistry.java +++ b/src/main/java/tconstruct/library/client/TConstructClientRegistry.java @@ -13,6 +13,8 @@ public class TConstructClientRegistry { + public static ArrayList stencilButtons = new ArrayList(); + public static ArrayList stencilButtons2 = new ArrayList(); public static ArrayList toolButtons = new ArrayList(20); public static ArrayList tierTwoButtons = new ArrayList(); public static Map manualIcons = new HashMap(); @@ -103,6 +105,27 @@ public static void registerManualSmeltery (String name, ItemStack output, ItemSt } //Gui + public static void addStencilButton (StencilGuiElement element) + { + stencilButtons.add(element); + } + + public static void addStencilButton (int xButton, int yButton, int index, String domain, String texture) + { + stencilButtons.add(new StencilGuiElement(xButton, yButton, index, domain, texture)); + } + + public static void addStencilButton2 (StencilGuiElement element) + { + stencilButtons.add(element); + } + + // adds a button to the right side of the stencil table + public static void addStencilButton2 (int xButton, int yButton, int index, String domain, String texture) + { + stencilButtons2.add(new StencilGuiElement(xButton, yButton, index, domain, texture)); + } + public static void addToolButton (ToolGuiElement element) { toolButtons.add(element); diff --git a/src/main/java/tconstruct/library/crafting/StencilBuilder.java b/src/main/java/tconstruct/library/crafting/StencilBuilder.java index c64fb41df22..8654c51f82c 100644 --- a/src/main/java/tconstruct/library/crafting/StencilBuilder.java +++ b/src/main/java/tconstruct/library/crafting/StencilBuilder.java @@ -46,7 +46,7 @@ public static void registerStencil(ItemStack pattern) */ public static int getIndex(ItemStack stencil) { for(int i = 0; i < instance.stencils.size(); i++) - if(ItemStack.areItemStackTagsEqual(stencil, getStencil(i))) + if(OreDictionary.itemMatches(stencil, getStencil(i), false)) return i; return -1; diff --git a/src/main/java/tconstruct/tools/TinkerTools.java b/src/main/java/tconstruct/tools/TinkerTools.java index 0ccf1be27bc..c9f61f08d48 100644 --- a/src/main/java/tconstruct/tools/TinkerTools.java +++ b/src/main/java/tconstruct/tools/TinkerTools.java @@ -355,13 +355,7 @@ public void preInit (FMLPreInitializationEvent event) registerMaterials(); - // register stencils/wooden patterns in the stencil table - StencilBuilder.registerBlankStencil(new ItemStack(TinkerTools.blankPattern)); - - for(int i = 1; i < 26; i++) { - if(i == 22) continue; // hide full guard - StencilBuilder.registerStencil(TinkerTools.woodPattern, i); - } + registerStencils(); //TODO: Redesign stencil table to be a sensible block @@ -945,4 +939,41 @@ void registerMaterials () pb.addToolPattern((IPattern) TinkerTools.woodPattern); } + + private void registerStencils() + { + StencilBuilder.registerBlankStencil(new ItemStack(TinkerTools.blankPattern)); + + // we register this manually because we want that specific order + StencilBuilder.registerStencil(TinkerTools.woodPattern, 1); // tool rod + StencilBuilder.registerStencil(TinkerTools.woodPattern, 9); // binding + StencilBuilder.registerStencil(TinkerTools.woodPattern, 14); // large tool rod + StencilBuilder.registerStencil(TinkerTools.woodPattern, 15); // large binding + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 2); // pickaxe head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 3); // shovel head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 4); // hatchet head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 18); // scythe + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 21); // hammer head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 19); // excavator head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 17); // lumberaxe head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 16); // large plate + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 10); // frying pan + StencilBuilder.registerStencil(TinkerTools.woodPattern, 11); // battlesign + StencilBuilder.registerStencil(TinkerTools.woodPattern, 13); // chisel + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 12); // knifeblade + StencilBuilder.registerStencil(TinkerTools.woodPattern, 5); // swordblade + StencilBuilder.registerStencil(TinkerTools.woodPattern, 20); // cleaver blade + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 8); // crossbar + StencilBuilder.registerStencil(TinkerTools.woodPattern, 7); // small guard + StencilBuilder.registerStencil(TinkerTools.woodPattern, 6); // wide guard + + StencilBuilder.registerStencil(TinkerTools.woodPattern, 25); // arrow head + StencilBuilder.registerStencil(TinkerTools.woodPattern, 24); // fletchling + StencilBuilder.registerStencil(TinkerTools.woodPattern, 23); // bowstring + } } diff --git a/src/main/java/tconstruct/tools/ToolProxyClient.java b/src/main/java/tconstruct/tools/ToolProxyClient.java index b093adea7c7..6932aafdae0 100644 --- a/src/main/java/tconstruct/tools/ToolProxyClient.java +++ b/src/main/java/tconstruct/tools/ToolProxyClient.java @@ -6,6 +6,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.event.sound.SoundLoadEvent; @@ -23,6 +24,7 @@ import tconstruct.library.TConstructRegistry; import tconstruct.library.client.TConstructClientRegistry; import tconstruct.library.client.ToolGuiElement; +import tconstruct.library.crafting.StencilBuilder; import tconstruct.library.crafting.ToolBuilder; import tconstruct.library.tools.ToolCore; import tconstruct.smeltery.TinkerSmeltery; @@ -63,6 +65,7 @@ public void initialize () registerManualIcons(); registerManualRecipes(); addToolRenderMappings(); + addStencilButtons(); addToolButtons(); } @@ -325,6 +328,63 @@ public void onSound (SoundLoadEvent event) MinecraftForge.EVENT_BUS.unregister(this); } + void addStencilButtons () + { + int[][] icons = { + {0,3}, // tool rod + {1,3}, // binding + {8,3}, // large tool rod + {9,3}, // large binding + + {0,2}, // pickaxe head + {3,2}, // shovel head + {2,2}, // hatchet head + {8,2}, // scythe + + {11,2}, // hammer head + {10,2}, // excavator head + {6,2}, // lumberaxe head + {9,2}, // large plate + + {}, + {4,2}, // frying pan + {5,2}, // battlesign + {7,3}, // chisel + + {}, + {7,2}, // knifeblade + {1,2}, // swordblade + {6,3}, // cleaver blade + + {}, + {4,3}, // crossbar + {3,3}, // small guard + {2,3}, // wide guard + + {}, + {11,3}, // arrow head + {12,3}, // fletchling + {10,3}, // bowstring + }; + + int i = 0; + for(ItemStack stack : StencilBuilder.getStencils()) { + // spacer + while(icons[i].length == 0) + { + addStencilButton(0,0, -1); + i++; + } + addStencilButton(icons[i][0], icons[i][1], StencilBuilder.getIndex(stack)); + i++; + } + } + + void addStencilButton (int xButton, int yButton, int index) + { + TConstructClientRegistry.addStencilButton(xButton, yButton, index, "tinker", "textures/gui/icons.png"); + } + static int[][] itemIcons = { new int[] { 0, 3, 0 }, // Repair new int[] { 1, 4, 0 }, // Pickaxe new int[] { 2, 5, 0 }, // Shovel diff --git a/src/main/java/tconstruct/tools/gui/GuiButtonStencil.java b/src/main/java/tconstruct/tools/gui/GuiButtonStencil.java new file mode 100644 index 00000000000..a59dc7ad5af --- /dev/null +++ b/src/main/java/tconstruct/tools/gui/GuiButtonStencil.java @@ -0,0 +1,50 @@ +package tconstruct.tools.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import tconstruct.library.client.StencilGuiElement; +import tconstruct.library.client.ToolGuiElement; + +public class GuiButtonStencil extends GuiButton{ + /** + * True for pointing right (next page), false for pointing left (previous + * page). + */ + int textureX; + int textureY; + public String texture; + public StencilGuiElement element; + private static ResourceLocation background; + + public GuiButtonStencil(int id, int posX, int posY, int texX, int texY, String domain, String tex, StencilGuiElement e) + { + super(id, posX, posY, 18, 18, ""); + textureX = texX; + textureY = texY; + texture = tex; + element = e; + background = new ResourceLocation(domain, tex); + } + + /** + * Draws this button to the screen. + */ + @Override + public void drawButton (Minecraft mc, int mouseX, int mouseY) + { + if (this.visible) + { + boolean var4 = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.getTextureManager().bindTexture(background); + + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + int var5 = this.getHoverState(this.field_146123_n); + int index = 18 * getHoverState(field_146123_n); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 144 + index * 2, 234, 18, 18); + this.drawTexturedModalRect(this.xPosition, this.yPosition, textureX * 18, textureY * 18, 18, 18); + } + } +} diff --git a/src/main/java/tconstruct/tools/gui/StencilTableGui.java b/src/main/java/tconstruct/tools/gui/StencilTableGui.java index f7a9dc24606..b5d9c5feba7 100644 --- a/src/main/java/tconstruct/tools/gui/StencilTableGui.java +++ b/src/main/java/tconstruct/tools/gui/StencilTableGui.java @@ -11,6 +11,9 @@ import org.lwjgl.opengl.GL11; import tconstruct.TConstruct; +import tconstruct.library.client.StencilGuiElement; +import tconstruct.library.client.TConstructClientRegistry; +import tconstruct.library.client.ToolGuiElement; import tconstruct.library.crafting.StencilBuilder; import tconstruct.tools.TinkerTools; import tconstruct.tools.inventory.PatternShaperContainer; @@ -20,13 +23,13 @@ public class StencilTableGui extends GuiContainer { StencilTableLogic logic; - int patternIndex; + int activeButton; public StencilTableGui(InventoryPlayer inventoryplayer, StencilTableLogic shaper, World world, int x, int y, int z) { super(new PatternShaperContainer(inventoryplayer, shaper)); logic = shaper; - patternIndex = 0; + activeButton = 0; } @Override @@ -62,24 +65,42 @@ protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3) public void initGui () { super.initGui(); - int cornerX = (this.width - this.xSize) / 2; - int cornerY = (this.height - this.ySize) / 2; + + int bpr = 4; // buttons per row! + int cornerX = this.guiLeft - 22*bpr; + int cornerY = this.guiTop + 2; this.buttonList.clear(); - /*ToolGuiElement repair = TConstruct.toolButtons.get(0); - GuiButtonTool repairButton = new GuiButtonTool(0, cornerX - 110, cornerY, repair.buttonIconX, repair.buttonIconY, repair.texture); // Repair - repairButton.enabled = false; - this.buttonList.add(repairButton);*/ - this.buttonList.add(new GuiButton(0, cornerX - 120, cornerY, 120, 20, (StatCollector.translateToLocal("gui.stenciltable1")))); - this.buttonList.add(new GuiButton(1, cornerX - 120, cornerY + 20, 120, 20, (StatCollector.translateToLocal("gui.stenciltable2")))); - - //for (int iter = 0; iter < TConstructContent.patternOutputs.length; iter++) - //{ - - /*ToolGuiElement element = TConstruct.toolButtons.get(iter); - GuiButtonTool button = new GuiButtonTool(iter, cornerX - 110 + 22 * (iter % 5), cornerY + 22 * (iter / 5), element.buttonIconX, element.buttonIconY, element.texture); // Repair - this.buttonList.add(button);*/ - //} + + int id = 0; + for (int iter = 0; iter < TConstructClientRegistry.stencilButtons.size(); iter++) + { + StencilGuiElement element = TConstructClientRegistry.stencilButtons.get(iter); + if(element.stencilIndex == -1) + continue; + GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture, + element); + this.buttonList.add(button); + } + + // secondary buttons, yay! + // these are to use for other mods :I + cornerX = this.guiLeft + this.xSize + 4; + for (int iter = 0; iter < TConstructClientRegistry.stencilButtons2.size(); iter++) + { + StencilGuiElement element = TConstructClientRegistry.stencilButtons2.get(iter); + if(element.stencilIndex == -1) + continue; + GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture, + element); + this.buttonList.add(button); + } + + // get the correct setting :I + if(logic.getStackInSlot(1) != null) + activeButton = StencilBuilder.getIndex(logic.getStackInSlot(1)); + + setActiveButton(activeButton); } @Override @@ -88,28 +109,30 @@ protected void actionPerformed (GuiButton button) ItemStack pattern = logic.getStackInSlot(0); if (pattern != null && StencilBuilder.isBlank(pattern)) { - if (button.id == 0) - { - patternIndex++; - if (patternIndex >= StencilBuilder.getStencilCount() - 1) - patternIndex = 0; - } - else if (button.id == 1) + int id = ((GuiButtonStencil)button).element.stencilIndex; + ItemStack stack = StencilBuilder.getStencil(id); + if(stack != null) { - patternIndex--; - if (patternIndex < 0) - patternIndex = StencilBuilder.getStencilCount() - 2; + logic.setInventorySlotContents(1, stack); + updateServer(stack); } - - ItemStack stack = StencilBuilder.getStencil(patternIndex); - logic.setInventorySlotContents(1, stack); - updateServer(stack); } + + setActiveButton(button.id); } - void updateServer (ItemStack stack) + private void setActiveButton(int id) { + // deactivate old button + ((GuiButton)this.buttonList.get(activeButton)).enabled = true; + // update active button + activeButton = id; + // activate the button + ((GuiButton)this.buttonList.get(activeButton)).enabled = false; + } + void updateServer (ItemStack stack) + { TConstruct.packetPipeline.sendToServer(new PatternTablePacket(logic.xCoord, logic.yCoord, logic.zCoord, stack)); } } \ No newline at end of file