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 HashMap<String, Integer> oreIDs = new HashMap<String, Integer>();
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 {
initVanillaEntries();
}
@ -32,16 +39,16 @@ public class OreDictionary
{
if (!hasInit)
{
registerOre("logWood", new ItemStack(Block.wood, 1, -1));
registerOre("plankWood", new ItemStack(Block.planks, 1, -1));
registerOre("slabWood", new ItemStack(Block.woodSingleSlab, 1, -1));
registerOre("logWood", new ItemStack(Block.wood, 1, WILDCARD_VALUE));
registerOre("plankWood", new ItemStack(Block.planks, 1, WILDCARD_VALUE));
registerOre("slabWood", new ItemStack(Block.woodSingleSlab, 1, WILDCARD_VALUE));
registerOre("stairWood", Block.stairCompactPlanks);
registerOre("stairWood", Block.stairsWoodBirch);
registerOre("stairWood", Block.stairsWoodJungle);
registerOre("stairWood", Block.stairsWoodSpruce);
registerOre("stickWood", Item.stick);
registerOre("treeSapling", new ItemStack(Block.sapling, 1, -1));
registerOre("treeLeaves", new ItemStack(Block.leaves, 1, -1));
registerOre("treeSapling", new ItemStack(Block.sapling, 1, WILDCARD_VALUE));
registerOre("treeLeaves", new ItemStack(Block.leaves, 1, WILDCARD_VALUE));
}
// Build our list of items to replace with ore tags
@ -50,7 +57,7 @@ public class OreDictionary
replacements.put(new ItemStack(Item.stick), "stickWood");
// Register dyes
String[] dyes =
String[] dyes =
{
"dyeBlack",
"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.
*
*
* @param name The unique name for this ore 'oreIron', 'ingotIron', etc..
* @return A number representing the ID for this ore type
*/
@ -156,10 +163,10 @@ public class OreDictionary
}
return val;
}
/**
* Reverse of getOreID, will not create new entries.
*
*
* @param id The ID to translate to a string
* @return The String name, or "Unknown" if not found.
*/
@ -174,7 +181,7 @@ public class OreDictionary
}
return "Unknown";
}
/**
* 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.
@ -193,7 +200,7 @@ public class OreDictionary
{
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();
}
@ -201,11 +208,11 @@ public class OreDictionary
}
return -1; // didn't find it.
}
/**
* Retrieves the ArrayList of items that are registered to this ore type.
* Creates the list as empty if it did not exist.
*
*
* @param name The ore name, directly calls getOreID
* @return An arrayList containing ItemStacks registered for this ore
*/
@ -213,21 +220,21 @@ public class OreDictionary
{
return getOres(getOreID(name));
}
/**
* Retrieves a list of all unique ore names that are already registered.
*
*
* @return All unique ore names that are currently registered.
*/
public static String[] getOreNames()
{
return oreIDs.keySet().toArray(new String[oreIDs.keySet().size()]);
}
/**
* Retrieves the ArrayList of items that are registered to this ore type.
* Creates the list as empty if it did not exist.
*
*
* @param id The ore ID, see getOreID
* @return An arrayList containing ItemStacks registered for this ore
*/
@ -263,7 +270,7 @@ public class OreDictionary
{
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)
@ -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, Block ore){ registerOre(id, new ItemStack(ore)); }
public static void registerOre(int id, ItemStack ore){ registerOre(getOreName(id), id, ore); }
/**
* Registers a ore item into the dictionary.
* Raises the registerOre function in all registered handlers.
*
*
* @param name The name of the ore
* @param id The ID of the ore
* @param ore The ore's ItemStack
@ -289,12 +296,12 @@ public class OreDictionary
ores.add(ore);
MinecraftForge.EVENT_BUS.post(new OreRegisterEvent(name, ore));
}
public static class OreRegisterEvent extends Event
{
public final String Name;
public final ItemStack Ore;
public OreRegisterEvent(String name, ItemStack ore)
{
this.Name = name;

View File

@ -13,12 +13,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipes;
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.
private static final int MAX_CRAFT_GRID_WIDTH = 3;
private static final int MAX_CRAFT_GRID_HEIGHT = 3;
private ItemStack output = null;
private Object[] input = null;
private int width = 0;
@ -56,7 +56,7 @@ public class ShapedOreRecipe implements IRecipe
width = s.length();
shape += s;
}
height = parts.length;
}
else
@ -98,7 +98,7 @@ public class ShapedOreRecipe implements IRecipe
}
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)
{
@ -120,7 +120,7 @@ public class ShapedOreRecipe implements IRecipe
int x = 0;
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
public boolean matches(InventoryCrafting inv, World world)
{
{
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++)
{
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y)
@ -171,17 +171,17 @@ public class ShapedOreRecipe implements IRecipe
{
return true;
}
if (mirrored && checkMatch(inv, x, y, false))
{
return true;
}
}
}
return false;
}
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
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);
if (target instanceof ItemStack)
{
if (!checkItemEquals((ItemStack)target, slot))
@ -216,12 +216,12 @@ public class ShapedOreRecipe implements IRecipe
else if (target instanceof ArrayList)
{
boolean matched = false;
for (ItemStack item : (ArrayList<ItemStack>)target)
{
matched = matched || checkItemEquals(item, slot);
}
if (!matched)
{
return false;
@ -243,7 +243,7 @@ public class ShapedOreRecipe implements IRecipe
{
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)
@ -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.
* @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.world.World;
public class ShapelessOreRecipe implements IRecipe
public class ShapelessOreRecipe implements IRecipe
{
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(Item result, Object... recipe){ this(new ItemStack(result), recipe); }
public ShapelessOreRecipe(ItemStack result, Object... recipe)
{
output = result.copy();
@ -81,12 +81,12 @@ public class ShapelessOreRecipe implements IRecipe
@Override
public ItemStack getRecipeOutput(){ return output; }
@Override
public ItemStack getCraftingResult(InventoryCrafting var1){ return output.copy(); }
@Override
public boolean matches(InventoryCrafting var1, World world)
public boolean matches(InventoryCrafting var1, World world)
{
ArrayList required = new ArrayList(input);
@ -102,9 +102,9 @@ public class ShapelessOreRecipe implements IRecipe
while (req.hasNext())
{
boolean match = false;
Object next = req.next();
if (next instanceof ItemStack)
{
match = checkItemEquals((ItemStack)next, slot);
@ -134,14 +134,14 @@ public class ShapelessOreRecipe implements IRecipe
return required.isEmpty();
}
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.
* @return The recipes input vales.
*/