Ensure slave maps are cleaned up when handling registry overrides (#5250)

This commit is contained in:
Ben Staddon authored and tterrag committed 2019-01-03 20:36:32 -05:00
1 parent c5402d50fa
commit 54882f2564
1 file changed
+27
@@ -288,6 +288,15 @@ public class GameData
this.identityMap.clear();
this.objectList.clear();
}
void remove(I key)
{
Integer prev = this.identityMap.remove(key);
if (prev != null)
{
this.objectList.set(prev, null);
}
}
}
@@ -302,6 +311,14 @@ public class GameData
@SuppressWarnings("unchecked")
ClearableObjectIntIdentityMap<IBlockState> blockstateMap = owner.getSlaveMap(BLOCKSTATE_TO_ID, ClearableObjectIntIdentityMap.class);
if (oldBlock != null)
{
for (IBlockState state : oldBlock.getBlockState().getValidStates())
{
blockstateMap.remove(state);
}
}
if ("minecraft:tripwire".equals(block.getRegistryName().toString())) //Tripwire is crap so we have to special case whee!
{
for (int meta = 0; meta < 15; meta++)
@@ -387,6 +404,12 @@ public class GameData
@Override
public void onAdd(IForgeRegistryInternal<Item> owner, RegistryManager stage, int id, Item item, @Nullable Item oldItem)
{
if (oldItem instanceof ItemBlock)
{
@SuppressWarnings("unchecked")
BiMap<Block, Item> blockToItem = owner.getSlaveMap(BLOCK_TO_ITEM, BiMap.class);
blockToItem.remove(((ItemBlock)oldItem).getBlock());
}
if (item instanceof ItemBlock)
{
@SuppressWarnings("unchecked")
@@ -477,6 +500,10 @@ public class GameData
}
@SuppressWarnings("unchecked")
Map<Class<? extends Entity>, EntityEntry> map = owner.getSlaveMap(ENTITY_CLASS_TO_ENTRY, Map.class);
if (oldEntry != null)
{
map.remove(oldEntry.getEntityClass());
}
map.put(entry.getEntityClass(), entry);
}