diff --git a/resources/assets/tinker/textures/gui/icons.png b/resources/assets/tinker/textures/gui/icons.png index 38ffb143..a1cd9908 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 00000000..f5d977e3 --- /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 00000000..0a2f406c --- /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 35762d31..2469834d 100644 --- a/src/main/java/tconstruct/library/client/TConstructClientRegistry.java +++ b/src/main/java/tconstruct/library/client/TConstructClientRegistry.java @@ -13,6 +13,8 @@ import tconstruct.library.tools.ToolCore; 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 class TConstructClientRegistry } //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/client/ToolGuiElement.java b/src/main/java/tconstruct/library/client/ToolGuiElement.java index 640ef286..a87efc5c 100644 --- a/src/main/java/tconstruct/library/client/ToolGuiElement.java +++ b/src/main/java/tconstruct/library/client/ToolGuiElement.java @@ -1,27 +1,20 @@ package tconstruct.library.client; -public class ToolGuiElement +public class ToolGuiElement extends GuiElement { public final int slotType; - public final int buttonIconX; - public final int buttonIconY; public final int[] iconsX; public final int[] iconsY; public final String title; public final String body; - public final String domain; - public final String texture; public ToolGuiElement(int st, int bx, int by, int[] xi, int[] yi, String t, String b, String d, String tex) { + super(bx, by, d, tex); slotType = st; - buttonIconX = bx; - buttonIconY = by; iconsX = xi; iconsY = yi; title = t; body = b; - domain = d; - texture = tex; } } diff --git a/src/main/java/tconstruct/library/crafting/StencilBuilder.java b/src/main/java/tconstruct/library/crafting/StencilBuilder.java new file mode 100644 index 00000000..8654c51f --- /dev/null +++ b/src/main/java/tconstruct/library/crafting/StencilBuilder.java @@ -0,0 +1,64 @@ +package tconstruct.library.crafting; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.*; + +public class StencilBuilder { + public static StencilBuilder instance = new StencilBuilder(); + + public List blanks = new LinkedList(); // i wish ItemStack would support equals so i could use a Set here... + public List stencils = new ArrayList(); + + /** + * Returns whether the given ItemStack is a blank pattern and therefore usable for stencil crafting. + */ + public static boolean isBlank(ItemStack stack) + { + for(ItemStack blank : instance.blanks) + if(OreDictionary.itemMatches(stack, blank, false)) // this has nothing to do with the oredictionary. + return true; + + return false; + } + + public static void registerBlankStencil(ItemStack itemStack) + { + instance.blanks.add(itemStack); + } + + public static void registerStencil(Item item, int meta) + { + instance.stencils.add(new ItemStack(item, 1, meta)); + } + + public static void registerStencil(ItemStack pattern) + { + instance.stencils.add(pattern); + } + + public static List getStencils() { return instance.stencils; } + + /** + * Returns the index of the given stencil. If no stencil is found, returns -1. + */ + public static int getIndex(ItemStack stencil) { + for(int i = 0; i < instance.stencils.size(); i++) + if(OreDictionary.itemMatches(stencil, getStencil(i), false)) + return i; + + return -1; + } + + // returns the stencil with the given index + public static ItemStack getStencil(int num) { + if(num >= instance.stencils.size()) + return null; + + return instance.stencils.get(num).copy(); + } + + public static int getStencilCount() { return instance.stencils.size(); } +} diff --git a/src/main/java/tconstruct/tools/TinkerTools.java b/src/main/java/tconstruct/tools/TinkerTools.java index d4517dc0..5e96d4c2 100644 --- a/src/main/java/tconstruct/tools/TinkerTools.java +++ b/src/main/java/tconstruct/tools/TinkerTools.java @@ -43,10 +43,7 @@ import tconstruct.items.tools.Shortbow; import tconstruct.items.tools.Shovel; import tconstruct.library.TConstructRegistry; import tconstruct.library.client.TConstructClientRegistry; -import tconstruct.library.crafting.Detailing; -import tconstruct.library.crafting.ModifyBuilder; -import tconstruct.library.crafting.PatternBuilder; -import tconstruct.library.crafting.ToolBuilder; +import tconstruct.library.crafting.*; import tconstruct.library.tools.ToolCore; import tconstruct.library.util.IPattern; import tconstruct.modifiers.tools.ModAntiSpider; @@ -358,7 +355,10 @@ public class TinkerTools registerMaterials(); - //TODO: Redesign stencil table to be a sensible block + registerStencils(); + + + // this array is only used to register the remaining pattern-part-interactions TinkerTools.patternOutputs = new Item[] { TinkerTools.toolRod, TinkerTools.pickaxeHead, TinkerTools.shovelHead, TinkerTools.hatchetHead, TinkerTools.swordBlade, TinkerTools.wideGuard, TinkerTools.handGuard, TinkerTools.crossbar, TinkerTools.binding, TinkerTools.frypanHead, TinkerTools.signHead, TinkerTools.knifeBlade, TinkerTools.chiselHead, TinkerTools.toughRod, TinkerTools.toughBinding, TinkerTools.largePlate, TinkerTools.broadAxeHead, TinkerTools.scytheBlade, TinkerTools.excavatorHead, TinkerTools.largeSwordBlade, TinkerTools.hammerHead, @@ -939,4 +939,41 @@ public class TinkerTools 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 b093adea..6932aafd 100644 --- a/src/main/java/tconstruct/tools/ToolProxyClient.java +++ b/src/main/java/tconstruct/tools/ToolProxyClient.java @@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer; 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.common.TProxyCommon; 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 class ToolProxyClient extends ToolProxyCommon registerManualIcons(); registerManualRecipes(); addToolRenderMappings(); + addStencilButtons(); addToolButtons(); } @@ -325,6 +328,63 @@ public class ToolProxyClient extends ToolProxyCommon 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 00000000..a59dc7ad --- /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 4ef8b9f3..b5d9c5fe 100644 --- a/src/main/java/tconstruct/tools/gui/StencilTableGui.java +++ b/src/main/java/tconstruct/tools/gui/StencilTableGui.java @@ -11,6 +11,10 @@ import net.minecraft.world.World; 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; import tconstruct.tools.logic.StencilTableLogic; @@ -19,13 +23,13 @@ import tconstruct.util.network.PatternTablePacket; 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 @@ -61,67 +65,74 @@ public class StencilTableGui extends GuiContainer 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++) - //{ + 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); + } - /*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);*/ - //} + // 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 protected void actionPerformed (GuiButton button) { ItemStack pattern = logic.getStackInSlot(0); - if (pattern != null && pattern.getItem() == TinkerTools.blankPattern) + if (pattern != null && StencilBuilder.isBlank(pattern)) { - int meta = pattern.getItemDamage(); - if (meta == 0) + int id = ((GuiButtonStencil)button).element.stencilIndex; + ItemStack stack = StencilBuilder.getStencil(id); + if(stack != null) { - if (button.id == 0) - { - patternIndex++; - if (patternIndex == 21) - patternIndex++; - if (patternIndex >= TinkerTools.patternOutputs.length - 1) - patternIndex = 0; - } - else if (button.id == 1) - { - patternIndex--; - if (patternIndex < 0) - patternIndex = TinkerTools.patternOutputs.length - 2; - if (patternIndex == 21) - patternIndex--; - } - ItemStack stack = new ItemStack(TinkerTools.woodPattern, 1, patternIndex + 1); logic.setInventorySlotContents(1, stack); updateServer(stack); } - /*else if (meta == 1 || meta == 2) - { - ItemStack stack = new ItemStack(TContent.metalPattern, 1, 0); - logic.setInventorySlotContents(1, stack); - updateServer(stack); - }*/ } + + setActiveButton(button.id); + } + + 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 diff --git a/src/main/java/tconstruct/tools/gui/ToolStationGui.java b/src/main/java/tconstruct/tools/gui/ToolStationGui.java index 550286fe..3511548c 100644 --- a/src/main/java/tconstruct/tools/gui/ToolStationGui.java +++ b/src/main/java/tconstruct/tools/gui/ToolStationGui.java @@ -434,7 +434,7 @@ public class ToolStationGui extends GuiContainer for (int i = 0; i < slotX.length; i++) { - this.drawTexturedModalRect(cornerX + slotX[i] - 4, this.guiTop + slotY[i] - 4, 140, 212, 28, 28); + this.drawTexturedModalRect(cornerX + slotX[i], this.guiTop + slotY[i], 144, 216, 18, 18); if (!logic.isStackInSlot(i + 1)) { this.drawTexturedModalRect(cornerX + slotX[i], this.guiTop + slotY[i], 18 * iconX[i], 18 * iconY[i], 18, 18); diff --git a/src/main/java/tconstruct/tools/logic/StencilTableLogic.java b/src/main/java/tconstruct/tools/logic/StencilTableLogic.java index 135b16b1..037499f9 100644 --- a/src/main/java/tconstruct/tools/logic/StencilTableLogic.java +++ b/src/main/java/tconstruct/tools/logic/StencilTableLogic.java @@ -7,6 +7,7 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import tconstruct.library.crafting.StencilBuilder; import tconstruct.tools.TinkerTools; import tconstruct.tools.inventory.PatternShaperContainer; @@ -47,12 +48,9 @@ public class StencilTableLogic extends InventoryLogic implements ISidedInventory public void setInventorySlotContents (int slot, ItemStack itemstack) { super.setInventorySlotContents(slot, itemstack); - if (slot == 0 && itemstack != null && itemstack.getItem() == TinkerTools.blankPattern)//instanceof tconstruct.items.Pattern) + if (slot == 0 && itemstack != null && StencilBuilder.isBlank(itemstack)) { - if (itemstack.getItemDamage() == 0) - setInventorySlotContents(1, new ItemStack(TinkerTools.woodPattern, 1, 1)); - /*else if (itemstack.getItemDamage() == 1) - setInventorySlotContents(1, new ItemStack(TContent.metalPattern, 1, 0));*/ + setInventorySlotContents(1, new ItemStack(TinkerTools.woodPattern, 1, 1)); } }