Change StencilTable from hardcoded patterns to a flexible system

This commit is contained in:
Bernhard Bonigl committed 2014-08-20 19:15:16 +02:00
1 parent 49764fd251
commit 5dd0e0c8fa
4 files changed
+92 -36

No files matched your search

@@ -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(); }
}
@@ -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,6 +355,15 @@ public class TinkerTools
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,
@@ -11,6 +11,7 @@ import net.minecraft.world.World;
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;
@@ -85,37 +86,24 @@ public class StencilTableGui extends GuiContainer
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);
}
}
@@ -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));
}
}