Blocks are no longer erased from the registry if the mod isn't present. This means that modded blocks can potentially retain their IDs

even if they are temporarily not present in the game. Currently TileEntity data associated with the block is erased.
This commit is contained in:
cpw 2015-12-23 11:18:54 -05:00
parent 5562c14c45
commit bcecf59a87
2 changed files with 23 additions and 1 deletions

View File

@ -138,11 +138,13 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespacedDefaul
{
throw new IllegalStateException(String.format("Registry entry for name %s doesn't yield the expected id %d.", name, id));
}
/*
// entry is blocked, thus should be empty
if (blockedIds.contains(id))
{
throw new IllegalStateException(String.format("Registry entry for %s %s, id %d, name %s, marked as dangling.", registryName, obj, id, name));
}
*/
}
}

View File

@ -19,7 +19,11 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
@ -167,6 +171,18 @@ public class PersistentRegistryManager
return missedMappings;
}
// If we're loading from disk, we can actually substitute air in the block map for anything that is otherwise "missing". This keeps the reference in the map, in case
// the block comes back later
if (injectFrozenData)
{
for (Map.Entry<ResourceLocation, Integer> missingBlock: missing.get(BLOCKS).entrySet())
{
ResourceLocation rl = missingBlock.getKey();
Integer id = missingBlock.getValue();
FMLLog.log(Level.DEBUG, "Replacing id %s named as %s with air block. If the mod becomes available again later, it can reload here", id, rl);
PersistentRegistry.STAGING.getRegistry(BLOCKS, Block.class).add(id, rl, new BlockDummyAir());
}
}
// If we're loading up the world from disk, we want to add in the new data that might have been provisioned by mods
if (injectFrozenData)
{
@ -201,7 +217,11 @@ public class PersistentRegistryManager
// Return an empty list, because we're good
return ImmutableList.of();
}
private static class BlockDummyAir extends BlockAir {
private BlockDummyAir() {
setUnlocalizedName("air");
}
}
private static void forAllRegistries(PersistentRegistry registrySet, Function<Map.Entry<ResourceLocation, FMLControlledNamespacedRegistry<?>>, Void> operation)
{
for (Map.Entry<ResourceLocation, FMLControlledNamespacedRegistry<?>> r : registrySet.registries.entrySet())