OreDictionary will warn if there's an invalid ore being registered now, rather than just

using -1 and doing weird things with the list as a result.
This commit is contained in:
cpw 2015-10-29 12:46:12 -04:00
parent 945d3887d2
commit a92f2a263b
1 changed files with 31 additions and 4 deletions

View File

@ -13,6 +13,8 @@ import java.util.RandomAccess;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@ -28,6 +30,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.registry.GameData;
@ -494,8 +497,22 @@ public class OreDictionary
}
int oreID = getOreID(name);
// HACK: use the registry name's ID. It is unique and it knows about substitutions
int hash = GameData.getItemRegistry().getId(ore.getItem().delegate.name());
// HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet
// IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about.
// APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game.
String registryName = ore.getItem().delegate.name();
int hash;
if (registryName == null)
{
FMLLog.bigWarning("A broken ore dictionary registration with name %s has occurred. It adds an item (type: %s) which is currently unknown to the game registry. This dictionary item can only support a single value when"
+ " registered with ores like this, and NO I am not going to turn this spam off. Just register your ore dictionary entries after the GameRegistry.\n"
+ "TO USERS: YES this is a BUG in the mod "+Loader.instance().activeModContainer().getName()+" report it to them!", name, ore.getItem().getClass());
hash = -1;
}
else
{
hash = GameData.getItemRegistry().getId(registryName);
}
if (ore.getItemDamage() != WILDCARD_VALUE)
{
hash |= ((ore.getItemDamage() + 1) << 16); // +1 so 0 is significant
@ -539,8 +556,18 @@ public class OreDictionary
if (ores == null) continue;
for (ItemStack ore : ores)
{
// HACK: use the registry name's ID. It is unique and it knows about substitutions
int hash = GameData.getItemRegistry().getId(ore.getItem().delegate.name());
// HACK: use the registry name's ID. It is unique and it knows about substitutions
String name = ore.getItem().delegate.name();
int hash;
if (name == null)
{
FMLLog.log(Level.DEBUG, "Defaulting unregistered ore dictionary entry for ore dictionary %s: type %s to -1", getOreName(id), ore.getItem().getClass());
hash = -1;
}
else
{
hash = GameData.getItemRegistry().getId(name);
}
if (ore.getItemDamage() != WILDCARD_VALUE)
{
hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant