mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
More cleanups, removed deprecated UniqueIdentifier {ResourceLocation now}
This commit is contained in:
1 parent
e2df8d1be3
commit
edbc56b2ff
4 files changed
+28
-143
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<? extends ItemBlock> 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
|
||||
+19
-12
@@ -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<Class<? extends IForgeRegistryEntry<?>>, ResourceLocation> registrySuperTypes = HashBiMap.create();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T extends IForgeRegistryEntry<?>> FMLControlledNamespacedRegistry<T> getRegistry(ResourceLocation key, Class<T> regType)
|
||||
private <T extends IForgeRegistryEntry<T>> Class<T> getRegistrySuperType(ResourceLocation key)
|
||||
{
|
||||
return (Class<T>)registrySuperTypes.inverse().get(key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends IForgeRegistryEntry<?>> FMLControlledNamespacedRegistry<T> getRegistry(ResourceLocation key, Class<T> regType)
|
||||
{
|
||||
return (FMLControlledNamespacedRegistry<T>)registries.get(key);
|
||||
}
|
||||
|
||||
<T extends IForgeRegistryEntry<?>> FMLControlledNamespacedRegistry<T> getOrShallowCopyRegistry(ResourceLocation key, Class<T> regType, FMLControlledNamespacedRegistry<T> other)
|
||||
private <T extends IForgeRegistryEntry<?>> FMLControlledNamespacedRegistry<T> getOrShallowCopyRegistry(ResourceLocation key, Class<T> regType, FMLControlledNamespacedRegistry<T> other)
|
||||
{
|
||||
if (!registries.containsKey(key))
|
||||
{
|
||||
@@ -152,7 +156,7 @@ public class PersistentRegistryManager
|
||||
// Load the snapshot into the "STAGING" registry
|
||||
for (Map.Entry<ResourceLocation, GameDataSnapshot.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<ResourceLocation, FMLControlledNamespacedRegistry<?>> 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<ResourceLocation, FMLControlledNamespacedRegistry<?>> 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 <T extends IForgeRegistryEntry<?>> void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, Class<T> regType)
|
||||
private static <T extends IForgeRegistryEntry<T>> void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, PersistentRegistry typeRegistry)
|
||||
{
|
||||
Class<T> regType = typeRegistry.getRegistrySuperType(registryName);
|
||||
FMLControlledNamespacedRegistry<T> fromRegistry = from.getRegistry(registryName, regType);
|
||||
if (fromRegistry == null)
|
||||
{
|
||||
@@ -287,16 +292,18 @@ public class PersistentRegistryManager
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends IForgeRegistryEntry<?>> void loadFrozenDataToStagingRegistry(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, ResourceLocation registryName, Class<T> regType)
|
||||
private static <T extends IForgeRegistryEntry<T>> void loadFrozenDataToStagingRegistry(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, ResourceLocation registryName, PersistentRegistry typeRegistry)
|
||||
{
|
||||
Class<T> regType = typeRegistry.getRegistrySuperType(registryName);
|
||||
FMLControlledNamespacedRegistry<T> frozenRegistry = PersistentRegistry.FROZEN.getRegistry(registryName, regType);
|
||||
FMLControlledNamespacedRegistry<T> newRegistry = PersistentRegistry.STAGING.getOrShallowCopyRegistry(registryName, regType, frozenRegistry);
|
||||
newRegistry.loadIds(frozenRegistry.getEntriesNotIn(newRegistry), Maps.<ResourceLocation, Integer>newLinkedHashMap(), remaps.get(registryName), frozenRegistry, registryName);
|
||||
}
|
||||
|
||||
private static <T extends IForgeRegistryEntry<?>> void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing, Map.Entry<ResourceLocation, GameDataSnapshot.Entry> snapEntry, Class<T> regType)
|
||||
private static <T extends IForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing, Map.Entry<ResourceLocation, GameDataSnapshot.Entry> snapEntry, PersistentRegistry typeRegistry)
|
||||
{
|
||||
ResourceLocation registryName = snapEntry.getKey();
|
||||
Class<T> 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<ResourceLocation, FMLControlledNamespacedRegistry<?>> 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.<ResourceLocation, Integer[]>of(), ImmutableMap.<ResourceLocation, Integer[]>of(), true);
|
||||
@@ -362,7 +369,7 @@ public class PersistentRegistryManager
|
||||
FMLLog.fine("Freezing block and item id maps");
|
||||
for (Map.Entry<ResourceLocation, FMLControlledNamespacedRegistry<?>> 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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user