use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.
the class OreDictionary method getOreIDs.
/**
* Gets all the integer ID for the ores that the specified item stack is registered to.
* If the item stack is not linked to any ore, this will return an empty array and no new entry will be created.
*
* @param stack The item stack of the ore.
* @return An array of ids that this ore is registered as.
*/
public static int[] getOreIDs(@Nonnull ItemStack stack) {
if (stack.isEmpty())
throw new IllegalArgumentException("Stack can not be invalid!");
Set<Integer> set = new HashSet<Integer>();
// 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.
ResourceLocation registryName = stack.getItem().delegate.name();
int id;
if (registryName == null) {
FMLLog.log(Level.DEBUG, "Attempted to find the oreIDs for an unregistered object (%s). This won't work very well.", stack);
return new int[0];
} else {
id = GameData.getItemRegistry().getId(registryName);
}
List<Integer> ids = stackToId.get(id);
if (ids != null)
set.addAll(ids);
ids = stackToId.get(id | ((stack.getItemDamage() + 1) << 16));
if (ids != null)
set.addAll(ids);
Integer[] tmp = set.toArray(new Integer[set.size()]);
int[] ret = new int[tmp.length];
for (int x = 0; x < tmp.length; x++) ret[x] = tmp[x];
return ret;
}
use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.
the class OreDictionary method rebakeMap.
public static void rebakeMap() {
//System.out.println("Baking OreDictionary:");
stackToId.clear();
for (int id = 0; id < idToStack.size(); id++) {
NonNullList<ItemStack> ores = idToStack.get(id);
if (ores == null)
continue;
for (ItemStack ore : ores) {
// HACK: use the registry name's ID. It is unique and it knows about substitutions
ResourceLocation 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) {
// +1 so meta 0 is significant
hash |= ((ore.getItemDamage() + 1) << 16);
}
List<Integer> ids = stackToId.get(hash);
if (ids == null) {
ids = Lists.newArrayList();
stackToId.put(hash, ids);
}
ids.add(id);
//System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore);
}
}
}
use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.
the class FMLControlledNamespacedRegistry method putObject.
/**
* DANGEROUS! EVIL! DO NOT USE!
*
* @deprecated register through {@link GameRegistry} instead.
*/
@Override
@Deprecated
public void putObject(@Nonnull ResourceLocation name, @Nonnull I thing) {
Preconditions.checkNotNull(name, "Can't use a null-name for the registry.");
Preconditions.checkNotNull(thing, "Can't add null-object to the registry.");
ResourceLocation existingName = getNameForObject(thing);
if (existingName == null) {
FMLLog.bigWarning("Ignoring putObject(%s, %s), not resolvable", name, thing);
} else if (existingName.equals(name)) {
FMLLog.bigWarning("Ignoring putObject(%s, %s), already added", name, thing);
} else {
FMLLog.bigWarning("Ignoring putObject(%s, %s), adding alias to %s instead", name, thing, existingName);
addAlias(name, existingName);
}
}
use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.
the class NoPotionEffectRenderTest method preInit.
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
TestPotion INSTANCE = new TestPotion(new ResourceLocation(modID, "test_potion"), false, 0xff00ff);
GameData.getPotionRegistry().register(-1, new ResourceLocation(modID, "test_potion"), INSTANCE);
}
use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.
the class PotionRegistryDebug method preInit.
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
// test automatic id distribution
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff);
// test that ids above 127 work
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00);
//TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
GameData.getPotionRegistry().register(-1, new ResourceLocation(ForgeVersion.MOD_ID, "forge"), forge);
GameData.getPotionRegistry().register(200, new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), forgy);
Random rand = new Random();
TIntSet taken = new TIntHashSet(100);
int ra = rand.nextInt(100) + 100;
taken.add(ra);
for (int i = 0; i < 20; i++) {
int r = rand.nextInt(200) + 35;
while (taken.contains(r)) r = rand.nextInt(200) + 35;
//r = 32+i;
taken.add(r);
// this potions will most likely not have the same IDs between server and client.
// The forge handshake on connect should fix this.
//new PotionForge(new ResourceLocation(ForgeModContainer.MOD_ID, "randomPotion" + r), false, 0xff00ff);
}
}
Aggregations