Some more stuffs. ObjectHolder's replacement?

This commit is contained in:
cpw authored and LexManos committed 2018-09-05 11:58:31 -07:00
1 parent baa9dfe55a
commit 06b16aaa19
47 files changed
+987 -269

No files matched your search

@@ -51,12 +51,15 @@ import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.InjectedModContainer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
{
public static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugRegistryEntries", "false"));
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
private static Logger LOGGER = LogManager.getLogger("FML");
private final RegistryManager stage;
private final BiMap<Integer, V> ids = HashBiMap.create();
private final BiMap<ResourceLocation, V> names = HashBiMap.create();
@@ -293,7 +296,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
V oldEntry = getRaw(key);
if (oldEntry == value) // already registered, return prev registration's id
{
FMLLog.bigWarning("Registry {}: The object {} has been registered twice for the same name {}.", this.superType.getSimpleName(), value, key);
LOGGER.warn(REGISTRIES,"Registry {}: The object {} has been registered twice for the same name {}.", this.superType.getSimpleName(), value, key);
return this.getID(value);
}
if (oldEntry != null) // duplicate name
@@ -302,8 +305,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
throw new IllegalArgumentException(String.format("The name %s has been registered twice, for %s and %s.", key, getRaw(key), value));
if (owner == null)
throw new IllegalStateException(String.format("Could not determine owner for the override on %s. Value: %s", key, value));
if (DEBUG)
FMLLog.log.debug("Registry {} Override: {} {} -> {}", this.superType.getSimpleName(), key, oldEntry, value);
LOGGER.debug(REGISTRIES,"Registry {} Override: {} {} -> {}", this.superType.getSimpleName(), key, oldEntry, value);
idToUse = this.getID(oldEntry);
}
@@ -345,11 +347,10 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
if (this.add != null)
this.add.onAdd(this, this.stage, idToUse, value, oldEntry);
if (this.dummies.remove(key) && DEBUG)
FMLLog.log.debug("Registry {} Dummy Remove: {}", this.superType.getSimpleName(), key);
if (this.dummies.remove(key))
LOGGER.debug(REGISTRIES,"Registry {} Dummy Remove: {}", this.superType.getSimpleName(), key);
if (DEBUG)
FMLLog.log.trace("Registry {} add: {} {} {} (req. id {})", this.superType.getSimpleName(), key, idToUse, value, id);
LOGGER.trace(REGISTRIES,"Registry {} add: {} {} {} (req. id {})", this.superType.getSimpleName(), key, idToUse, value, id);
return idToUse;
}
@@ -377,8 +378,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
if (this.isLocked())
throw new IllegalStateException(String.format("Attempted to register the alias %s -> %s to late", from, to));
this.aliases.put(from, to);
if (DEBUG)
FMLLog.log.trace("Registry {} alias: {} -> {}", this.superType.getSimpleName(), from, to);
LOGGER.trace(REGISTRIES,"Registry {} alias: {} -> {}", this.superType.getSimpleName(), from, to);
}
void addDummy(ResourceLocation key)
@@ -386,8 +386,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
if (this.isLocked())
throw new IllegalStateException(String.format("Attempted to register the dummy %s to late", key));
this.dummies.add(key);
if (DEBUG)
FMLLog.log.trace("Registry {} dummy: {}", this.superType.getSimpleName(), key);
LOGGER.trace(REGISTRIES,"Registry {} dummy: {}", this.superType.getSimpleName(), key);
}
private RegistryDelegate<V> getDelegate(V thing)
@@ -471,8 +470,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
void sync(ResourceLocation name, ForgeRegistry<V> from)
{
if (DEBUG)
FMLLog.log.debug("Registry {} Sync: {} -> {}", this.superType.getSimpleName(), this.stage.getName(), from.stage.getName());
LOGGER.debug(REGISTRIES,"Registry {} Sync: {} -> {}", this.superType.getSimpleName(), this.stage.getName(), from.stage.getName());
if (this == from)
throw new IllegalArgumentException("WTF We are the same!?!?!");
if (from.superType != this.superType)
@@ -509,7 +507,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
int realId = add(id, entry.getValue());
if (id != realId && id != -1)
{
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), id, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), id, realId);
errored = true;
}
}
@@ -521,14 +519,14 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
OverrideOwner owner = from.owners.inverse().get(value);
if (owner == null)
{
FMLLog.log.warn("Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.superType.getSimpleName(), entry.getKey(), value);
LOGGER.warn(REGISTRIES,"Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.superType.getSimpleName(), entry.getKey(), value);
errored = true;
continue;
}
int realId = add(id, value, owner.owner);
if (id != realId && id != -1)
{
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), id, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), id, realId);
errored = true;
}
}
@@ -582,8 +580,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
if (id == null)
throw new IllegalStateException("Removed a entry that did not have an associated id: " + key + " " + value.toString() + " This should never happen unless hackery!");
if (DEBUG)
FMLLog.log.trace("Registry {} remove: {} {}", this.superType.getSimpleName(), key, id);
LOGGER.trace(REGISTRIES,"Registry {} remove: {} {}", this.superType.getSimpleName(), key, id);
}
return value;
@@ -627,8 +624,8 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
Collections.sort(ids);
FMLLog.log.trace("Registry Name : {}", name);
ids.forEach(id -> FMLLog.log.trace(" Registry: {} {} {}", id, getKey(getValue(id)), getValue(id)));
LOGGER.trace(REGISTRIES, "Registry Name : {}", name);
ids.forEach(id -> LOGGER.trace(REGISTRIES," Registry: {} {} {}", id, getKey(getValue(id)), getValue(id)));
}
public void loadIds(Map<ResourceLocation, Integer> ids, Map<ResourceLocation, String> overrides, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remapped, ForgeRegistry<V> old, ResourceLocation name)
@@ -642,13 +639,13 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
if (currId == -1)
{
FMLLog.log.info("Registry {}: Found a missing id from the world {}", this.superType.getSimpleName(), itemName);
LOGGER.info(REGISTRIES,"Registry {}: Found a missing id from the world {}", this.superType.getSimpleName(), itemName);
missing.put(itemName, newId);
continue; // no block/item -> nothing to add
}
else if (currId != newId)
{
FMLLog.log.debug("Registry {}: Fixed {} id mismatch {}: {} (init) -> {} (map).", this.superType.getSimpleName(), name, itemName, currId, newId);
LOGGER.debug(REGISTRIES,"Registry {}: Fixed {} id mismatch {}: {} (init) -> {} (map).", this.superType.getSimpleName(), name, itemName, currId, newId);
remapped.put(itemName, new Integer[] {currId, newId});
}
@@ -674,7 +671,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
OverrideOwner owner = old.owners.inverse().get(value);
if (owner == null)
{
FMLLog.log.warn("Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.superType.getSimpleName(), entry.getKey(), value);
LOGGER.warn(REGISTRIES,"Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.superType.getSimpleName(), entry.getKey(), value);
continue;
}
@@ -683,12 +680,12 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
int realId = add(newId, value, owner.owner);
if (newId != realId)
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
}
int realId = add(newId, obj, primaryName == null ? itemName.getResourceDomain() : primaryName);
if (realId != newId)
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
ovs.remove(itemName);
}
@@ -702,16 +699,16 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
V _new = this.owners.get(new OverrideOwner(owner, itemName));
if (_new == null)
{
FMLLog.log.warn("Registry {}: Skipping override for {}, Unknown owner {}", this.superType.getSimpleName(), itemName, owner);
LOGGER.warn(REGISTRIES,"Registry {}: Skipping override for {}, Unknown owner {}", this.superType.getSimpleName(), itemName, owner);
continue;
}
FMLLog.log.info("Registry {}: Activating override {} for {}", this.superType.getSimpleName(), owner, itemName);
LOGGER.info(REGISTRIES,"Registry {}: Activating override {} for {}", this.superType.getSimpleName(), owner, itemName);
int newId = this.getID(itemName);
int realId = this.add(newId, _new, owner);
if (newId != realId)
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), entry.getKey(), newId, realId);
}
}
}
@@ -722,8 +719,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
return false;
V dummy = this.dummyFactory.createDummy(key);
if (DEBUG)
FMLLog.log.debug("Registry Dummy Add: {} {} -> {}", key, id, dummy);
LOGGER.debug(REGISTRIES,"Registry Dummy Add: {} {} -> {}", key, id, dummy);
//It was blocked before so we need to unset the blocking map
this.availabilityMap.clear(id);
@@ -740,15 +736,14 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
throw new IllegalStateException("Removed a entry that did not have an associated id: " + key + " " + value.toString() + " This should never happen unless hackery!");
if (oldid != id)
FMLLog.log.debug("Registry {}: Dummy ID mismatch {} {} -> {}", this.superType.getSimpleName(), key, oldid, id);
LOGGER.debug(REGISTRIES,"Registry {}: Dummy ID mismatch {} {} -> {}", this.superType.getSimpleName(), key, oldid, id);
if (DEBUG)
FMLLog.log.debug("Registry {} remove: {} {}", this.superType.getSimpleName(), key, oldid);
LOGGER.debug(REGISTRIES,"Registry {} remove: {} {}", this.superType.getSimpleName(), key, oldid);
}
int realId = this.add(id, dummy);
if (realId != id)
FMLLog.log.warn("Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), key, id, realId);
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.superType.getSimpleName(), key, id, realId);
this.dummies.add(key);
return true;
@@ -773,8 +768,8 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
{
V obj = this.names.get(key);
OverrideOwner owner = this.owners.inverse().get(obj);
if (owner == null && DEBUG)
FMLLog.log.debug("Registry {} {}: Invalid override {} {}", this.superType.getSimpleName(), this.stage.getName(), key, obj);
if (owner == null)
LOGGER.debug(REGISTRIES,"Registry {} {}: Invalid override {} {}", this.superType.getSimpleName(), this.stage.getName(), key, obj);
ret.put(key, owner.owner);
}
return ret;
@@ -904,7 +899,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
void processMissingEvent(ResourceLocation name, ForgeRegistry<V> pool, List<MissingMappings.Mapping<V>> mappings, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
{
FMLLog.log.debug("Processing missing event for {}:", name);
LOGGER.debug(REGISTRIES,"Processing missing event for {}:", name);
int ignored = 0;
for (MissingMappings.Mapping<V> remap : mappings)
@@ -916,19 +911,19 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
// entry re-mapped, finish the registration with the new name/object, but the old id
int currId = getID(remap.getTarget());
ResourceLocation newName = pool.getKey(remap.getTarget());
FMLLog.log.debug(" Remapping {} -> {}.", remap.key, newName);
LOGGER.debug(REGISTRIES," Remapping {} -> {}.", remap.key, newName);
missing.remove(remap.key);
//I don't think this will work, but I dont think it ever worked.. the item is already in the map with a different id... we want to fix that..
int realId = this.add(remap.id, remap.getTarget());
if (realId != remap.id)
FMLLog.log.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", newName, this.getRegistrySuperType(), remap.id, realId);
LOGGER.warn(REGISTRIES,"Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", newName, this.getRegistrySuperType(), remap.id, realId);
this.addAlias(remap.key, newName);
if (currId != realId)
{
FMLLog.log.info(" Fixed id mismatch {}: {} (init) -> {} (map).", newName, currId, realId);
LOGGER.info(REGISTRIES,"Fixed id mismatch {}: {} (init) -> {} (map).", newName, currId, realId);
remaps.put(newName, new Integer[] {currId, realId});
}
}
@@ -945,24 +940,24 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
}
else if (action == MissingMappings.Action.IGNORE)
{
FMLLog.log.debug(" Ignoring {}", remap.key);
LOGGER.debug(REGISTRIES,"Ignoring {}", remap.key);
ignored++;
}
else if (action == MissingMappings.Action.FAIL)
{
FMLLog.log.debug(" Failing {}!", remap.key);
LOGGER.debug(REGISTRIES,"Failing {}!", remap.key);
failed.add(remap.key);
}
else if (action == MissingMappings.Action.WARN)
{
FMLLog.log.warn(" {} may cause world breakage!", remap.key);
LOGGER.warn(REGISTRIES,"{} may cause world breakage!", remap.key);
}
this.block(remap.id);
}
}
if (failed.isEmpty() && ignored > 0)
FMLLog.log.debug("There were {} missing mappings that have been ignored", ignored);
LOGGER.debug(REGISTRIES,"There were {} missing mappings that have been ignored", ignored);
}
private static class OverrideOwner
@@ -83,6 +83,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import static net.minecraftforge.fml.Logging.fmlLog;
@@ -116,6 +118,7 @@ public class GameData
private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap");
private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid");
private static final Logger LOGGER = LogManager.getLogger("FML");
private static boolean hasInit = false;
private static final boolean DISABLE_VANILLA_REGISTRIES = Boolean.parseBoolean(System.getProperty("forge.disableVanillaGameData", "false")); // Use for unit tests/debugging
private static final BiConsumer<ResourceLocation, ForgeRegistry<?>> LOCK_VANILLA = (name, reg) -> reg.slaves.values().stream().filter(o -> o instanceof ILockableRegistry).forEach(o -> ((ILockableRegistry)o).lock());
@@ -563,8 +566,7 @@ public class GameData
}
else if (isLocalWorld)
{
if (ForgeRegistry.DEBUG)
FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy);
LOGGER.debug("Registry {}: Resuscitating dummy entry {}", key, dummy);
}
else
{
@@ -751,12 +753,10 @@ public class GameData
if (filter.test(BLOCKS))
{
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(BLOCKS).getRegisterEvent(BLOCKS));
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject any blocks
}
if (filter.test(ITEMS))
{
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(ITEMS).getRegisterEvent(ITEMS));
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject any items
}
for (ResourceLocation rl : keys)
{
@@ -764,7 +764,6 @@ public class GameData
if (rl == BLOCKS || rl == ITEMS) continue;
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(rl).getRegisterEvent(rl));
}
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject everything else
/*