Change OreDictionary over from "null" to the new ItemStack system. (#3400)
This commit is contained in:
parent
df32442a64
commit
bf090cb4c2
3 changed files with 41 additions and 33 deletions
|
@ -28,6 +28,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.BlockPrismarine;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
|
@ -51,15 +52,17 @@ import net.minecraftforge.fml.common.Loader;
|
|||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class OreDictionary
|
||||
{
|
||||
private static boolean hasInit = false;
|
||||
private static List<String> idToName = new ArrayList<String>();
|
||||
private static Map<String, Integer> nameToId = new HashMap<String, Integer>(128);
|
||||
private static List<List<ItemStack>> idToStack = Lists.newArrayList();
|
||||
private static List<List<ItemStack>> idToStackUn = Lists.newArrayList();
|
||||
private static List<NonNullList<ItemStack>> idToStack = Lists.newArrayList();
|
||||
private static List<NonNullList<ItemStack>> idToStackUn = Lists.newArrayList();
|
||||
private static Map<Integer, List<Integer>> stackToId = Maps.newHashMapWithExpectedSize((int)(128 * 0.75));
|
||||
public static final ImmutableList<ItemStack> EMPTY_LIST = ImmutableList.of();
|
||||
public static final NonNullList<ItemStack> EMPTY_LIST = NonNullList.func_191196_a();
|
||||
|
||||
/**
|
||||
* Minecraft changed from -1 to Short.MAX_VALUE in 1.5 release for the "block wildcard". Use this in case it
|
||||
|
@ -337,8 +340,8 @@ public class OreDictionary
|
|||
new ItemStack(Blocks.WOODEN_SLAB),
|
||||
new ItemStack(Blocks.GLASS_PANE),
|
||||
new ItemStack(Blocks.BONE_BLOCK), // Bone Block, to prevent conversion of dyes into bone meal.
|
||||
new ItemStack(Items.BOAT),
|
||||
null //So the above can have a comma and we don't have to keep editing extra lines.
|
||||
new ItemStack(Items.BOAT),
|
||||
ItemStack.field_190927_a //So the above can have a comma and we don't have to keep editing extra lines.
|
||||
};
|
||||
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
|
@ -352,7 +355,7 @@ public class OreDictionary
|
|||
{
|
||||
ShapedRecipes recipe = (ShapedRecipes)obj;
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
if (output != null && containsMatch(false, exclusions, output))
|
||||
if (!output.func_190926_b() && containsMatch(false, exclusions, output))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -367,7 +370,7 @@ public class OreDictionary
|
|||
{
|
||||
ShapelessRecipes recipe = (ShapelessRecipes)obj;
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
if (output != null && containsMatch(false, exclusions, output))
|
||||
if (!output.func_190926_b() && containsMatch(false, exclusions, output))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -404,9 +407,9 @@ public class OreDictionary
|
|||
idToName.add(name);
|
||||
val = idToName.size() - 1; //0 indexed
|
||||
nameToId.put(name, val);
|
||||
List<ItemStack> back = Lists.newArrayList();
|
||||
NonNullList<ItemStack> back = NonNullList.func_191196_a();
|
||||
idToStack.add(back);
|
||||
idToStackUn.add(Collections.unmodifiableList(back));
|
||||
idToStackUn.add(back);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
@ -429,9 +432,9 @@ public class OreDictionary
|
|||
* @param stack The item stack of the ore.
|
||||
* @return An array of ids that this ore is registered as.
|
||||
*/
|
||||
public static int[] getOreIDs(ItemStack stack)
|
||||
public static int[] getOreIDs(@Nonnull ItemStack stack)
|
||||
{
|
||||
if (stack == null || stack.getItem() == null) throw new IllegalArgumentException("Stack can not be null!");
|
||||
if (stack.func_190926_b()) throw new IllegalArgumentException("Stack can not be invalid!");
|
||||
|
||||
Set<Integer> set = new HashSet<Integer>();
|
||||
|
||||
|
@ -471,7 +474,7 @@ public class OreDictionary
|
|||
* @param name The ore name, directly calls getOreID
|
||||
* @return An arrayList containing ItemStacks registered for this ore
|
||||
*/
|
||||
public static List<ItemStack> getOres(String name)
|
||||
public static NonNullList<ItemStack> getOres(String name)
|
||||
{
|
||||
return getOres(getOreID(name));
|
||||
}
|
||||
|
@ -491,7 +494,7 @@ public class OreDictionary
|
|||
* @param alwaysCreateEntry Flag - should a new entry be created if empty
|
||||
* @return An arraylist containing ItemStacks registered for this ore
|
||||
*/
|
||||
public static List<ItemStack> getOres(String name, boolean alwaysCreateEntry)
|
||||
public static NonNullList<ItemStack> getOres(String name, boolean alwaysCreateEntry)
|
||||
{
|
||||
if (alwaysCreateEntry) {
|
||||
return getOres(getOreID(name));
|
||||
|
@ -531,12 +534,12 @@ public class OreDictionary
|
|||
* @param id The ore ID, see getOreID
|
||||
* @return An List containing ItemStacks registered for this ore
|
||||
*/
|
||||
private static List<ItemStack> getOres(int id)
|
||||
private static NonNullList<ItemStack> getOres(int id)
|
||||
{
|
||||
return idToStackUn.size() > id ? idToStackUn.get(id) : EMPTY_LIST;
|
||||
}
|
||||
|
||||
private static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets)
|
||||
private static boolean containsMatch(boolean strict, ItemStack[] inputs, @Nonnull ItemStack... targets)
|
||||
{
|
||||
for (ItemStack input : inputs)
|
||||
{
|
||||
|
@ -551,7 +554,7 @@ public class OreDictionary
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsMatch(boolean strict, List<ItemStack> inputs, ItemStack... targets)
|
||||
public static boolean containsMatch(boolean strict, NonNullList<ItemStack> inputs, @Nonnull ItemStack... targets)
|
||||
{
|
||||
for (ItemStack input : inputs)
|
||||
{
|
||||
|
@ -566,9 +569,9 @@ public class OreDictionary
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
|
||||
public static boolean itemMatches(@Nonnull ItemStack target, @Nonnull ItemStack input, boolean strict)
|
||||
{
|
||||
if (input == null && target != null || input != null && target == null)
|
||||
if (input.func_190926_b() && !target.func_190926_b() || !input.func_190926_b() && target.func_190926_b())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -578,7 +581,7 @@ public class OreDictionary
|
|||
//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
|
||||
public static void registerOre(String name, Item ore){ registerOre(name, new ItemStack(ore)); }
|
||||
public static void registerOre(String name, Block ore){ registerOre(name, new ItemStack(ore)); }
|
||||
public static void registerOre(String name, ItemStack ore){ registerOreImpl(name, ore); }
|
||||
public static void registerOre(String name, @Nonnull ItemStack ore){ registerOreImpl(name, ore); }
|
||||
|
||||
/**
|
||||
* Registers a ore item into the dictionary.
|
||||
|
@ -587,10 +590,10 @@ public class OreDictionary
|
|||
* @param name The name of the ore
|
||||
* @param ore The ore's ItemStack
|
||||
*/
|
||||
private static void registerOreImpl(String name, ItemStack ore)
|
||||
private static void registerOreImpl(String name, @Nonnull ItemStack ore)
|
||||
{
|
||||
if ("Unknown".equals(name)) return; //prevent bad IDs.
|
||||
if (ore == null || ore.getItem() == null)
|
||||
if (ore.func_190926_b())
|
||||
{
|
||||
FMLLog.bigWarning("Invalid registration attempt for an Ore Dictionary item with name %s has occurred. The registration has been denied to prevent crashes. The mod responsible for the registration needs to correct this.", name);
|
||||
return; //prevent bad ItemStacks.
|
||||
|
@ -639,7 +642,7 @@ public class OreDictionary
|
|||
private final String Name;
|
||||
private final ItemStack Ore;
|
||||
|
||||
public OreRegisterEvent(String name, ItemStack ore)
|
||||
public OreRegisterEvent(String name, @Nonnull ItemStack ore)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Ore = ore;
|
||||
|
@ -662,7 +665,7 @@ public class OreDictionary
|
|||
stackToId.clear();
|
||||
for (int id = 0; id < idToStack.size(); id++)
|
||||
{
|
||||
List<ItemStack> ores = idToStack.get(id);
|
||||
NonNullList<ItemStack> ores = idToStack.get(id);
|
||||
if (ores == null) continue;
|
||||
for (ItemStack ore : ores)
|
||||
{
|
||||
|
|
|
@ -34,13 +34,15 @@ import net.minecraft.util.NonNullList;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ShapedOreRecipe implements IRecipe
|
||||
{
|
||||
//Added in for future ease of change, but hard coded for now.
|
||||
public static final int MAX_CRAFT_GRID_WIDTH = 3;
|
||||
public static final int MAX_CRAFT_GRID_HEIGHT = 3;
|
||||
|
||||
protected ItemStack output = null;
|
||||
protected ItemStack output = ItemStack.field_190927_a;
|
||||
protected Object[] input = null;
|
||||
protected int width = 0;
|
||||
protected int height = 0;
|
||||
|
@ -48,7 +50,7 @@ public class ShapedOreRecipe implements IRecipe
|
|||
|
||||
public ShapedOreRecipe(Block result, Object... recipe){ this(new ItemStack(result), recipe); }
|
||||
public ShapedOreRecipe(Item result, Object... recipe){ this(new ItemStack(result), recipe); }
|
||||
public ShapedOreRecipe(ItemStack result, Object... recipe)
|
||||
public ShapedOreRecipe(@Nonnull ItemStack result, Object... recipe)
|
||||
{
|
||||
output = result.copy();
|
||||
|
||||
|
@ -157,7 +159,7 @@ public class ShapedOreRecipe implements IRecipe
|
|||
{
|
||||
ItemStack ingredient = recipe.recipeItems[i];
|
||||
|
||||
if(ingredient == null) continue;
|
||||
if(ingredient.func_190926_b()) continue;
|
||||
|
||||
input[i] = recipe.recipeItems[i];
|
||||
|
||||
|
@ -250,7 +252,7 @@ public class ShapedOreRecipe implements IRecipe
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else if (target == null && slot != null)
|
||||
else if (target == null && !slot.func_190926_b())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,15 +34,17 @@ import net.minecraft.util.NonNullList;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ShapelessOreRecipe implements IRecipe
|
||||
{
|
||||
protected ItemStack output = null;
|
||||
protected ArrayList<Object> input = new ArrayList<Object>();
|
||||
protected ItemStack output = ItemStack.field_190927_a;
|
||||
protected NonNullList<Object> input = NonNullList.func_191196_a();
|
||||
|
||||
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)
|
||||
public ShapelessOreRecipe(@Nonnull ItemStack result, Object... recipe)
|
||||
{
|
||||
output = result.copy();
|
||||
for (Object in : recipe)
|
||||
|
@ -108,13 +110,14 @@ public class ShapelessOreRecipe implements IRecipe
|
|||
@Override
|
||||
public boolean matches(InventoryCrafting var1, World world)
|
||||
{
|
||||
ArrayList<Object> required = new ArrayList<Object>(input);
|
||||
NonNullList<Object> required = NonNullList.func_191196_a();
|
||||
required.addAll(input);
|
||||
|
||||
for (int x = 0; x < var1.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack slot = var1.getStackInSlot(x);
|
||||
|
||||
if (slot != null)
|
||||
if (!slot.func_190926_b())
|
||||
{
|
||||
boolean inRecipe = false;
|
||||
Iterator<Object> req = required.iterator();
|
||||
|
@ -161,7 +164,7 @@ public class ShapelessOreRecipe implements IRecipe
|
|||
* manipulate the values in this array as it will effect the recipe itself.
|
||||
* @return The recipes input vales.
|
||||
*/
|
||||
public ArrayList<Object> getInput()
|
||||
public NonNullList<Object> getInput()
|
||||
{
|
||||
return this.input;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue