diff --git a/fml/patches/minecraft/net/minecraft/block/Block.java.patch b/fml/patches/minecraft/net/minecraft/block/Block.java.patch index 2fc80defda..60c590e5ae 100644 --- a/fml/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/fml/patches/minecraft/net/minecraft/block/Block.java.patch @@ -1,15 +1,18 @@ --- ../src-base/minecraft/net/minecraft/block/Block.java +++ ../src-work/minecraft/net/minecraft/block/Block.java -@@ -39,7 +39,7 @@ +@@ -39,8 +39,9 @@ public class Block { private static final ResourceLocation field_176230_a = new ResourceLocation("air"); - public static final RegistryNamespacedDefaultedByKey field_149771_c = new RegistryNamespacedDefaultedByKey(field_176230_a); +- public static final ObjectIntIdentityMap field_176229_d = new ObjectIntIdentityMap(); + public static final RegistryNamespacedDefaultedByKey field_149771_c = net.minecraftforge.fml.common.registry.GameData.getBlockRegistry(); - public static final ObjectIntIdentityMap field_176229_d = new ObjectIntIdentityMap(); ++ @Deprecated //Modders: DO NOT use this! Use GameRegistry ++ public static final ObjectIntIdentityMap field_176229_d = net.minecraftforge.fml.common.registry.GameData.getBlockStateIDMap(); private CreativeTabs field_149772_a; public static final Block.SoundType field_149769_e = new Block.SoundType("stone", 1.0F, 1.0F); -@@ -124,6 +124,9 @@ + public static final Block.SoundType field_149766_f = new Block.SoundType("wood", 1.0F, 1.0F); +@@ -124,6 +125,9 @@ private String field_149770_b; private static final String __OBFID = "CL_00000199"; diff --git a/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java b/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java index 02da7550a0..9ffb22ab13 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java @@ -26,9 +26,11 @@ import java.util.Map.Entry; import java.util.Set; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.ObjectIntIdentityMap; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLLog; @@ -384,6 +386,10 @@ public class GameData { } } } + + // Clear State map for it's ready for us to register below. + GameData.BLOCKSTATE_TO_ID.clear(); + // process blocks and items in the world, blocks in the first pass, items in the second // blocks need to be added first for proper ItemBlock handling for (int pass = 0; pass < 2; pass++) @@ -484,6 +490,17 @@ public class GameData { Loader.instance().fireRemapEvent(remaps); // The id map changed, ensure we apply object holders ObjectHolderRegistry.INSTANCE.applyObjectHolders(); + + // Rebuild the state map for all blocks. TODO: Clean this up to a better system when Block.BLOCK_STATE_IDS is cleaned up. + GameData.BLOCKSTATE_TO_ID.clear(); + for (Block block : getMain().iBlockRegistry.typeSafeIterable()) + { + int id = getMain().iBlockRegistry.getId(block); + for (IBlockState state : ((List)block.getBlockState().getValidStates())) + { + GameData.BLOCKSTATE_TO_ID.put(state, id << 4 | block.getMetaFromState(state)); + } + } return ImmutableList.of(); } @@ -789,6 +806,12 @@ public class GameData { useSlot(blockId); ((RegistryDelegate.Delegate) block.delegate).setName(name); + + for (IBlockState state : ((List)block.getBlockState().getValidStates())) + { + GameData.BLOCKSTATE_TO_ID.put(state, blockId << 4 | block.getMetaFromState(state)); + } + return blockId; } @@ -933,4 +956,21 @@ public class GameData { { return BLOCK_TO_ITEM; } + + private static ClearableObjectIntIdentityMap BLOCKSTATE_TO_ID = new ClearableObjectIntIdentityMap(); + //Internal: DO NOT USE, will change without warning. + public static ObjectIntIdentityMap getBlockStateIDMap() + { + return BLOCKSTATE_TO_ID; + } + + //Lets us clear the map so we can rebuild it. + private static class ClearableObjectIntIdentityMap extends ObjectIntIdentityMap + { + private void clear() + { + this.field_148749_a.clear(); + this.field_148748_b.clear(); + } + } }