diff --git a/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java b/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java index a6b404b9d6..a665ac217b 100644 --- a/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java +++ b/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java @@ -5,11 +5,11 @@ import java.io.Serializable; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.fml.common.registry.GameRegistry.UniqueIdentifier; /** * Represents a captured snapshot of a block which will not change @@ -29,7 +29,7 @@ public class BlockSnapshot implements Serializable public int flag; private final NBTTagCompound nbt; public transient World world; - public final UniqueIdentifier blockIdentifier; + public final ResourceLocation blockIdentifier; public final int meta; public BlockSnapshot(World world, BlockPos pos, IBlockState state) @@ -38,7 +38,7 @@ public class BlockSnapshot implements Serializable this.dimId = world.provider.getDimension(); this.pos = pos; this.replacedBlock = state; - this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock()); + this.blockIdentifier = state.getBlock().getRegistryName(); this.meta = state.getBlock().getMetaFromState(state); this.flag = 3; TileEntity te = world.getTileEntity(pos); @@ -60,7 +60,7 @@ public class BlockSnapshot implements Serializable this.dimId = world.provider.getDimension(); this.pos = pos.getImmutable(); this.replacedBlock = state; - this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock()); + this.blockIdentifier = state.getBlock().getRegistryName(); this.meta = state.getBlock().getMetaFromState(state); this.flag = 3; this.nbt = nbt; @@ -84,7 +84,7 @@ public class BlockSnapshot implements Serializable this.dimId = dimension; this.pos = pos.getImmutable(); this.flag = flag; - this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName); + this.blockIdentifier = new ResourceLocation(modid, blockName); this.meta = meta; this.nbt = nbt; } @@ -131,7 +131,7 @@ public class BlockSnapshot implements Serializable { if (this.replacedBlock == null) { - this.replacedBlock = GameRegistry.findBlock(this.blockIdentifier.modId, this.blockIdentifier.name).getStateFromMeta(meta); + this.replacedBlock = GameRegistry.findBlock(this.blockIdentifier.getResourceDomain(), this.blockIdentifier.getResourcePath()).getStateFromMeta(meta); } return this.replacedBlock; } @@ -225,8 +225,8 @@ public class BlockSnapshot implements Serializable public void writeToNBT(NBTTagCompound compound) { - compound.setString("blockMod", blockIdentifier.modId); - compound.setString("blockName", blockIdentifier.name); + compound.setString("blockMod", blockIdentifier.getResourceDomain()); + compound.setString("blockName", blockIdentifier.getResourcePath()); compound.setInteger("posX", pos.getX()); compound.setInteger("posY", pos.getY()); compound.setInteger("posZ", pos.getZ()); diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameData.java b/src/main/java/net/minecraftforge/fml/common/registry/GameData.java index eb36b1bbb3..aa8d9a9c75 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameData.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameData.java @@ -21,7 +21,6 @@ import net.minecraft.item.ItemBlock; import net.minecraft.potion.Potion; import net.minecraft.util.ObjectIntIdentityMap; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.Loader; @@ -91,26 +90,6 @@ public class GameData return getMain().iBlockRegistry.getObject(new ResourceLocation(modId, name)); } - static GameRegistry.UniqueIdentifier getUniqueName(Block block) - { - if (block == null) - { - return null; - } - Object name = getMain().iBlockRegistry.getNameForObject(block); - return new GameRegistry.UniqueIdentifier(name); - } - - static GameRegistry.UniqueIdentifier getUniqueName(Item item) - { - if (item == null) - { - return null; - } - Object name = getMain().iItemRegistry.getNameForObject(item); - return new GameRegistry.UniqueIdentifier(name); - } - protected static GameData getMain() { return mainData; diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java index 54e699af72..8ea45b5b90 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java @@ -51,7 +51,6 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import org.apache.logging.log4j.Level; -import com.google.common.base.Objects; import com.google.common.base.Strings; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; @@ -223,7 +222,7 @@ public class GameRegistry */ public static Block registerBlock(Block block, Class itemclass, Object... itemCtorArgs) { - return registerBlock(block, itemclass, block.getRegistryName(), itemCtorArgs); + return registerBlock(block, itemclass, block.getRegistryName().toString(), itemCtorArgs); } /** @@ -374,112 +373,12 @@ public class GameRegistry return GameData.findItem(modId, name); } - /** - * Will be switching to using ResourceLocation, since it's used widely elsewhere - */ - @Deprecated - public static final class UniqueIdentifier - { - public final String modId; - public final String name; - - UniqueIdentifier(String modId, String name) - { - this.modId = modId; - this.name = name; - } - - public UniqueIdentifier(String string) - { - String[] parts = string.split(":"); - this.modId = parts[0]; - this.name = parts[1]; - } - - public UniqueIdentifier(Object obj) - { - if (obj instanceof String) - { - String[] parts = ((String)obj).split(":"); - this.modId = parts[0]; - this.name = parts[1]; - } - else if (obj instanceof ResourceLocation) - { - this.modId = ((ResourceLocation)obj).getResourceDomain(); - this.name = ((ResourceLocation)obj).getResourcePath(); - } - else - { - throw new IllegalArgumentException("UniqueIdentifier must be a String or ResourceLocation, was " + obj.getClass()); - } - } - - @Override - public boolean equals(Object obj) - { - if (obj == null) - { - return false; - } - if (obj.getClass() != this.getClass()) - { - return false; - } - final UniqueIdentifier other = (UniqueIdentifier)obj; - return Objects.equal(modId, other.modId) && Objects.equal(name, other.name); - } - - @Override - public int hashCode() - { - return Objects.hashCode(modId, name); - } - - @Override - public String toString() - { - return String.format("%s:%s", modId, name); - } - } - public enum Type { BLOCK, ITEM; } - /** - * Look up the mod identifier data for a block. - *

- * Note: uniqueness and persistence is only guaranteed by mods using the game registry - * correctly. - * - * @param block to lookup - * @return a {@link UniqueIdentifier} for the block or null - */ - @Deprecated - public static UniqueIdentifier findUniqueIdentifierFor(Block block) - { - return GameData.getUniqueName(block); - } - - /** - * Look up the mod identifier data for an item. - *

- * Note: uniqueness and persistence is only guaranteed by mods using the game registry - * correctly. - * - * @param item to lookup - * @return a {@link UniqueIdentifier} for the item or null - */ - @Deprecated - public static UniqueIdentifier findUniqueIdentifierFor(Item item) - { - return GameData.getUniqueName(item); - } - - /** * ObjectHolder can be used to automatically populate public static final fields with entries * from the registry. These values can then be referred within mod code directly. diff --git a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java index 7a5bcabbc1..65029c5a28 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java @@ -1,7 +1,6 @@ package net.minecraftforge.fml.common.registry; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -24,7 +23,6 @@ import org.apache.logging.log4j.Level; import net.minecraft.block.Block; import net.minecraft.block.BlockAir; import net.minecraft.item.Item; -import net.minecraft.potion.Potion; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.EnhancedRuntimeException; import net.minecraftforge.fml.common.FMLCommonHandler; @@ -51,12 +49,18 @@ public class PersistentRegistryManager private final BiMap>, ResourceLocation> registrySuperTypes = HashBiMap.create(); @SuppressWarnings("unchecked") - > FMLControlledNamespacedRegistry getRegistry(ResourceLocation key, Class regType) + private > Class getRegistrySuperType(ResourceLocation key) + { + return (Class)registrySuperTypes.inverse().get(key); + } + + @SuppressWarnings("unchecked") + private > FMLControlledNamespacedRegistry getRegistry(ResourceLocation key, Class regType) { return (FMLControlledNamespacedRegistry)registries.get(key); } - > FMLControlledNamespacedRegistry getOrShallowCopyRegistry(ResourceLocation key, Class regType, FMLControlledNamespacedRegistry other) + private > FMLControlledNamespacedRegistry getOrShallowCopyRegistry(ResourceLocation key, Class regType, FMLControlledNamespacedRegistry other) { if (!registries.containsKey(key)) { @@ -152,7 +156,7 @@ public class PersistentRegistryManager // Load the snapshot into the "STAGING" registry for (Map.Entry snapshotEntry : snapshot.entries.entrySet()) { - loadPersistentDataToStagingRegistry(injectFrozenData, remaps, missing, snapshotEntry, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(snapshotEntry.getKey())); + loadPersistentDataToStagingRegistry(injectFrozenData, remaps, missing, snapshotEntry, PersistentRegistry.ACTIVE); } // Handle dummied blocks @@ -210,7 +214,7 @@ public class PersistentRegistryManager // So we load it from the frozen persistent registry for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadFrozenDataToStagingRegistry(remaps, r.getKey(), PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + loadFrozenDataToStagingRegistry(remaps, r.getKey(), PersistentRegistry.ACTIVE); } } @@ -220,7 +224,7 @@ public class PersistentRegistryManager // Load the STAGING registry into the ACTIVE registry for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.STAGING, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + loadRegistry(r.getKey(), PersistentRegistry.STAGING, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE); } // Dump the active registry @@ -251,8 +255,9 @@ public class PersistentRegistryManager } } - private static > void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, Class regType) + private static > void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, PersistentRegistry typeRegistry) { + Class regType = typeRegistry.getRegistrySuperType(registryName); FMLControlledNamespacedRegistry fromRegistry = from.getRegistry(registryName, regType); if (fromRegistry == null) { @@ -287,16 +292,18 @@ public class PersistentRegistryManager } } - private static > void loadFrozenDataToStagingRegistry(Map> remaps, ResourceLocation registryName, Class regType) + private static > void loadFrozenDataToStagingRegistry(Map> remaps, ResourceLocation registryName, PersistentRegistry typeRegistry) { + Class regType = typeRegistry.getRegistrySuperType(registryName); FMLControlledNamespacedRegistry frozenRegistry = PersistentRegistry.FROZEN.getRegistry(registryName, regType); FMLControlledNamespacedRegistry newRegistry = PersistentRegistry.STAGING.getOrShallowCopyRegistry(registryName, regType, frozenRegistry); newRegistry.loadIds(frozenRegistry.getEntriesNotIn(newRegistry), Maps.newLinkedHashMap(), remaps.get(registryName), frozenRegistry, registryName); } - private static > void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map> remaps, LinkedHashMap> missing, Map.Entry snapEntry, Class regType) + private static > void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map> remaps, LinkedHashMap> missing, Map.Entry snapEntry, PersistentRegistry typeRegistry) { ResourceLocation registryName = snapEntry.getKey(); + Class regType = typeRegistry.getRegistrySuperType(registryName); //Translate old names if ("fml:blocks".equals(registryName.toString())) registryName = PersistentRegistryManager.BLOCKS; @@ -347,7 +354,7 @@ public class PersistentRegistryManager } for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + loadRegistry(r.getKey(), PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE); } // the id mapping has reverted, fire remap events for those that care about id changes Loader.instance().fireRemapEvent(ImmutableMap.of(), ImmutableMap.of(), true); @@ -362,7 +369,7 @@ public class PersistentRegistryManager FMLLog.fine("Freezing block and item id maps"); for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.ACTIVE, PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + loadRegistry(r.getKey(), PersistentRegistry.ACTIVE, PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE); } forAllRegistries(PersistentRegistry.FROZEN, ValidateRegistryFunction.OPERATION); }