Skip to content

Commit

Permalink
Merge pull request #892 from bonii-xx/new_pr2
Browse files Browse the repository at this point in the history
Rework Stencil Table
  • Loading branch information
mDiyo committed Aug 21, 2014
2 parents d37a45d + 9ed65aa commit b1e30d8
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 65 deletions.
Binary file modified resources/assets/tinker/textures/gui/icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/main/java/tconstruct/library/client/GuiElement.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions src/main/java/tconstruct/library/client/StencilGuiElement.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class TConstructClientRegistry
{
public static ArrayList<StencilGuiElement> stencilButtons = new ArrayList<StencilGuiElement>();
public static ArrayList<StencilGuiElement> stencilButtons2 = new ArrayList<StencilGuiElement>();
public static ArrayList<ToolGuiElement> toolButtons = new ArrayList<ToolGuiElement>(20);
public static ArrayList<ToolGuiElement> tierTwoButtons = new ArrayList<ToolGuiElement>();
public static Map<String, ItemStack> manualIcons = new HashMap<String, ItemStack>();
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/tconstruct/library/client/ToolGuiElement.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
64 changes: 64 additions & 0 deletions src/main/java/tconstruct/library/crafting/StencilBuilder.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> blanks = new LinkedList<ItemStack>(); // i wish ItemStack would support equals so i could use a Set here...
public List<ItemStack> stencils = new ArrayList<ItemStack>();

/**
* 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<ItemStack> 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(); }
}
47 changes: 42 additions & 5 deletions src/main/java/tconstruct/tools/TinkerTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
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;
Expand Down Expand Up @@ -358,7 +355,10 @@ public void preInit (FMLPreInitializationEvent event)

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,
Expand Down Expand Up @@ -939,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
}
}
60 changes: 60 additions & 0 deletions src/main/java/tconstruct/tools/ToolProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -63,6 +65,7 @@ public void initialize ()
registerManualIcons();
registerManualRecipes();
addToolRenderMappings();
addStencilButtons();
addToolButtons();
}

Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/tconstruct/tools/gui/GuiButtonStencil.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit b1e30d8

Please sign in to comment.