mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Fix intrusive handlers on dummy objects.
This commit is contained in:
1 parent
c1874bb5ab
commit
eb8fe02a5e
4 files changed
+45
-7
No files matched your search
@@ -876,6 +876,29 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
if (this.dummyFactory == null)
|
||||
return false;
|
||||
|
||||
ForgeRegistry<V> active = RegistryManager.ACTIVE.getRegistry(getRegistryKey());
|
||||
Optional<NamespacedHolderHelper<V>> holders = active.getHolderHelper();
|
||||
if (holders.isPresent() && holders.get().isIntrusive() && holders.get().isFrozen())
|
||||
{
|
||||
try
|
||||
{
|
||||
// We have to unfreeze the ACTIVE registry because a lot of vanilla objects use intrusive handlers in object init.
|
||||
holders.get().unfreeze();
|
||||
createAndAddDummy(key, id);
|
||||
}
|
||||
finally
|
||||
{
|
||||
holders.get().freeze();
|
||||
}
|
||||
}
|
||||
else
|
||||
createAndAddDummy(key, id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createAndAddDummy(ResourceLocation key, int id)
|
||||
{
|
||||
V dummy = this.dummyFactory.createDummy(key);
|
||||
LOGGER.debug(REGISTRIES,"Registry {} Dummy Add: {} {} -> {}", this.name, key, id, dummy);
|
||||
|
||||
@@ -906,8 +929,6 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
if (realId != id)
|
||||
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.name, key, id, realId);
|
||||
this.dummies.add(key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Public for tests
|
||||
|
||||
@@ -737,7 +737,7 @@ public class GameData
|
||||
}
|
||||
}
|
||||
|
||||
RegistryManager STAGING = new RegistryManager("STAGING");
|
||||
RegistryManager STAGING = new RegistryManager();
|
||||
|
||||
final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap();
|
||||
final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap();
|
||||
|
||||
@@ -236,10 +236,20 @@ class NamespacedHolderHelper<T extends IForgeRegistryEntry<T>>
|
||||
this.frozen = false;
|
||||
}
|
||||
|
||||
boolean isFrozen()
|
||||
{
|
||||
return this.frozen;
|
||||
}
|
||||
|
||||
boolean isIntrusive()
|
||||
{
|
||||
return this.holderLookup != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Holder<T> onAdded(RegistryManager stage, int id, T newValue, T oldValue)
|
||||
{
|
||||
if (stage != RegistryManager.ACTIVE)
|
||||
if (stage != RegistryManager.ACTIVE && (this.holderLookup == null || !stage.isStaging())) // Intrusive handlers need updating in staging.
|
||||
return null; // Only do holder shit on the active registries, not pending or snapshots.
|
||||
|
||||
ResourceKey<T> key = ResourceKey.create(this.self.key(), newValue.getRegistryName());
|
||||
|
||||
@@ -7,13 +7,11 @@ package net.minecraftforge.registries;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
@@ -28,7 +26,6 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraftforge.fml.IModStateTransition;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.network.HandshakeMessages;
|
||||
import net.minecraftforge.registries.ForgeRegistry.Snapshot;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -50,6 +47,11 @@ public class RegistryManager
|
||||
private Map<ResourceLocation, ResourceLocation> legacyNames = new HashMap<>();
|
||||
private final String name;
|
||||
|
||||
RegistryManager()
|
||||
{
|
||||
this("STAGING");
|
||||
}
|
||||
|
||||
public RegistryManager(String name)
|
||||
{
|
||||
this.name = name;
|
||||
@@ -60,6 +62,11 @@ public class RegistryManager
|
||||
return this.name;
|
||||
}
|
||||
|
||||
boolean isStaging()
|
||||
{
|
||||
return "STAGING".equals(this.name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V extends IForgeRegistryEntry<V>> Class<V> getSuperType(ResourceLocation key)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user