More error cleanup, reinstanted IForgeReigstryEntry.

The abstract class will be used as the default, and to enable delegates but we should keep it api simple by keeping the interface.
Removed some patches that didnt get removed in the rebase.
This commit is contained in:
LexManos committed 2018-09-05 20:06:18 -07:00
1 parent ff6fa2cfaf
commit 2798080f60
35 files changed
+200 -472

No files matched your search

@@ -56,7 +56,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class ForgeRegistry<V extends ForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
{
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
private static Logger LOGGER = LogManager.getLogger();
@@ -22,14 +22,17 @@ package net.minecraftforge.registries;
import com.google.common.reflect.TypeToken;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModThreadContext;
import org.apache.logging.log4j.LogManager;
import javax.annotation.Nullable;
/**
* Default implementation of IForgeRegistryEntry, this is necessary to reduce redundant code.
* This also enables the registrie's ability to manage delegates. Which are automatically updated
* if another entry overrides existing ones in the registry.
*/
@SuppressWarnings("unchecked")
public abstract class ForgeRegistryEntry<V extends ForgeRegistryEntry<V>>
public abstract class ForgeRegistryEntry<V extends ForgeRegistryEntry<V>> implements IForgeRegistryEntry<V>
{
@SuppressWarnings("serial")
private final TypeToken<V> token = new TypeToken<V>(getClass()){};
public final IRegistryDelegate<V> delegate = new RegistryDelegate<>((V)this, (Class<V>)token.getRawType());
private ResourceLocation registryName = null;
@@ -39,16 +42,7 @@ public abstract class ForgeRegistryEntry<V extends ForgeRegistryEntry<V>>
if (getRegistryName() != null)
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
int index = name.lastIndexOf(':');
String oldPrefix = index == -1 ? "" : name.substring(0, index).toLowerCase();
name = index == -1 ? name : name.substring(index + 1);
String prefix = ModThreadContext.get().getActiveContainer().getPrefix();
if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
{
LogManager.getLogger().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);
this.registryName = GameData.checkPrefix(name);
return (V)this;
}
@@ -65,4 +59,4 @@ public abstract class ForgeRegistryEntry<V extends ForgeRegistryEntry<V>>
}
public final Class<V> getRegistryType() { return (Class<V>)token.getRawType(); }
}
}
@@ -25,17 +25,11 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockObserver;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionType;
import net.minecraft.util.ObjectIntIdentityMap;
@@ -43,12 +37,12 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.fml.common.EnhancedRuntimeException;
import net.minecraftforge.fml.ModThreadContext;
import net.minecraftforge.fml.StartupQuery;
import com.google.common.collect.ArrayListMultimap;
@@ -196,7 +190,7 @@ public class GameData
public static void vanillaSnapshot()
{
LOGGER.debug("Creating vanilla freeze snapshot");
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.ACTIVE, RegistryManager.VANILLA, clazz, true);
@@ -244,7 +238,7 @@ public class GameData
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates());
LOGGER.debug(GD, "Reverting to frozen data state.");
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.FROZEN, RegistryManager.ACTIVE, clazz, true);
@@ -680,11 +674,12 @@ public class GameData
STAGING.registries.forEach((name, reg) -> reg.validateContent(name));
// Load the STAGING registry into the ACTIVE registry
for (Map.Entry<ResourceLocation, IForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
//for (Map.Entry<ResourceLocation, IForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
RegistryManager.ACTIVE.registries.forEach((key, value) ->
{
final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), STAGING, RegistryManager.ACTIVE, registrySuperType, true);
}
final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE.getSuperType(key);
loadRegistry(key, STAGING, RegistryManager.ACTIVE, registrySuperType, true);
});
// Dump the active registry
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name));
@@ -700,7 +695,7 @@ public class GameData
}
//Has to be split because of generics, Yay!
private static <T extends ForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(RegistryManager pool, RegistryManager to, Map<ResourceLocation, Integer[]> remaps, Map<ResourceLocation, Integer> missing, ResourceLocation name, ForgeRegistry.Snapshot snap, Class<T> regType)
private static <T extends IForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(RegistryManager pool, RegistryManager to, Map<ResourceLocation, Integer[]> remaps, Map<ResourceLocation, Integer> missing, ResourceLocation name, ForgeRegistry.Snapshot snap, Class<T> regType)
{
ForgeRegistry<T> active = pool.getRegistry(name);
if (active == null)
@@ -715,7 +710,7 @@ public class GameData
//Another bouncer for generic reasons
@SuppressWarnings("unchecked")
private static <T extends ForgeRegistryEntry<T>> void processMissing(Class<T> clazz, ResourceLocation name, RegistryManager STAGING, MissingMappings<?> e, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
private static <T extends IForgeRegistryEntry<T>> void processMissing(Class<T> clazz, ResourceLocation name, RegistryManager STAGING, MissingMappings<?> e, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
{
List<MissingMappings.Mapping<T>> mappings = ((MissingMappings<T>)e).getAllMappings();
ForgeRegistry<T> active = RegistryManager.ACTIVE.getRegistry(name);
@@ -723,7 +718,7 @@ public class GameData
staging.processMissingEvent(name, active, mappings, missing, remaps, defaulted, failed, injectNetworkDummies);
}
private static <T extends ForgeRegistryEntry<T>> void loadFrozenDataToStagingRegistry(RegistryManager STAGING, ResourceLocation name, Map<ResourceLocation, Integer[]> remaps, Class<T> clazz)
private static <T extends IForgeRegistryEntry<T>> void loadFrozenDataToStagingRegistry(RegistryManager STAGING, ResourceLocation name, Map<ResourceLocation, Integer[]> remaps, Class<T> clazz)
{
ForgeRegistry<T> frozen = RegistryManager.FROZEN.getRegistry(name);
ForgeRegistry<T> newRegistry = STAGING.getRegistry(name, RegistryManager.FROZEN);
@@ -781,11 +776,10 @@ public class GameData
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);
String prefix = ModThreadContext.get().getActiveContainer().getPrefix();
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);
LogManager.getLogger().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;
}
return new ResourceLocation(prefix, name);
@@ -798,7 +792,7 @@ public class GameData
{
try
{
regName = IForgeRegistryEntry.Impl.class.getDeclaredField("registryName");
regName = ForgeRegistryEntry.class.getDeclaredField("registryName");
regName.setAccessible(true);
}
catch (NoSuchFieldException | SecurityException e)
@@ -20,7 +20,6 @@
package net.minecraftforge.registries;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
@@ -34,7 +33,7 @@ import javax.annotation.Nullable;
*
* @param <V> The top level type for the registry
*/
public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterable<V>
public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterable<V>
{
Class<V> getRegistrySuperType();
@@ -49,13 +48,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
@Nullable ResourceLocation getKey(V value);
@Nonnull Set<ResourceLocation> getKeys();
/** @deprecated use {@link #getValuesCollection} */
@Deprecated // TODO: remove in 1.13
@Nonnull List<V> getValues();
@Nonnull
default Collection<V> getValuesCollection() { // TODO rename this to getValues in 1.13
return getValues();
}
@Nonnull Collection<V> getValues();
@Nonnull Set<Entry<ResourceLocation, V>> getEntries();
/**
@@ -72,7 +65,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
* Callback fired when objects are added to the registry. This will fire when the registry is rebuilt
* on the client side from a server side synchronization, or when a world is loaded.
*/
interface AddCallback<V extends ForgeRegistryEntry<V>>
interface AddCallback<V extends IForgeRegistryEntry<V>>
{
void onAdd(IForgeRegistryInternal<V> owner, RegistryManager stage, int id, V obj, @Nullable V oldObj);
}
@@ -81,7 +74,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
* Callback fired when the registry is cleared. This is done before a registry is reloaded from client
* or server.
*/
interface ClearCallback<V extends ForgeRegistryEntry<V>>
interface ClearCallback<V extends IForgeRegistryEntry<V>>
{
void onClear(IForgeRegistryInternal<V> owner, RegistryManager stage);
}
@@ -89,7 +82,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
/**
* Callback fired when a registry instance is created. Populate slave maps here.
*/
interface CreateCallback<V extends ForgeRegistryEntry<V>>
interface CreateCallback<V extends IForgeRegistryEntry<V>>
{
void onCreate(IForgeRegistryInternal<V> owner, RegistryManager stage);
}
@@ -105,7 +98,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
/**
* Factory for creating dummy entries, allowing worlds to be loaded and keep the missing block references.
*/
interface DummyFactory<V extends ForgeRegistryEntry<V>>
interface DummyFactory<V extends IForgeRegistryEntry<V>>
{
V createDummy(ResourceLocation key);
}
@@ -113,7 +106,7 @@ public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterabl
/**
*
*/
interface MissingFactory<V extends ForgeRegistryEntry<V>>
interface MissingFactory<V extends IForgeRegistryEntry<V>>
{
V createMissing(ResourceLocation key, boolean isNetwork);
}
@@ -18,9 +18,6 @@
*/
package net.minecraftforge.registries;
import com.google.common.reflect.TypeToken;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
@@ -41,7 +38,7 @@ public interface IForgeRegistryEntry<V>
*
* @param name Unique registry name
* @return This instance
* /
*/
V setRegistryName(ResourceLocation name);
/**
@@ -50,44 +47,15 @@ public interface IForgeRegistryEntry<V>
* If neither are valid null is returned.
*
* @return Unique identifier or null.
* /
*/
@Nullable
ResourceLocation getRegistryName();
/**
* Determines the type for this entry, used to look up the correct registry in the global registries list as there can only be one
* registry per concrete class.
*
* @return Root registry type.
*/
Class<V> getRegistryType();
// Default implementation, modders who make extra items SHOULD extend this instead of Object.
// So, all fields in interfaces are forced static, so even with Java8 people must still extend this.
@SuppressWarnings({ "serial", "unchecked" })
public static class Impl<T extends IForgeRegistryEntry<T>> implements IForgeRegistryEntry<T>
{
private TypeToken<T> token = new TypeToken<T>(getClass()){};
public final IRegistryDelegate<T> delegate = new RegistryDelegate<T>((T)this, (Class<T>)token.getRawType());
private ResourceLocation registryName = null;
public final T setRegistryName(String name)
{
if (getRegistryName() != null)
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
this.registryName = GameData.checkPrefix(name);
return (T)this;
}
//Helper functions
@Override
public final T setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
public final T setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
@Override
@Nullable
public final ResourceLocation getRegistryName()
{
if (delegate.name() != null) return delegate.name();
return registryName != null ? registryName : null;
}
@Override
public final Class<T> getRegistryType() { return (Class<T>) token.getRawType(); };
}
*/
}
@@ -21,7 +21,7 @@ package net.minecraftforge.registries;
import net.minecraft.util.ResourceLocation;
public interface IForgeRegistryInternal<V extends ForgeRegistryEntry<V>> extends IForgeRegistry<V>
public interface IForgeRegistryInternal<V extends IForgeRegistryEntry<V>> extends IForgeRegistry<V>
{
void setSlaveMap(ResourceLocation name, Object obj);
}
@@ -33,7 +33,7 @@ import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedDefaultedWrapper<V extends ForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, V> implements ILockableRegistry
class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
@@ -130,7 +130,7 @@ class NamespacedDefaultedWrapper<V extends ForgeRegistryEntry<V>> extends Regist
@Override
public void lock(){ this.locked = true; }
public static class Factory<V extends ForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override
@@ -33,7 +33,7 @@ import net.minecraft.util.registry.RegistryNamespaced;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedWrapper<V extends ForgeRegistryEntry<V>> extends RegistryNamespaced<ResourceLocation, V> implements ILockableRegistry
class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespaced<ResourceLocation, V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
@@ -125,7 +125,7 @@ class NamespacedWrapper<V extends ForgeRegistryEntry<V>> extends RegistryNamespa
@Override
public void lock(){ this.locked = true; }
public static class Factory<V extends ForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override
@@ -28,7 +28,7 @@ import net.minecraftforge.registries.IForgeRegistry.*;
import javax.annotation.Nullable;
public class RegistryBuilder<T extends ForgeRegistryEntry<T>>
public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
{
private ResourceLocation registryName;
private Class<T> registryType;
@@ -44,7 +44,7 @@ public class RegistryManager
public static final RegistryManager FROZEN = new RegistryManager("FROZEN");
BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> registries = HashBiMap.create();
private BiMap<Class<? extends ForgeRegistryEntry<?>>, ResourceLocation> superTypes = HashBiMap.create();
private BiMap<Class<? extends IForgeRegistryEntry<?>>, ResourceLocation> superTypes = HashBiMap.create();
private Set<ResourceLocation> persisted = Sets.newHashSet();
private final String name;