Check name prefix used for tile entity registrations (#4681)
This commit is contained in:
parent
40b567e962
commit
1d863cdefc
4 changed files with 29 additions and 17 deletions
|
@ -226,11 +226,19 @@ public class GameRegistry
|
||||||
FurnaceRecipes.instance().addSmeltingRecipe(input, output, xp);
|
FurnaceRecipes.instance().addSmeltingRecipe(input, output, xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated //TODO: Remove in 1.13, Use ResourceLocation version.
|
||||||
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String key)
|
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String key)
|
||||||
{
|
{
|
||||||
|
// As return is ignored for compatibility, always check namespace
|
||||||
|
GameData.checkPrefix(new ResourceLocation(key).toString());
|
||||||
TileEntity.register(key, tileEntityClass);
|
TileEntity.register(key, tileEntityClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, ResourceLocation key)
|
||||||
|
{
|
||||||
|
registerTileEntity(tileEntityClass, key.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated set your item's {@link Item#getItemBurnTime(ItemStack)} or subscribe to {@link FurnaceFuelBurnTimeEvent} instead.
|
* @deprecated set your item's {@link Item#getItemBurnTime(ItemStack)} or subscribe to {@link FurnaceFuelBurnTimeEvent} instead.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -51,8 +51,11 @@ import net.minecraftforge.event.RegistryEvent;
|
||||||
import net.minecraftforge.event.RegistryEvent.MissingMappings;
|
import net.minecraftforge.event.RegistryEvent.MissingMappings;
|
||||||
import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.common.FMLContainer;
|
||||||
import net.minecraftforge.fml.common.FMLLog;
|
import net.minecraftforge.fml.common.FMLLog;
|
||||||
|
import net.minecraftforge.fml.common.InjectedModContainer;
|
||||||
import net.minecraftforge.fml.common.Loader;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
import net.minecraftforge.fml.common.StartupQuery;
|
import net.minecraftforge.fml.common.StartupQuery;
|
||||||
import net.minecraftforge.fml.common.ZipperUtil;
|
import net.minecraftforge.fml.common.ZipperUtil;
|
||||||
import net.minecraftforge.fml.common.registry.EntityEntry;
|
import net.minecraftforge.fml.common.registry.EntityEntry;
|
||||||
|
@ -69,6 +72,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -756,6 +760,21 @@ public class GameData
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation checkPrefix(String name)
|
||||||
|
{
|
||||||
|
int index = name.lastIndexOf(':');
|
||||||
|
String oldPrefix = index == -1 ? "" : name.substring(0, index).toLowerCase(Locale.ROOT);
|
||||||
|
name = index == -1 ? name : name.substring(index + 1);
|
||||||
|
ModContainer mc = Loader.instance().activeModContainer();
|
||||||
|
String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId().toLowerCase(Locale.ROOT);
|
||||||
|
if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
|
||||||
|
{
|
||||||
|
FMLLog.log.warn("Potentially Dangerous alternative prefix `{}` for name `{}`, expected `{}`. This could be a intended override, but in most cases indicates a broken mod.", oldPrefix, name, prefix);
|
||||||
|
prefix = oldPrefix;
|
||||||
|
}
|
||||||
|
return new ResourceLocation(prefix, name);
|
||||||
|
}
|
||||||
|
|
||||||
private static Field regName;
|
private static Field regName;
|
||||||
private static void forceRegistryName(IForgeRegistryEntry<?> entry, ResourceLocation name)
|
private static void forceRegistryName(IForgeRegistryEntry<?> entry, ResourceLocation name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,11 +22,6 @@ package net.minecraftforge.registries;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.fml.common.FMLContainer;
|
|
||||||
import net.minecraftforge.fml.common.FMLLog;
|
|
||||||
import net.minecraftforge.fml.common.InjectedModContainer;
|
|
||||||
import net.minecraftforge.fml.common.Loader;
|
|
||||||
import net.minecraftforge.fml.common.ModContainer;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -75,17 +70,7 @@ public interface IForgeRegistryEntry<V>
|
||||||
if (getRegistryName() != null)
|
if (getRegistryName() != null)
|
||||||
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
|
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
|
||||||
|
|
||||||
int index = name.lastIndexOf(':');
|
this.registryName = GameData.checkPrefix(name);
|
||||||
String oldPrefix = index == -1 ? "" : name.substring(0, index).toLowerCase();
|
|
||||||
name = index == -1 ? name : name.substring(index + 1);
|
|
||||||
ModContainer mc = Loader.instance().activeModContainer();
|
|
||||||
String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId().toLowerCase();
|
|
||||||
if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
|
|
||||||
{
|
|
||||||
FMLLog.log.info("Potentially Dangerous alternative prefix `{}` for name `{}`, expected `{}`. This could be a intended override, but in most cases indicates a broken mod.", oldPrefix, name, prefix);
|
|
||||||
prefix = oldPrefix;
|
|
||||||
}
|
|
||||||
this.registryName = new ResourceLocation(prefix, name);
|
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -251,7 +251,7 @@ public class FastTESRTransparentTest
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent evt)
|
public void preInit(FMLPreInitializationEvent evt)
|
||||||
{
|
{
|
||||||
GameRegistry.registerTileEntity(TransparentFastTE.class, "fast-tesr-te");
|
GameRegistry.registerTileEntity(TransparentFastTE.class, MODID + ":fast-tesr-te");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
@EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||||
|
|
Loading…
Reference in a new issue