Change stencils to be identified by actual IDs because DAMN was that other stuff a pain to use if you wanted to identify one.

This commit is contained in:
Bernhard Bonigl committed 2014-10-23 00:14:27 +02:00
1 parent 035cc454a5
commit b9efa7373f
4 files changed
+44 -42

No files matched your search

@@ -9,7 +9,7 @@ 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>();
public Map<Integer, ItemStack> stencils = new TreeMap<Integer, ItemStack>();
/**
* Returns whether the given ItemStack is a blank pattern and therefore usable for stencil crafting.
@@ -28,29 +28,32 @@ public class StencilBuilder
instance.blanks.add(itemStack);
}
public static void registerStencil (Item item, int meta)
public static void registerStencil (int id, Item item, int meta)
{
instance.stencils.add(new ItemStack(item, 1, meta));
registerStencil(id, new ItemStack(item, 1, meta));
}
public static void registerStencil (ItemStack pattern)
public static void registerStencil (int id, ItemStack pattern)
{
instance.stencils.add(pattern);
if(instance.stencils.containsKey(id))
throw new IllegalArgumentException("[TCon API] Stencil ID " + id + " is already occupied by " + instance.stencils.get(id).getDisplayName());
instance.stencils.put(id, pattern);
}
public static List<ItemStack> getStencils ()
public static Collection<ItemStack> getStencils ()
{
return instance.stencils;
return instance.stencils.values();
}
/**
* Returns the index of the given stencil. If no stencil is found, returns -1.
*/
public static int getIndex (ItemStack stencil)
public static int getId(ItemStack stencil)
{
for (int i = 0; i < instance.stencils.size(); i++)
if (OreDictionary.itemMatches(stencil, getStencil(i), false))
return i;
for(Map.Entry<Integer, ItemStack> entry : instance.stencils.entrySet())
if (OreDictionary.itemMatches(stencil, entry.getValue(), false))
return entry.getKey();
return -1;
}
@@ -58,7 +61,7 @@ public class StencilBuilder
// returns the stencil with the given index
public static ItemStack getStencil (int num)
{
if (num >= instance.stencils.size())
if (!instance.stencils.containsKey(num))
return null;
return instance.stencils.get(num).copy();