Skip to content

Commit

Permalink
Change StencilTable from hardcoded patterns to a flexible system
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Aug 20, 2014
1 parent 49764fd commit 5dd0e0c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 36 deletions.
64 changes: 64 additions & 0 deletions 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<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(ItemStack.areItemStackTagsEqual(stencil, getStencil(i)))
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(); }
}
14 changes: 10 additions & 4 deletions src/main/java/tconstruct/tools/TinkerTools.java
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,6 +355,15 @@ 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);
}


//TODO: Redesign stencil table to be a sensible block
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,
Expand Down
42 changes: 15 additions & 27 deletions src/main/java/tconstruct/tools/gui/StencilTableGui.java
Expand Up @@ -11,6 +11,7 @@
import org.lwjgl.opengl.GL11;

import tconstruct.TConstruct;
import tconstruct.library.crafting.StencilBuilder;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.inventory.PatternShaperContainer;
import tconstruct.tools.logic.StencilTableLogic;
Expand Down Expand Up @@ -85,37 +86,24 @@ public void initGui ()
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)
if (button.id == 0)
{
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);
patternIndex++;
if (patternIndex >= StencilBuilder.getStencilCount() - 1)
patternIndex = 0;
}
/*else if (meta == 1 || meta == 2)
else if (button.id == 1)
{
ItemStack stack = new ItemStack(TContent.metalPattern, 1, 0);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}*/
patternIndex--;
if (patternIndex < 0)
patternIndex = StencilBuilder.getStencilCount() - 2;
}

ItemStack stack = StencilBuilder.getStencil(patternIndex);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/tconstruct/tools/logic/StencilTableLogic.java
Expand Up @@ -7,6 +7,7 @@
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;

Expand Down Expand Up @@ -47,12 +48,9 @@ public void onInventoryChanged()
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));
}
}

Expand Down

0 comments on commit 5dd0e0c

Please sign in to comment.