diff --git a/patches/minecraft/net/minecraft/enchantment/Enchantment.java.patch b/patches/minecraft/net/minecraft/enchantment/Enchantment.java.patch index bd1ecc9102..682828fbba 100644 --- a/patches/minecraft/net/minecraft/enchantment/Enchantment.java.patch +++ b/patches/minecraft/net/minecraft/enchantment/Enchantment.java.patch @@ -1,5 +1,17 @@ --- ../src-base/minecraft/net/minecraft/enchantment/Enchantment.java +++ ../src-work/minecraft/net/minecraft/enchantment/Enchantment.java +@@ -12,9 +12,9 @@ + import net.minecraft.util.registry.RegistryNamespaced; + import net.minecraft.util.text.translation.I18n; + +-public abstract class Enchantment ++public abstract class Enchantment extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl + { +- public static final RegistryNamespaced field_185264_b = new RegistryNamespaced(); ++ public static final RegistryNamespaced field_185264_b = net.minecraftforge.fml.common.registry.GameData.getEnchantmentRegistry(); + private final EntityEquipmentSlot[] field_185263_a; + private final Enchantment.Rarity field_77333_a; + public EnumEnchantmentType field_77351_y; @@ -118,7 +118,7 @@ public boolean func_92089_a(ItemStack p_92089_1_) diff --git a/patches/minecraft/net/minecraft/potion/PotionType.java.patch b/patches/minecraft/net/minecraft/potion/PotionType.java.patch new file mode 100644 index 0000000000..43c7e4b7d1 --- /dev/null +++ b/patches/minecraft/net/minecraft/potion/PotionType.java.patch @@ -0,0 +1,16 @@ +--- ../src-base/minecraft/net/minecraft/potion/PotionType.java ++++ ../src-work/minecraft/net/minecraft/potion/PotionType.java +@@ -8,10 +8,11 @@ + import net.minecraftforge.fml.relauncher.Side; + import net.minecraftforge.fml.relauncher.SideOnly; + +-public class PotionType ++public class PotionType extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl + { ++ @Deprecated // unused + private static final ResourceLocation field_185177_b = new ResourceLocation("water"); +- public static final RegistryNamespacedDefaultedByKey field_185176_a = new RegistryNamespacedDefaultedByKey(field_185177_b); ++ public static final RegistryNamespacedDefaultedByKey field_185176_a = net.minecraftforge.fml.common.registry.GameData.getPotionTypesRegistry(); + private static int field_185178_c; + private final String field_185179_d; + private final ImmutableList field_185180_e; diff --git a/patches/minecraft/net/minecraft/util/SoundEvent.java.patch b/patches/minecraft/net/minecraft/util/SoundEvent.java.patch new file mode 100644 index 0000000000..26b5a580d3 --- /dev/null +++ b/patches/minecraft/net/minecraft/util/SoundEvent.java.patch @@ -0,0 +1,14 @@ +--- ../src-base/minecraft/net/minecraft/util/SoundEvent.java ++++ ../src-work/minecraft/net/minecraft/util/SoundEvent.java +@@ -4,9 +4,9 @@ + import net.minecraftforge.fml.relauncher.Side; + import net.minecraftforge.fml.relauncher.SideOnly; + +-public class SoundEvent ++public class SoundEvent extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl + { +- public static final RegistryNamespaced field_187505_a = new RegistryNamespaced(); ++ public static final RegistryNamespaced field_187505_a = net.minecraftforge.fml.common.registry.GameData.getSoundEventRegistry(); + private final ResourceLocation field_187506_b; + private static int field_187507_c = 0; + diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameData.java b/src/main/java/net/minecraftforge/fml/common/registry/GameData.java index 3258b9018b..ca49d8294f 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameData.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameData.java @@ -17,11 +17,15 @@ import java.util.Map; import com.google.common.collect.HashBiMap; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.enchantment.Enchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionType; import net.minecraft.util.ObjectIntIdentityMap; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.Loader; @@ -31,14 +35,21 @@ import com.google.common.collect.BiMap; public class GameData { - static final int MIN_BLOCK_ID = 0; - static final int MAX_BLOCK_ID = 4095; - static final int MIN_ITEM_ID = 4096; - static final int MAX_ITEM_ID = 31999; - static final int MIN_POTION_ID = 0; // 0-~31 are vanilla, forge start at 32 - static final int MAX_POTION_ID = 255; // S1DPacketEntityEffect sends bytes, we can only use 255 - static final int MIN_BIOME_ID = 0; // 0-~31 are vanilla, forge start at 32 - static final int MAX_BIOME_ID = 255; // S1DPacketEntityEffect sends bytes, we can only use 255 + private static final int MIN_BLOCK_ID = 0; + private static final int MAX_BLOCK_ID = 4095; + private static final int MIN_ITEM_ID = 4096; + private static final int MAX_ITEM_ID = 31999; + private static final int MIN_POTION_ID = 0; // 0-~31 are vanilla, forge start at 32 + private static final int MAX_POTION_ID = 255; // SPacketEntityEffect sends bytes, we can only use 255 + private static final int MIN_BIOME_ID = 0; + private static final int MAX_BIOME_ID = 255; // Maximum number in a byte in the chunk + private static final int MIN_SOUND_ID = 0; // Varint + private static final int MAX_SOUND_ID = Integer.MAX_VALUE; // Varint (SPacketSoundEffect) + private static final int MIN_POTIONTYPE_ID = 0; // Int + private static final int MAX_POTIONTYPE_ID = Integer.MAX_VALUE; // Int (SPacketEffect) + private static final int MIN_ENCHANTMENT_ID = 0; // Int + private static final int MAX_ENCHANTMENT_ID = Integer.MAX_VALUE; // Int - not serialized as an ID? + private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap"); private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid"); @@ -50,51 +61,63 @@ public class GameData iItemRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ITEMS, Item.class, null, MIN_ITEM_ID, MAX_ITEM_ID, true, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE); iPotionRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONS, Potion.class, null, MIN_POTION_ID, MAX_POTION_ID, false, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE); iBiomeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BIOMES, BiomeGenBase.class, null, MIN_BIOME_ID, MAX_BIOME_ID, false, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE); + iSoundEventRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.SOUNDEVENTS, SoundEvent.class, null, MIN_SOUND_ID, MAX_SOUND_ID, false, null, null, null); + ResourceLocation WATER = new ResourceLocation("water"); + iPotionTypeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONTYPES, PotionType.class, WATER, MIN_POTIONTYPE_ID, MAX_POTIONTYPE_ID, false, null, null, null); + iEnchantmentRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ENCHANTMENTS, Enchantment.class, null, MIN_ENCHANTMENT_ID, MAX_ENCHANTMENT_ID, false, null, null, null); } - // public api + // internal registry objects + private final FMLControlledNamespacedRegistry iBlockRegistry; + private final FMLControlledNamespacedRegistry iItemRegistry; + private final FMLControlledNamespacedRegistry iPotionRegistry; + private final FMLControlledNamespacedRegistry iBiomeRegistry; + private final FMLControlledNamespacedRegistry iSoundEventRegistry; + private final FMLControlledNamespacedRegistry iPotionTypeRegistry; + private final FMLControlledNamespacedRegistry iEnchantmentRegistry; - /** - * Get the currently active block registry. - * - * @return Block Registry. - */ + /** INTERNAL ONLY */ + @Deprecated public static FMLControlledNamespacedRegistry getBlockRegistry() { return getMain().iBlockRegistry; } - /** - * Get the currently active item registry. - * - * @return Item Registry. - */ + /** INTERNAL ONLY */ + @Deprecated public static FMLControlledNamespacedRegistry getItemRegistry() { return getMain().iItemRegistry; } - /** - * Get the currently active potion registry. - * - * @return Potion Registry. - */ + /** INTERNAL ONLY */ + @Deprecated public static FMLControlledNamespacedRegistry getPotionRegistry() { return getMain().iPotionRegistry; } + /** INTERNAL ONLY */ + @Deprecated public static FMLControlledNamespacedRegistry getBiomeRegistry() { return getMain().iBiomeRegistry; } + /** INTERNAL ONLY */ + @Deprecated + public static FMLControlledNamespacedRegistry getSoundEventRegistry() { return getMain().iSoundEventRegistry; } - /*************************************************** - * INTERNAL CODE FROM HERE ON DO NOT USE! - ***************************************************/ + /** INTERNAL ONLY */ + @Deprecated + public static FMLControlledNamespacedRegistry getPotionTypesRegistry() { return getMain().iPotionTypeRegistry; } + /** INTERNAL ONLY */ + @Deprecated + public static FMLControlledNamespacedRegistry getEnchantmentRegistry() { return getMain().iEnchantmentRegistry; } + @Deprecated static Item findItem(String modId, String name) { return getMain().iItemRegistry.getObject(new ResourceLocation(modId, name)); } + @Deprecated static Block findBlock(String modId, String name) { return getMain().iBlockRegistry.getObject(new ResourceLocation(modId, name)); @@ -105,17 +128,13 @@ public class GameData return mainData; } - // internal registry objects - private final FMLControlledNamespacedRegistry iBlockRegistry; - private final FMLControlledNamespacedRegistry iItemRegistry; - private final FMLControlledNamespacedRegistry iPotionRegistry; - private final FMLControlledNamespacedRegistry iBiomeRegistry; - + @Deprecated int registerItem(Item item, String name) // from GameRegistry { return iItemRegistry.add(-1, addPrefix(name), item); } + @Deprecated int registerBlock(Block block, String name) // from GameRegistry { return iBlockRegistry.add(-1, addPrefix(name), block); diff --git a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java index 294f04ff22..04781af814 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java @@ -130,6 +130,9 @@ public class PersistentRegistryManager public static final ResourceLocation ITEMS = new ResourceLocation("minecraft:items"); public static final ResourceLocation POTIONS = new ResourceLocation("minecraft:potions"); public static final ResourceLocation BIOMES = new ResourceLocation("minecraft:biomes"); + public static final ResourceLocation SOUNDEVENTS = new ResourceLocation("minecraft:soundevents"); + public static final ResourceLocation POTIONTYPES = new ResourceLocation("minecraft:potiontypes"); + public static final ResourceLocation ENCHANTMENTS = new ResourceLocation("minecraft:enchantments"); public static > FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class registryType, ResourceLocation optionalDefaultKey, int minId, int maxId, boolean hasDelegates, IForgeRegistry.AddCallback addCallback, IForgeRegistry.ClearCallback clearCallback, IForgeRegistry.CreateCallback createCallback) {