Restore the ability to register modded TileEntities.
This commit is contained in:
parent
eb6b3ea228
commit
6dcd276de1
4 changed files with 75 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntity.java
|
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntity.java
|
||||||
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntity.java
|
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntity.java
|
||||||
@@ -21,7 +21,7 @@
|
@@ -21,10 +21,10 @@
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -8,7 +8,11 @@
|
||||||
+public abstract class TileEntity implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
|
+public abstract class TileEntity implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
|
||||||
{
|
{
|
||||||
private static final Logger field_145852_a = LogManager.getLogger();
|
private static final Logger field_145852_a = LogManager.getLogger();
|
||||||
private static final RegistryNamespaced < ResourceLocation, Class <? extends TileEntity >> field_190562_f = new RegistryNamespaced();
|
- private static final RegistryNamespaced < ResourceLocation, Class <? extends TileEntity >> field_190562_f = new RegistryNamespaced();
|
||||||
|
+ private static final RegistryNamespaced < ResourceLocation, Class <? extends TileEntity >> field_190562_f = net.minecraftforge.fml.common.registry.GameData.getTileEntityRegistry();
|
||||||
|
protected World field_145850_b;
|
||||||
|
protected BlockPos field_174879_c = BlockPos.field_177992_a;
|
||||||
|
protected boolean field_145846_f;
|
||||||
@@ -60,6 +60,8 @@
|
@@ -60,6 +60,8 @@
|
||||||
public void func_145839_a(NBTTagCompound p_145839_1_)
|
public void func_145839_a(NBTTagCompound p_145839_1_)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.potion.Potion;
|
import net.minecraft.potion.Potion;
|
||||||
import net.minecraft.potion.PotionType;
|
import net.minecraft.potion.PotionType;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ObjectIntIdentityMap;
|
import net.minecraft.util.ObjectIntIdentityMap;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.util.SoundEvent;
|
||||||
|
@ -87,6 +88,8 @@ public class GameData
|
||||||
FMLLog.log(Level.FATAL, e, "Cannot access the 'block' field from ItemBlock, this is fatal!");
|
FMLLog.log(Level.FATAL, e, "Cannot access the 'block' field from ItemBlock, this is fatal!");
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iTileEntityRegistry = new LegacyNamespacedRegistry<Class<? extends TileEntity>>();
|
||||||
}
|
}
|
||||||
// internal registry objects
|
// internal registry objects
|
||||||
private final FMLControlledNamespacedRegistry<Block> iBlockRegistry;
|
private final FMLControlledNamespacedRegistry<Block> iBlockRegistry;
|
||||||
|
@ -97,6 +100,11 @@ public class GameData
|
||||||
private final FMLControlledNamespacedRegistry<PotionType> iPotionTypeRegistry;
|
private final FMLControlledNamespacedRegistry<PotionType> iPotionTypeRegistry;
|
||||||
private final FMLControlledNamespacedRegistry<Enchantment> iEnchantmentRegistry;
|
private final FMLControlledNamespacedRegistry<Enchantment> iEnchantmentRegistry;
|
||||||
|
|
||||||
|
//TODO: ? These are never used by ID, so they don't need to be full registries/persisted.
|
||||||
|
//Need cpw to decide how we want to go about this as they are generic registries that
|
||||||
|
//don't follow the same patterns as the other ones.
|
||||||
|
private final LegacyNamespacedRegistry<Class<? extends TileEntity>> iTileEntityRegistry;
|
||||||
|
|
||||||
/** INTERNAL ONLY */
|
/** INTERNAL ONLY */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static FMLControlledNamespacedRegistry<Block> getBlockRegistry()
|
public static FMLControlledNamespacedRegistry<Block> getBlockRegistry()
|
||||||
|
@ -133,6 +141,10 @@ public class GameData
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static FMLControlledNamespacedRegistry<Enchantment> getEnchantmentRegistry() { return getMain().iEnchantmentRegistry; }
|
public static FMLControlledNamespacedRegistry<Enchantment> getEnchantmentRegistry() { return getMain().iEnchantmentRegistry; }
|
||||||
|
|
||||||
|
/** INTERNAL ONLY */
|
||||||
|
@Deprecated
|
||||||
|
public static LegacyNamespacedRegistry<Class<? extends TileEntity>> getTileEntityRegistry() { return getMain().iTileEntityRegistry; }
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
static Item findItem(String modId, String name)
|
static Item findItem(String modId, String name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -257,7 +257,7 @@ public class GameRegistry
|
||||||
|
|
||||||
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String id)
|
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String id)
|
||||||
{
|
{
|
||||||
// TileEntity.addMapping(tileEntityClass, id);
|
GameData.getTileEntityRegistry().putObject(new ResourceLocation(id), tileEntityClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,14 +270,10 @@ public class GameRegistry
|
||||||
*/
|
*/
|
||||||
public static void registerTileEntityWithAlternatives(Class<? extends TileEntity> tileEntityClass, String id, String... alternatives)
|
public static void registerTileEntityWithAlternatives(Class<? extends TileEntity> tileEntityClass, String id, String... alternatives)
|
||||||
{
|
{
|
||||||
// TileEntity.addMapping(tileEntityClass, id);
|
GameRegistry.registerTileEntity(tileEntityClass, id);
|
||||||
Map<String, Class<?>> teMappings = ObfuscationReflectionHelper.getPrivateValue(TileEntity.class, null, "field_" + "145855_i", "nameToClassMap");
|
|
||||||
for (String s : alternatives)
|
for (String s : alternatives)
|
||||||
{
|
{
|
||||||
if (!teMappings.containsKey(s))
|
GameData.getTileEntityRegistry().addLegacyName(new ResourceLocation(s), new ResourceLocation(id));
|
||||||
{
|
|
||||||
teMappings.put(s, tileEntityClass);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Minecraft Forge
|
||||||
|
* Copyright (c) 2016.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation version 2.1
|
||||||
|
* of the License.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.minecraftforge.fml.common.registry;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.registry.RegistryNamespaced;
|
||||||
|
|
||||||
|
public class LegacyNamespacedRegistry<V> extends RegistryNamespaced<ResourceLocation, V>
|
||||||
|
{
|
||||||
|
private Map<ResourceLocation, ResourceLocation> legacy_names = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public V getObject(@Nullable ResourceLocation name)
|
||||||
|
{
|
||||||
|
V ret = super.getObject(name);
|
||||||
|
|
||||||
|
if (ret == null)
|
||||||
|
{
|
||||||
|
ResourceLocation new_name = legacy_names.get(name);
|
||||||
|
if (new_name != null)
|
||||||
|
ret = super.getObject(new_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLegacyName(ResourceLocation old_name, ResourceLocation new_name)
|
||||||
|
{
|
||||||
|
legacy_names.put(old_name, new_name);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue