Fix the oredictionary for the new recipe wildcard value of Short.MAX_VALUE.

This commit is contained in:
Christian 2013-03-11 17:43:23 -04:00
parent 4d6c135182
commit 529062d73f
3 changed files with 56 additions and 49 deletions

View file

@ -23,7 +23,14 @@ public class OreDictionary
private static int maxID = 0; private static int maxID = 0;
private static HashMap<String, Integer> oreIDs = new HashMap<String, Integer>(); private static HashMap<String, Integer> oreIDs = new HashMap<String, Integer>();
private static HashMap<Integer, ArrayList<ItemStack>> oreStacks = new HashMap<Integer, ArrayList<ItemStack>>(); private static HashMap<Integer, ArrayList<ItemStack>> oreStacks = new HashMap<Integer, ArrayList<ItemStack>>();
/**
* Minecraft changed from -1 to Short.MAX_VALUE in 1.5 release for the "block wildcard". Use this in case it
* changes again.
*/
public static final int WILDCARD_VALUE = Short.MAX_VALUE;
static { static {
initVanillaEntries(); initVanillaEntries();
} }
@ -32,16 +39,16 @@ public class OreDictionary
{ {
if (!hasInit) if (!hasInit)
{ {
registerOre("logWood", new ItemStack(Block.wood, 1, -1)); registerOre("logWood", new ItemStack(Block.wood, 1, WILDCARD_VALUE));
registerOre("plankWood", new ItemStack(Block.planks, 1, -1)); registerOre("plankWood", new ItemStack(Block.planks, 1, WILDCARD_VALUE));
registerOre("slabWood", new ItemStack(Block.woodSingleSlab, 1, -1)); registerOre("slabWood", new ItemStack(Block.woodSingleSlab, 1, WILDCARD_VALUE));
registerOre("stairWood", Block.stairCompactPlanks); registerOre("stairWood", Block.stairCompactPlanks);
registerOre("stairWood", Block.stairsWoodBirch); registerOre("stairWood", Block.stairsWoodBirch);
registerOre("stairWood", Block.stairsWoodJungle); registerOre("stairWood", Block.stairsWoodJungle);
registerOre("stairWood", Block.stairsWoodSpruce); registerOre("stairWood", Block.stairsWoodSpruce);
registerOre("stickWood", Item.stick); registerOre("stickWood", Item.stick);
registerOre("treeSapling", new ItemStack(Block.sapling, 1, -1)); registerOre("treeSapling", new ItemStack(Block.sapling, 1, WILDCARD_VALUE));
registerOre("treeLeaves", new ItemStack(Block.leaves, 1, -1)); registerOre("treeLeaves", new ItemStack(Block.leaves, 1, WILDCARD_VALUE));
} }
// Build our list of items to replace with ore tags // Build our list of items to replace with ore tags
@ -50,7 +57,7 @@ public class OreDictionary
replacements.put(new ItemStack(Item.stick), "stickWood"); replacements.put(new ItemStack(Item.stick), "stickWood");
// Register dyes // Register dyes
String[] dyes = String[] dyes =
{ {
"dyeBlack", "dyeBlack",
"dyeRed", "dyeRed",
@ -139,9 +146,9 @@ public class OreDictionary
} }
/** /**
* Gets the integer ID for the specified ore name. * Gets the integer ID for the specified ore name.
* If the name does not have a ID it assigns it a new one. * If the name does not have a ID it assigns it a new one.
* *
* @param name The unique name for this ore 'oreIron', 'ingotIron', etc.. * @param name The unique name for this ore 'oreIron', 'ingotIron', etc..
* @return A number representing the ID for this ore type * @return A number representing the ID for this ore type
*/ */
@ -156,10 +163,10 @@ public class OreDictionary
} }
return val; return val;
} }
/** /**
* Reverse of getOreID, will not create new entries. * Reverse of getOreID, will not create new entries.
* *
* @param id The ID to translate to a string * @param id The ID to translate to a string
* @return The String name, or "Unknown" if not found. * @return The String name, or "Unknown" if not found.
*/ */
@ -174,7 +181,7 @@ public class OreDictionary
} }
return "Unknown"; return "Unknown";
} }
/** /**
* Gets the integer ID for the specified item stack. * Gets the integer ID for the specified item stack.
* If the item stack is not linked to any ore, this will return -1 and no new entry will be created. * If the item stack is not linked to any ore, this will return -1 and no new entry will be created.
@ -193,7 +200,7 @@ public class OreDictionary
{ {
for(ItemStack target : ore.getValue()) for(ItemStack target : ore.getValue())
{ {
if(itemStack.itemID == target.itemID && (target.getItemDamage() == -1 || itemStack.getItemDamage() == target.getItemDamage())) if(itemStack.itemID == target.itemID && (target.getItemDamage() == WILDCARD_VALUE || itemStack.getItemDamage() == target.getItemDamage()))
{ {
return ore.getKey(); return ore.getKey();
} }
@ -201,11 +208,11 @@ public class OreDictionary
} }
return -1; // didn't find it. return -1; // didn't find it.
} }
/** /**
* Retrieves the ArrayList of items that are registered to this ore type. * Retrieves the ArrayList of items that are registered to this ore type.
* Creates the list as empty if it did not exist. * Creates the list as empty if it did not exist.
* *
* @param name The ore name, directly calls getOreID * @param name The ore name, directly calls getOreID
* @return An arrayList containing ItemStacks registered for this ore * @return An arrayList containing ItemStacks registered for this ore
*/ */
@ -213,21 +220,21 @@ public class OreDictionary
{ {
return getOres(getOreID(name)); return getOres(getOreID(name));
} }
/** /**
* Retrieves a list of all unique ore names that are already registered. * Retrieves a list of all unique ore names that are already registered.
* *
* @return All unique ore names that are currently registered. * @return All unique ore names that are currently registered.
*/ */
public static String[] getOreNames() public static String[] getOreNames()
{ {
return oreIDs.keySet().toArray(new String[oreIDs.keySet().size()]); return oreIDs.keySet().toArray(new String[oreIDs.keySet().size()]);
} }
/** /**
* Retrieves the ArrayList of items that are registered to this ore type. * Retrieves the ArrayList of items that are registered to this ore type.
* Creates the list as empty if it did not exist. * Creates the list as empty if it did not exist.
* *
* @param id The ore ID, see getOreID * @param id The ore ID, see getOreID
* @return An arrayList containing ItemStacks registered for this ore * @return An arrayList containing ItemStacks registered for this ore
*/ */
@ -263,7 +270,7 @@ public class OreDictionary
{ {
return false; return false;
} }
return (target.itemID == input.itemID && ((target.getItemDamage() == -1 && !strict) || target.getItemDamage() == input.getItemDamage())); return (target.itemID == input.itemID && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
} }
//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack) //Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
@ -273,11 +280,11 @@ public class OreDictionary
public static void registerOre(int id, Item ore){ registerOre(id, new ItemStack(ore)); } public static void registerOre(int id, Item ore){ registerOre(id, new ItemStack(ore)); }
public static void registerOre(int id, Block ore){ registerOre(id, new ItemStack(ore)); } public static void registerOre(int id, Block ore){ registerOre(id, new ItemStack(ore)); }
public static void registerOre(int id, ItemStack ore){ registerOre(getOreName(id), id, ore); } public static void registerOre(int id, ItemStack ore){ registerOre(getOreName(id), id, ore); }
/** /**
* Registers a ore item into the dictionary. * Registers a ore item into the dictionary.
* Raises the registerOre function in all registered handlers. * Raises the registerOre function in all registered handlers.
* *
* @param name The name of the ore * @param name The name of the ore
* @param id The ID of the ore * @param id The ID of the ore
* @param ore The ore's ItemStack * @param ore The ore's ItemStack
@ -289,12 +296,12 @@ public class OreDictionary
ores.add(ore); ores.add(ore);
MinecraftForge.EVENT_BUS.post(new OreRegisterEvent(name, ore)); MinecraftForge.EVENT_BUS.post(new OreRegisterEvent(name, ore));
} }
public static class OreRegisterEvent extends Event public static class OreRegisterEvent extends Event
{ {
public final String Name; public final String Name;
public final ItemStack Ore; public final ItemStack Ore;
public OreRegisterEvent(String name, ItemStack ore) public OreRegisterEvent(String name, ItemStack ore)
{ {
this.Name = name; this.Name = name;

View file

@ -13,12 +13,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ShapedOreRecipe implements IRecipe public class ShapedOreRecipe implements IRecipe
{ {
//Added in for future ease of change, but hard coded for now. //Added in for future ease of change, but hard coded for now.
private static final int MAX_CRAFT_GRID_WIDTH = 3; private static final int MAX_CRAFT_GRID_WIDTH = 3;
private static final int MAX_CRAFT_GRID_HEIGHT = 3; private static final int MAX_CRAFT_GRID_HEIGHT = 3;
private ItemStack output = null; private ItemStack output = null;
private Object[] input = null; private Object[] input = null;
private int width = 0; private int width = 0;
@ -56,7 +56,7 @@ public class ShapedOreRecipe implements IRecipe
width = s.length(); width = s.length();
shape += s; shape += s;
} }
height = parts.length; height = parts.length;
} }
else else
@ -98,7 +98,7 @@ public class ShapedOreRecipe implements IRecipe
} }
else if (in instanceof Block) else if (in instanceof Block)
{ {
itemMap.put(chr, new ItemStack((Block)in, 1, -1)); itemMap.put(chr, new ItemStack((Block)in, 1, OreDictionary.WILDCARD_VALUE));
} }
else if (in instanceof String) else if (in instanceof String)
{ {
@ -120,7 +120,7 @@ public class ShapedOreRecipe implements IRecipe
int x = 0; int x = 0;
for (char chr : shape.toCharArray()) for (char chr : shape.toCharArray())
{ {
input[x++] = itemMap.get(chr); input[x++] = itemMap.get(chr);
} }
} }
@ -162,7 +162,7 @@ public class ShapedOreRecipe implements IRecipe
@Override @Override
public boolean matches(InventoryCrafting inv, World world) public boolean matches(InventoryCrafting inv, World world)
{ {
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++)
{ {
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y)
@ -171,17 +171,17 @@ public class ShapedOreRecipe implements IRecipe
{ {
return true; return true;
} }
if (mirrored && checkMatch(inv, x, y, false)) if (mirrored && checkMatch(inv, x, y, false))
{ {
return true; return true;
} }
} }
} }
return false; return false;
} }
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{ {
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
@ -205,7 +205,7 @@ public class ShapedOreRecipe implements IRecipe
} }
ItemStack slot = inv.getStackInRowAndColumn(x, y); ItemStack slot = inv.getStackInRowAndColumn(x, y);
if (target instanceof ItemStack) if (target instanceof ItemStack)
{ {
if (!checkItemEquals((ItemStack)target, slot)) if (!checkItemEquals((ItemStack)target, slot))
@ -216,12 +216,12 @@ public class ShapedOreRecipe implements IRecipe
else if (target instanceof ArrayList) else if (target instanceof ArrayList)
{ {
boolean matched = false; boolean matched = false;
for (ItemStack item : (ArrayList<ItemStack>)target) for (ItemStack item : (ArrayList<ItemStack>)target)
{ {
matched = matched || checkItemEquals(item, slot); matched = matched || checkItemEquals(item, slot);
} }
if (!matched) if (!matched)
{ {
return false; return false;
@ -243,7 +243,7 @@ public class ShapedOreRecipe implements IRecipe
{ {
return false; return false;
} }
return (target.itemID == input.itemID && (target.getItemDamage() == -1 || target.getItemDamage() == input.getItemDamage())); return (target.itemID == input.itemID && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE|| target.getItemDamage() == input.getItemDamage()));
} }
public ShapedOreRecipe setMirrored(boolean mirror) public ShapedOreRecipe setMirrored(boolean mirror)
@ -253,7 +253,7 @@ public class ShapedOreRecipe implements IRecipe
} }
/** /**
* Returns the input for this recipe, any mod accessing this value should never * Returns the input for this recipe, any mod accessing this value should never
* manipulate the values in this array as it will effect the recipe itself. * manipulate the values in this array as it will effect the recipe itself.
* @return The recipes input vales. * @return The recipes input vales.
*/ */

View file

@ -15,14 +15,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ShapelessOreRecipe implements IRecipe public class ShapelessOreRecipe implements IRecipe
{ {
private ItemStack output = null; private ItemStack output = null;
private ArrayList input = new ArrayList(); private ArrayList input = new ArrayList();
public ShapelessOreRecipe(Block result, Object... recipe){ this(new ItemStack(result), recipe); } public ShapelessOreRecipe(Block result, Object... recipe){ this(new ItemStack(result), recipe); }
public ShapelessOreRecipe(Item result, Object... recipe){ this(new ItemStack(result), recipe); } public ShapelessOreRecipe(Item result, Object... recipe){ this(new ItemStack(result), recipe); }
public ShapelessOreRecipe(ItemStack result, Object... recipe) public ShapelessOreRecipe(ItemStack result, Object... recipe)
{ {
output = result.copy(); output = result.copy();
@ -81,12 +81,12 @@ public class ShapelessOreRecipe implements IRecipe
@Override @Override
public ItemStack getRecipeOutput(){ return output; } public ItemStack getRecipeOutput(){ return output; }
@Override @Override
public ItemStack getCraftingResult(InventoryCrafting var1){ return output.copy(); } public ItemStack getCraftingResult(InventoryCrafting var1){ return output.copy(); }
@Override @Override
public boolean matches(InventoryCrafting var1, World world) public boolean matches(InventoryCrafting var1, World world)
{ {
ArrayList required = new ArrayList(input); ArrayList required = new ArrayList(input);
@ -102,9 +102,9 @@ public class ShapelessOreRecipe implements IRecipe
while (req.hasNext()) while (req.hasNext())
{ {
boolean match = false; boolean match = false;
Object next = req.next(); Object next = req.next();
if (next instanceof ItemStack) if (next instanceof ItemStack)
{ {
match = checkItemEquals((ItemStack)next, slot); match = checkItemEquals((ItemStack)next, slot);
@ -134,14 +134,14 @@ public class ShapelessOreRecipe implements IRecipe
return required.isEmpty(); return required.isEmpty();
} }
private boolean checkItemEquals(ItemStack target, ItemStack input) private boolean checkItemEquals(ItemStack target, ItemStack input)
{ {
return (target.itemID == input.itemID && (target.getItemDamage() == -1 || target.getItemDamage() == input.getItemDamage())); return (target.itemID == input.itemID && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage()));
} }
/** /**
* Returns the input for this recipe, any mod accessing this value should never * Returns the input for this recipe, any mod accessing this value should never
* manipulate the values in this array as it will effect the recipe itself. * manipulate the values in this array as it will effect the recipe itself.
* @return The recipes input vales. * @return The recipes input vales.
*/ */