diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index 7b605588b..5f8654e43 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -1,7 +1,11 @@ --- ../src-base/minecraft/net/minecraft/block/Block.java +++ ../src-work/minecraft/net/minecraft/block/Block.java -@@ -46,8 +46,9 @@ - public class Block +@@ -43,11 +43,12 @@ + import net.minecraftforge.fml.relauncher.Side; + import net.minecraftforge.fml.relauncher.SideOnly; + +-public class Block ++public class Block extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl { private static final ResourceLocation field_176230_a = new ResourceLocation("air"); - public static final RegistryNamespacedDefaultedByKey field_149771_c = new RegistryNamespacedDefaultedByKey(field_176230_a); @@ -12,17 +16,7 @@ public static final AxisAlignedBB field_185505_j = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); public static final AxisAlignedBB field_185506_k = null; private CreativeTabs field_149772_a; -@@ -70,6 +71,9 @@ - private IBlockState field_176228_M; - private String field_149770_b; - -+ public final net.minecraftforge.fml.common.registry.RegistryDelegate delegate = -+ ((net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry)field_149771_c).getDelegate(this, Block.class); -+ - public static int func_149682_b(Block p_149682_0_) - { - return field_149771_c.func_148757_b(p_149682_0_); -@@ -83,7 +87,8 @@ +@@ -83,7 +84,8 @@ public static Block func_149729_e(int p_149729_0_) { @@ -32,7 +26,7 @@ } public static IBlockState func_176220_d(int p_176220_0_) -@@ -268,7 +273,7 @@ +@@ -268,7 +270,7 @@ public boolean func_176200_f(IBlockAccess p_176200_1_, BlockPos p_176200_2_) { @@ -41,7 +35,7 @@ } public Block func_149711_c(float p_149711_1_) -@@ -305,9 +310,10 @@ +@@ -305,9 +307,10 @@ return this.field_149789_z; } @@ -53,7 +47,7 @@ } public AxisAlignedBB func_185496_a(IBlockState p_185496_1_, IBlockAccess p_185496_2_, BlockPos p_185496_3_) -@@ -346,13 +352,13 @@ +@@ -346,13 +349,13 @@ @SideOnly(Side.CLIENT) public int func_185484_c(IBlockState p_185484_1_, IBlockAccess p_185484_2_, BlockPos p_185484_3_) { @@ -69,7 +63,7 @@ } else { -@@ -415,7 +421,7 @@ +@@ -415,7 +418,7 @@ } } @@ -78,7 +72,7 @@ } @SideOnly(Side.CLIENT) -@@ -472,6 +478,10 @@ +@@ -472,6 +475,10 @@ public void func_180663_b(World p_180663_1_, BlockPos p_180663_2_, IBlockState p_180663_3_) { @@ -89,7 +83,7 @@ } public int func_149745_a(Random p_149745_1_) -@@ -486,8 +496,7 @@ +@@ -486,8 +493,7 @@ public float func_180647_a(IBlockState p_180647_1_, EntityPlayer p_180647_2_, World p_180647_3_, BlockPos p_180647_4_) { @@ -99,7 +93,7 @@ } public final void func_176226_b(World p_176226_1_, BlockPos p_176226_2_, IBlockState p_176226_3_, int p_176226_4_) -@@ -497,20 +506,16 @@ +@@ -497,20 +503,16 @@ public void func_180653_a(World p_180653_1_, BlockPos p_180653_2_, IBlockState p_180653_3_, float p_180653_4_, int p_180653_5_) { @@ -125,7 +119,7 @@ } } } -@@ -518,8 +523,13 @@ +@@ -518,8 +520,13 @@ public static void func_180635_a(World p_180635_0_, BlockPos p_180635_1_, ItemStack p_180635_2_) { @@ -140,7 +134,7 @@ float f = 0.5F; double d0 = (double)(p_180635_0_.field_73012_v.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d1 = (double)(p_180635_0_.field_73012_v.nextFloat() * f) + (double)(1.0F - f) * 0.5D; -@@ -588,7 +598,7 @@ +@@ -588,7 +595,7 @@ public boolean func_176196_c(World p_176196_1_, BlockPos p_176196_2_) { @@ -149,7 +143,7 @@ } public boolean func_180639_a(World p_180639_1_, BlockPos p_180639_2_, IBlockState p_180639_3_, EntityPlayer p_180639_4_, EnumHand p_180639_5_, ItemStack p_180639_6_, EnumFacing p_180639_7_, float p_180639_8_, float p_180639_9_, float p_180639_10_) -@@ -638,25 +648,35 @@ +@@ -638,25 +645,35 @@ p_180657_2_.func_71029_a(StatList.func_188055_a(this)); p_180657_2_.func_71020_j(0.025F); @@ -188,20 +182,15 @@ } protected ItemStack func_180643_i(IBlockState p_180643_1_) -@@ -747,9 +767,11 @@ +@@ -747,6 +764,7 @@ p_176216_2_.field_70181_x = 0.0D; } + @Deprecated // Forge: Use more sensitive version below: getPickBlock public ItemStack func_185473_a(World p_185473_1_, BlockPos p_185473_2_, IBlockState p_185473_3_) { -- return new ItemStack(Item.func_150898_a(this), 1, this.func_180651_a(p_185473_3_)); -+ Item item = Item.func_150898_a(this); -+ return item == null ? null : new ItemStack(item, 1, this.func_180651_a(p_185473_3_)); - } - - @SideOnly(Side.CLIENT) -@@ -844,6 +866,1191 @@ + return new ItemStack(Item.func_150898_a(this), 1, this.func_180651_a(p_185473_3_)); +@@ -844,6 +862,1120 @@ return "Block{" + field_149771_c.func_177774_c(this) + "}"; } @@ -1286,24 +1275,12 @@ + + /** + * Queries if this block should render in a given layer. -+ * ISmartBlockModel can use {@link MinecraftForgeClient#getRenderLayer()} to alter their model based on layer. -+ * -+ * @deprecated New method with state sensitivity: {@link #canRenderInLayer(IBlockState, BlockRenderLayer)} ++ * ISmartBlockModel can use MinecraftForgeClient.getRenderLayer to alter their model based on layer + */ -+ @Deprecated + public boolean canRenderInLayer(BlockRenderLayer layer) + { + return func_180664_k() == layer; + } -+ -+ /** -+ * Queries if this block should render in a given layer. -+ * ISmartBlockModel can use {@link MinecraftForgeClient#getRenderLayer()} to alter their model based on layer. -+ */ -+ public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) -+ { -+ return canRenderInLayer(layer); -+ } + + // For Internal use only to capture droped items inside getDrops + protected static ThreadLocal captureDrops = new ThreadLocal() @@ -1329,65 +1306,6 @@ + } + } + -+ private ResourceLocation registryName = null; -+ /** -+ * Sets a unique name for this Block. This should be used for uniquely identify the instance of the Block. -+ * This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does. -+ * Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items. -+ * -+ * The supplied name will be prefixed with the currently active mod's modId. -+ * If the supplied name already has a prefix that is different, it will be used and a warning will be logged. -+ * -+ * If a name already exists, or this Block is already registered in a registry, then an IllegalStateException is thrown. -+ * -+ * Returns 'this' to allow for chaining. -+ * -+ * @param name Unique registry name -+ * @return This instance -+ */ -+ public final Block setRegistryName(String name) -+ { -+ if (getRegistryName() != null) -+ throw new IllegalStateException("Attempted to set registry name on block with exisiting registry name! New: " + name + " Old: " + getRegistryName()); -+ int index = name.lastIndexOf(':'); -+ String oldPrefix = index == -1 ? "" : name.substring(0, index); -+ name = index == -1 ? name : name.substring(index + 1); -+ net.minecraftforge.fml.common.ModContainer mc = net.minecraftforge.fml.common.Loader.instance().activeModContainer(); -+ String prefix = mc == null ? "minecraft" : mc.getModId(); -+ if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0) -+ { -+ net.minecraftforge.fml.common.FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", oldPrefix, name); -+ prefix = oldPrefix; -+ } -+ this.registryName = new ResourceLocation(prefix, name); -+ return this; -+ } -+ public final Block setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); } -+ public final Block setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); } -+ -+ /** -+ * A unique identifier for this block, if this block is registered in the game registry it will return that name. -+ * Otherwise it will return the name set in setRegistryName(). -+ * If neither are valid null is returned. -+ * -+ * @return Unique identifier or null. -+ */ -+ public final String getRegistryName() -+ { -+ if (delegate.getResourceName() != null) return delegate.getResourceName().toString(); -+ return registryName != null ? registryName.toString() : null; -+ } -+ -+ /** -+ * Add information to the blocks tooltip, called from the default implementation of {@link ItemBlock#addInformation(ItemStack, EntityPlayer, List, boolean)} -+ * @param stack The stack the tooltip is being retrieved for -+ * @param player The player retrieving the tooltip -+ * @param tooltip The lines to be displayed on the tooltip -+ * @param advanced If the client has advanced debug tooltips enabled -+ */ -+ public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) -+ { -+ } + /* ========================================= FORGE END ======================================*/ + public static void func_149671_p() diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderVillager.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderVillager.java.patch index 75cae2f1b..81ae5201a 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderVillager.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderVillager.java.patch @@ -5,7 +5,7 @@ return field_110906_m; default: - return field_110903_f; -+ return net.minecraftforge.fml.common.registry.VillagerRegistry.getVillagerSkin(p_110775_1_.func_70946_n(), field_110903_f); ++ return p_110775_1_.getProfessionForge().getSkin(); } } diff --git a/patches/minecraft/net/minecraft/entity/passive/EntityVillager.java.patch b/patches/minecraft/net/minecraft/entity/passive/EntityVillager.java.patch index d661dc5b2..9cd5cb3c5 100644 --- a/patches/minecraft/net/minecraft/entity/passive/EntityVillager.java.patch +++ b/patches/minecraft/net/minecraft/entity/passive/EntityVillager.java.patch @@ -1,6 +1,14 @@ --- ../src-base/minecraft/net/minecraft/entity/passive/EntityVillager.java +++ ../src-work/minecraft/net/minecraft/entity/passive/EntityVillager.java -@@ -90,6 +90,7 @@ +@@ -74,6 +74,7 @@ + public class EntityVillager extends EntityAgeable implements IMerchant, INpc + { + private static final DataParameter field_184752_bw = EntityDataManager.func_187226_a(EntityVillager.class, DataSerializers.field_187192_b); ++ private static final DataParameter PROFESSION_STR = EntityDataManager.func_187226_a(EntityVillager.class, DataSerializers.field_187194_d); + private int field_70955_e; + private boolean field_70952_f; + private boolean field_70953_g; +@@ -90,6 +91,7 @@ private boolean field_82190_bM; private boolean field_175564_by; private InventoryBasic field_175560_bz; @@ -8,7 +16,7 @@ private static final EntityVillager.ITradeList[][][][] field_175561_bA = new EntityVillager.ITradeList[][][][] {{{{new EntityVillager.EmeraldForItems(Items.field_151015_O, new EntityVillager.PriceInfo(18, 22)), new EntityVillager.EmeraldForItems(Items.field_151174_bG, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.EmeraldForItems(Items.field_151172_bF, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.ListItemForEmeralds(Items.field_151025_P, new EntityVillager.PriceInfo(-4, -2))}, {new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150423_aK), new EntityVillager.PriceInfo(8, 13)), new EntityVillager.ListItemForEmeralds(Items.field_151158_bO, new EntityVillager.PriceInfo(-3, -2))}, {new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150440_ba), new EntityVillager.PriceInfo(7, 12)), new EntityVillager.ListItemForEmeralds(Items.field_151034_e, new EntityVillager.PriceInfo(-5, -7))}, {new EntityVillager.ListItemForEmeralds(Items.field_151106_aX, new EntityVillager.PriceInfo(-6, -10)), new EntityVillager.ListItemForEmeralds(Items.field_151105_aU, new EntityVillager.PriceInfo(1, 1))}}, {{new EntityVillager.EmeraldForItems(Items.field_151007_F, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ItemAndEmeraldToItem(Items.field_151115_aP, new EntityVillager.PriceInfo(6, 6), Items.field_179566_aV, new EntityVillager.PriceInfo(6, 6))}, {new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151112_aM, new EntityVillager.PriceInfo(7, 8))}}, {{new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150325_L), new EntityVillager.PriceInfo(16, 22)), new EntityVillager.ListItemForEmeralds(Items.field_151097_aZ, new EntityVillager.PriceInfo(3, 4))}, {new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L)), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 1), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 2), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 3), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 4), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 5), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 6), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 7), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 8), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 9), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 10), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 11), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 12), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 13), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 14), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 15), new EntityVillager.PriceInfo(1, 2))}}, {{new EntityVillager.EmeraldForItems(Items.field_151007_F, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.ListItemForEmeralds(Items.field_151032_g, new EntityVillager.PriceInfo(-12, -8))}, {new EntityVillager.ListItemForEmeralds(Items.field_151031_f, new EntityVillager.PriceInfo(2, 3)), new EntityVillager.ItemAndEmeraldToItem(Item.func_150898_a(Blocks.field_150351_n), new EntityVillager.PriceInfo(10, 10), Items.field_151145_ak, new EntityVillager.PriceInfo(6, 10))}}}, {{{new EntityVillager.EmeraldForItems(Items.field_151121_aF, new EntityVillager.PriceInfo(24, 36)), new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.EmeraldForItems(Items.field_151122_aG, new EntityVillager.PriceInfo(8, 10)), new EntityVillager.ListItemForEmeralds(Items.field_151111_aL, new EntityVillager.PriceInfo(10, 12)), new EntityVillager.ListItemForEmeralds(Item.func_150898_a(Blocks.field_150342_X), new EntityVillager.PriceInfo(3, 4))}, {new EntityVillager.EmeraldForItems(Items.field_151164_bB, new EntityVillager.PriceInfo(2, 2)), new EntityVillager.ListItemForEmeralds(Items.field_151113_aN, new EntityVillager.PriceInfo(10, 12)), new EntityVillager.ListItemForEmeralds(Item.func_150898_a(Blocks.field_150359_w), new EntityVillager.PriceInfo(-5, -3))}, {new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.ListItemForEmeralds(Items.field_151057_cb, new EntityVillager.PriceInfo(20, 22))}}}, {{{new EntityVillager.EmeraldForItems(Items.field_151078_bh, new EntityVillager.PriceInfo(36, 40)), new EntityVillager.EmeraldForItems(Items.field_151043_k, new EntityVillager.PriceInfo(8, 10))}, {new EntityVillager.ListItemForEmeralds(Items.field_151137_ax, new EntityVillager.PriceInfo(-4, -1)), new EntityVillager.ListItemForEmeralds(new ItemStack(Items.field_151100_aR, 1, EnumDyeColor.BLUE.func_176767_b()), new EntityVillager.PriceInfo(-2, -1))}, {new EntityVillager.ListItemForEmeralds(Items.field_151079_bi, new EntityVillager.PriceInfo(4, 7)), new EntityVillager.ListItemForEmeralds(Item.func_150898_a(Blocks.field_150426_aN), new EntityVillager.PriceInfo(-3, -1))}, {new EntityVillager.ListItemForEmeralds(Items.field_151062_by, new EntityVillager.PriceInfo(3, 11))}}}, {{{new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.field_151028_Y, new EntityVillager.PriceInfo(4, 6))}, {new EntityVillager.EmeraldForItems(Items.field_151042_j, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListItemForEmeralds(Items.field_151030_Z, new EntityVillager.PriceInfo(10, 14))}, {new EntityVillager.EmeraldForItems(Items.field_151045_i, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151163_ad, new EntityVillager.PriceInfo(16, 19))}, {new EntityVillager.ListItemForEmeralds(Items.field_151029_X, new EntityVillager.PriceInfo(5, 7)), new EntityVillager.ListItemForEmeralds(Items.field_151022_W, new EntityVillager.PriceInfo(9, 11)), new EntityVillager.ListItemForEmeralds(Items.field_151020_U, new EntityVillager.PriceInfo(5, 7)), new EntityVillager.ListItemForEmeralds(Items.field_151023_V, new EntityVillager.PriceInfo(11, 15))}}, {{new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.field_151036_c, new EntityVillager.PriceInfo(6, 8))}, {new EntityVillager.EmeraldForItems(Items.field_151042_j, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151040_l, new EntityVillager.PriceInfo(9, 10))}, {new EntityVillager.EmeraldForItems(Items.field_151045_i, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151048_u, new EntityVillager.PriceInfo(12, 15)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151056_x, new EntityVillager.PriceInfo(9, 12))}}, {{new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151037_a, new EntityVillager.PriceInfo(5, 7))}, {new EntityVillager.EmeraldForItems(Items.field_151042_j, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151035_b, new EntityVillager.PriceInfo(9, 11))}, {new EntityVillager.EmeraldForItems(Items.field_151045_i, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151046_w, new EntityVillager.PriceInfo(12, 15))}}}, {{{new EntityVillager.EmeraldForItems(Items.field_151147_al, new EntityVillager.PriceInfo(14, 18)), new EntityVillager.EmeraldForItems(Items.field_151076_bf, new EntityVillager.PriceInfo(14, 18))}, {new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.field_151157_am, new EntityVillager.PriceInfo(-7, -5)), new EntityVillager.ListItemForEmeralds(Items.field_151077_bg, new EntityVillager.PriceInfo(-8, -6))}}, {{new EntityVillager.EmeraldForItems(Items.field_151116_aA, new EntityVillager.PriceInfo(9, 12)), new EntityVillager.ListItemForEmeralds(Items.field_151026_S, new EntityVillager.PriceInfo(2, 4))}, {new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151027_R, new EntityVillager.PriceInfo(7, 12))}, {new EntityVillager.ListItemForEmeralds(Items.field_151141_av, new EntityVillager.PriceInfo(8, 10))}}}}; public EntityVillager(World p_i1747_1_) -@@ -221,7 +222,7 @@ +@@ -221,7 +223,7 @@ { boolean flag = p_184645_3_ != null && p_184645_3_.func_77973_b() == Items.field_151063_bx; @@ -17,23 +25,106 @@ { if (!this.field_70170_p.field_72995_K && (this.field_70963_i == null || !this.field_70963_i.isEmpty())) { -@@ -533,6 +534,7 @@ +@@ -242,12 +244,14 @@ + { + super.func_70088_a(); + this.field_70180_af.func_187214_a(field_184752_bw, Integer.valueOf(0)); ++ this.field_70180_af.func_187214_a(PROFESSION_STR, "minecraft:farmer"); + } + + public void func_70014_b(NBTTagCompound p_70014_1_) + { + super.func_70014_b(p_70014_1_); + p_70014_1_.func_74768_a("Profession", this.func_70946_n()); ++ p_70014_1_.func_74778_a("ProfessionName", this.getProfessionForge().getRegistryName().toString()); + p_70014_1_.func_74768_a("Riches", this.field_70956_bz); + p_70014_1_.func_74768_a("Career", this.field_175563_bv); + p_70014_1_.func_74768_a("CareerLevel", this.field_175562_bw); +@@ -277,6 +281,14 @@ + { + super.func_70037_a(p_70037_1_); + this.func_70938_b(p_70037_1_.func_74762_e("Profession")); ++ if (p_70037_1_.func_74764_b("ProfessionName")) ++ { ++ net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p = ++ net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation(p_70037_1_.func_74779_i("ProfessionName"))); ++ if (p == null) ++ p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation("minecraft:farmer")); ++ this.setProfession(p); ++ } + this.field_70956_bz = p_70037_1_.func_74762_e("Riches"); + this.field_175563_bv = p_70037_1_.func_74762_e("Career"); + this.field_175562_bw = p_70037_1_.func_74762_e("CareerLevel"); +@@ -334,6 +346,26 @@ + return Math.max(((Integer)this.field_70180_af.func_187225_a(field_184752_bw)).intValue() % 5, 0); + } + ++ private net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof; ++ public void setProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof) ++ { ++ this.field_70180_af.func_187227_b(PROFESSION_STR, prof.getRegistryName().toString()); ++ this.prof = prof; ++ } ++ ++ public net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession getProfessionForge() ++ { ++ if (this.prof == null) ++ { ++ String p = this.field_70180_af.func_187225_a(PROFESSION_STR); ++ net.minecraft.util.ResourceLocation res = new net.minecraft.util.ResourceLocation(p == null ? "minecraft:farmer" : p); ++ this.prof = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(res); ++ if (this.prof == null) ++ return net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation("minecraft:farmer")); ++ } ++ return this.prof; ++ } ++ + public boolean func_70941_o() + { + return this.field_70952_f; +@@ -533,15 +565,13 @@ private void func_175554_cu() { -+ //TODO: Hook into VillagerRegistry - EntityVillager.ITradeList[][][] aentityvillager$itradelist = field_175561_bA[this.func_70946_n()]; - +- EntityVillager.ITradeList[][][] aentityvillager$itradelist = field_175561_bA[this.func_70946_n()]; +- if (this.field_175563_bv != 0 && this.field_175562_bw != 0) -@@ -647,6 +649,7 @@ + { + ++this.field_175562_bw; + } + else + { +- this.field_175563_bv = this.field_70146_Z.nextInt(aentityvillager$itradelist.length) + 1; ++ this.field_175563_bv = this.getProfessionForge().getRandomCareer(this.field_70146_Z) + 1; + this.field_175562_bw = 1; + } + +@@ -552,7 +582,7 @@ + + int i = this.field_175563_bv - 1; + int j = this.field_175562_bw - 1; +- EntityVillager.ITradeList[][] aentityvillager$itradelist1 = aentityvillager$itradelist[i]; ++ EntityVillager.ITradeList[][] aentityvillager$itradelist1 = this.getProfessionForge().getCareer(i).getTrades(); + + if (j >= 0 && j < aentityvillager$itradelist1.length) + { +@@ -647,9 +677,14 @@ } } ++ if (s1 == null) ++ s1 = this.getProfessionForge().getCareer(this.field_175563_bv).getName(); ++ else ++ s1 = "entity.Villager." + s1; + //TODO: Hook into VillagerRegistry to get name if (s1 != null) { - TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("entity.Villager." + s1, new Object[0]); -@@ -708,7 +711,7 @@ +- TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("entity.Villager." + s1, new Object[0]); ++ TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(s1, new Object[0]); + textcomponenttranslation.func_150256_b().func_150209_a(this.func_174823_aP()); + textcomponenttranslation.func_150256_b().func_179989_a(this.func_110124_au().toString()); + +@@ -708,7 +743,7 @@ public IEntityLivingData func_180482_a(DifficultyInstance p_180482_1_, IEntityLivingData p_180482_2_) { p_180482_2_ = super.func_180482_a(p_180482_1_, p_180482_2_); diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch index 0674d4782..27cfd57be 100644 --- a/patches/minecraft/net/minecraft/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/item/Item.java.patch @@ -1,8 +1,11 @@ --- ../src-base/minecraft/net/minecraft/item/Item.java +++ ../src-work/minecraft/net/minecraft/item/Item.java -@@ -58,8 +58,8 @@ +@@ -56,10 +56,10 @@ + import net.minecraftforge.fml.relauncher.Side; + import net.minecraftforge.fml.relauncher.SideOnly; - public class Item +-public class Item ++public class Item extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl { - public static final RegistryNamespaced field_150901_e = new RegistryNamespaced(); - private static final Map field_179220_a = Maps.newHashMap(); @@ -11,17 +14,7 @@ private static final IItemPropertyGetter field_185046_b = new IItemPropertyGetter() { @SideOnly(Side.CLIENT) -@@ -104,6 +104,9 @@ - private Item field_77700_c; - private String field_77774_bZ; - -+ public final net.minecraftforge.fml.common.registry.RegistryDelegate delegate = -+ ((net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry)field_150901_e).getDelegate(this, Item.class); -+ - public static int func_150891_b(Item p_150891_0_) - { - return p_150891_0_ == null ? 0 : field_150901_e.func_148757_b(p_150891_0_); -@@ -192,6 +195,7 @@ +@@ -192,6 +192,7 @@ return p_77654_1_; } @@ -29,7 +22,7 @@ public int func_77639_j() { return this.field_77777_bU; -@@ -312,6 +316,7 @@ +@@ -312,6 +313,7 @@ return this.field_77700_c; } @@ -37,7 +30,7 @@ public boolean func_77634_r() { return this.field_77700_c != null; -@@ -367,7 +372,7 @@ +@@ -367,7 +369,7 @@ public boolean func_77616_k(ItemStack p_77616_1_) { @@ -46,7 +39,7 @@ } protected RayTraceResult func_77621_a(World p_77621_1_, EntityPlayer p_77621_2_, boolean p_77621_3_) -@@ -385,6 +390,10 @@ +@@ -385,6 +387,10 @@ float f6 = f3 * f4; float f7 = f2 * f4; double d3 = 5.0D; @@ -57,7 +50,7 @@ Vec3d vec3d1 = vec3d.func_72441_c((double)f6 * d3, (double)f5 * d3, (double)f7 * d3); return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false); } -@@ -422,11 +431,606 @@ +@@ -422,11 +428,557 @@ return false; } @@ -575,55 +568,6 @@ + return !oldStack.equals(newStack); //!ItemStack.areItemStacksEqual(oldStack, newStack); + } + -+ private ResourceLocation registryName = null; -+ /** -+ * Sets a unique name for this Item. This should be used for uniquely identify the instance of the Item. -+ * This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does. -+ * Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items. -+ * -+ * The supplied name will be prefixed with the currently active mod's modId. -+ * If the supplied name already has a prefix that is different, it will be used and a warning will be logged. -+ * -+ * If a name already exists, or this Item is already registered in a registry, then an IllegalStateException is thrown. -+ * -+ * Returns 'this' to allow for chaining. -+ * -+ * @param name Unique registry name -+ * @return This instance -+ */ -+ public final Item setRegistryName(String name) -+ { -+ if (getRegistryName() != null) -+ throw new IllegalStateException("Attempted to set registry name on block with exisiting registry name! New: " + name + " Old: " + getRegistryName()); -+ int index = name.lastIndexOf(':'); -+ String oldPrefix = index == -1 ? "" : name.substring(0, index); -+ name = index == -1 ? name : name.substring(index + 1); -+ net.minecraftforge.fml.common.ModContainer mc = net.minecraftforge.fml.common.Loader.instance().activeModContainer(); -+ String prefix = mc == null ? "minecraft" : mc.getModId(); -+ if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0) -+ { -+ net.minecraftforge.fml.common.FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", oldPrefix, name); -+ prefix = oldPrefix; -+ } -+ this.registryName = new ResourceLocation(prefix, name); -+ return this; -+ } -+ public final Item setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); } -+ public final Item setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); } -+ -+ /** -+ * A unique identifier for this block, if this block is registered in the game registry it will return that name. -+ * Otherwise it will return the name set in setRegistryName(). -+ * If neither are valid null is returned. -+ * -+ * @return Unique identifier or null. -+ */ -+ public final String getRegistryName() -+ { -+ if (delegate.getResourceName() != null) return delegate.getResourceName().toString(); -+ return registryName != null ? registryName.toString() : null; -+ } -+ + /** + * Called from ItemStack.setItem, will hold extra data for the life of this ItemStack. + * Can be retrieved from stack.getCapabilities() @@ -664,7 +608,7 @@ public static void func_150900_l() { func_179214_a(Blocks.field_150348_b, (new ItemMultiTexture(Blocks.field_150348_b, Blocks.field_150348_b, new Function() -@@ -935,6 +1539,10 @@ +@@ -935,6 +1487,10 @@ private final float field_78011_i; private final int field_78008_j; @@ -675,7 +619,7 @@ private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_) { this.field_78001_f = p_i1874_3_; -@@ -969,9 +1577,36 @@ +@@ -969,9 +1525,36 @@ return this.field_78008_j; } diff --git a/patches/minecraft/net/minecraft/potion/Potion.java.patch b/patches/minecraft/net/minecraft/potion/Potion.java.patch index d8ed60afc..9385f031c 100644 --- a/patches/minecraft/net/minecraft/potion/Potion.java.patch +++ b/patches/minecraft/net/minecraft/potion/Potion.java.patch @@ -1,8 +1,11 @@ --- ../src-base/minecraft/net/minecraft/potion/Potion.java +++ ../src-work/minecraft/net/minecraft/potion/Potion.java -@@ -23,7 +23,7 @@ +@@ -21,9 +21,9 @@ + import net.minecraftforge.fml.relauncher.Side; + import net.minecraftforge.fml.relauncher.SideOnly; - public class Potion +-public class Potion ++public class Potion extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl { - public static final RegistryNamespaced field_188414_b = new RegistryNamespaced(); + public static final RegistryNamespaced field_188414_b = net.minecraftforge.fml.common.registry.GameData.getPotionRegistry(); diff --git a/patches/minecraft/net/minecraft/world/biome/BiomeGenBase.java.patch b/patches/minecraft/net/minecraft/world/biome/BiomeGenBase.java.patch index a7c0f1850..22c125373 100644 --- a/patches/minecraft/net/minecraft/world/biome/BiomeGenBase.java.patch +++ b/patches/minecraft/net/minecraft/world/biome/BiomeGenBase.java.patch @@ -1,5 +1,14 @@ --- ../src-base/minecraft/net/minecraft/world/biome/BiomeGenBase.java +++ ../src-work/minecraft/net/minecraft/world/biome/BiomeGenBase.java +@@ -51,7 +51,7 @@ + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; + +-public abstract class BiomeGenBase ++public abstract class BiomeGenBase extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl + { + private static final Logger field_150586_aC = LogManager.getLogger(); + protected static final IBlockState field_185365_a = Blocks.field_150348_b.func_176223_P(); @@ -70,7 +70,7 @@ protected static final WorldGenTrees field_76757_N = new WorldGenTrees(false); protected static final WorldGenBigTree field_76758_O = new WorldGenBigTree(false); diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 3c4ac2a47..aea9998c9 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -192,7 +192,7 @@ public final class ModelLoader extends ModelBakery { public int compare(Block b1, Block b2) { - return b1.getRegistryName().compareTo(b2.getRegistryName()); + return b1.getRegistryName().toString().compareTo(b2.getRegistryName().toString()); } }); ProgressBar blockBar = ProgressManager.push("ModelLoader: blocks", blocks.size()); @@ -201,7 +201,7 @@ public final class ModelLoader extends ModelBakery for(Block block : blocks) { - blockBar.step(block.getRegistryName()); + blockBar.step(block.getRegistryName().toString()); for(ResourceLocation location : mapper.getBlockstateLocations(block)) { loadBlock(mapper, block, location); @@ -276,14 +276,14 @@ public final class ModelLoader extends ModelBakery { public int compare(Item i1, Item i2) { - return i1.getRegistryName().compareTo(i2.getRegistryName()); + return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString()); } }); ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size()); for(Item item : items) { - itemBar.step(item.getRegistryName()); + itemBar.step(item.getRegistryName().toString()); for(String s : getVariantNames(item)) { ResourceLocation file = getItemLocation(s); @@ -916,7 +916,7 @@ public final class ModelLoader extends ModelBakery for(String s : getVariantNames(item)) { ModelResourceLocation memory = getInventoryVariant(s); - reverseItemMap.put(memory, item.getRegistryName()); + reverseItemMap.put(memory, item.getRegistryName().toString()); } } } diff --git a/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java b/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java index d1a2618c2..dd6bbe2e0 100644 --- a/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java +++ b/src/main/java/net/minecraftforge/common/util/BlockSnapshot.java @@ -38,7 +38,7 @@ public class BlockSnapshot implements Serializable this.dimId = world.provider.getDimension(); this.pos = pos; this.setReplacedBlock(state); - this.registryName = new ResourceLocation(state.getBlock().getRegistryName()); + this.registryName = state.getBlock().getRegistryName(); this.meta = state.getBlock().getMetaFromState(state); this.setFlag(3); TileEntity te = world.getTileEntity(pos); @@ -60,7 +60,7 @@ public class BlockSnapshot implements Serializable this.dimId = world.provider.getDimension(); this.pos = pos.toImmutable(); this.setReplacedBlock(state); - this.registryName = new ResourceLocation(state.getBlock().getRegistryName()); + this.registryName = state.getBlock().getRegistryName(); this.meta = state.getBlock().getMetaFromState(state); this.setFlag(3); this.nbt = nbt; diff --git a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java index b2a752f06..ec3e6be78 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java +++ b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java @@ -433,13 +433,7 @@ public abstract class FluidRegistry } @Override - public String name() - { - return name; - } - - @Override - public ResourceLocation getResourceName() { + public ResourceLocation name() { return new ResourceLocation(name); } diff --git a/src/main/java/net/minecraftforge/fml/common/FMLContainer.java b/src/main/java/net/minecraftforge/fml/common/FMLContainer.java index 3af70ae25..d92e7fc26 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLContainer.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLContainer.java @@ -48,7 +48,7 @@ import com.google.common.eventbus.Subscribe; * @author cpw * */ -public class FMLContainer extends DummyModContainer implements WorldAccessContainer +public final class FMLContainer extends DummyModContainer implements WorldAccessContainer { public FMLContainer() { diff --git a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java index ad9e2fd9c..2f83b230f 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java @@ -8,31 +8,31 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; +import com.google.common.base.Joiner; +import com.google.common.base.Throwables; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import org.apache.commons.lang3.Validate; +import org.apache.logging.log4j.Level; + import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.functions.GenericIterableFactory; import net.minecraftforge.fml.common.registry.RegistryDelegate.Delegate; -import org.apache.commons.lang3.Validate; -import org.apache.logging.log4j.Level; - -import com.google.common.base.Joiner; -import com.google.common.base.Throwables; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Iterators; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaultedByKey +public class FMLControlledNamespacedRegistry> extends RegistryNamespacedDefaultedByKey implements IForgeRegistry { public static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("fml.debugRegistryEntries", "false")); private final Class superType; private final boolean isDelegated; - private final Field delegateAccessor; private ResourceLocation optionalDefaultKey; private I optionalDefaultObject; private int maxId; @@ -59,43 +59,30 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul private final BitSet availabilityMap; + private final Map slaves = Maps.newHashMap(); + private final AddCallback addCallback; - public interface AddCallback - { - public void onAdd(T obj, int id); - } + private final ClearCallback clearCallback; - FMLControlledNamespacedRegistry(ResourceLocation defaultKey, int maxIdValue, int minIdValue, Class type, boolean isDelegated) - { - this(defaultKey, maxIdValue, minIdValue, type, isDelegated, null); - } + private final CreateCallback createCallback; - FMLControlledNamespacedRegistry(ResourceLocation defaultKey, int maxIdValue, int minIdValue, Class type, boolean isDelegated, AddCallback callback) + FMLControlledNamespacedRegistry(ResourceLocation defaultKey, int minIdValue, int maxIdValue, Class type, AddCallback addCallback, ClearCallback clearCallback, CreateCallback createCallback) { super(defaultKey); this.superType = type; this.optionalDefaultKey = defaultKey; - this.maxId = maxIdValue; this.minId = minIdValue; + this.maxId = maxIdValue; this.availabilityMap = new BitSet(maxIdValue + 1); - this.isDelegated = isDelegated; - if (this.isDelegated) + this.isDelegated = IForgeRegistryEntry.Impl.class.isAssignableFrom(type); + this.addCallback = addCallback; + this.clearCallback = clearCallback; + this.createCallback = createCallback; + if (createCallback != null) { - try - { - this.delegateAccessor = type.getField("delegate"); - } catch (NoSuchFieldException e) - { - FMLLog.log(Level.ERROR, e, "Delegate class identified with missing delegate field"); - throw Throwables.propagate(e); - } + createCallback.onCreate(slaves); } - else - { - this.delegateAccessor = null; - } - this.addCallback = callback; } void validateContent(ResourceLocation registryName) @@ -462,7 +449,7 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul addObjectRaw(idToUse, name, thing); if (isDelegated) { - getExistingDelegate(thing).setResourceName(name); + getExistingDelegate(thing).setName(name); } if (this.dummiedLocations.remove(name) && DEBUG) @@ -561,7 +548,7 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul availabilityMap.set(id); if (addCallback != null) { - addCallback.onAdd(thing, id); + addCallback.onAdd(thing, id, slaves); } } @@ -576,15 +563,15 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul } @SuppressWarnings("unchecked") - public Delegate getExistingDelegate(I thing) + private Delegate getExistingDelegate(I thing) { - try + if (isDelegated) { - return (Delegate)delegateAccessor.get(thing); - } catch (IllegalAccessException e) + return (Delegate)((IForgeRegistryEntry.Impl)thing).delegate; + } + else { - FMLLog.log(Level.ERROR, e, "Illegal attempt to access delegate"); - throw Throwables.propagate(e); + return null; } } @@ -655,7 +642,7 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul FMLControlledNamespacedRegistry makeShallowCopy() { - return new FMLControlledNamespacedRegistry(optionalDefaultKey, maxId, minId, superType, isDelegated); + return new FMLControlledNamespacedRegistry(optionalDefaultKey, minId, maxId, superType, addCallback, clearCallback, createCallback); } void resetSubstitutionDelegates() @@ -672,7 +659,7 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul } @SuppressWarnings("unchecked") - public FMLControlledNamespacedRegistry asType(Class type) + public > FMLControlledNamespacedRegistry asType(Class type) { return (FMLControlledNamespacedRegistry)this; } @@ -758,18 +745,118 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul for (I i : this.underlyingIntegerMap) { - addCallback.onAdd(i, this.underlyingIntegerMap.add(i)); + addCallback.onAdd(i, this.underlyingIntegerMap.add(i), slaves); } } @Override public ResourceLocation getNameForObject(I p_177774_1_) { - ResourceLocation rl = super.getNameForObject(p_177774_1_); + ResourceLocation rl = super.getNameForObjectBypass(p_177774_1_); if (rl == null) { rl = activeSubstitutions.inverse().get(p_177774_1_); } return rl; } + + @Override + public Class getRegistrySuperType() + { + return superType; + } + + + // IForgeRegistry: Modders should only interfaces with these methods + + @Override + public void register(I value) + { + ResourceLocation key = value.getRegistryName(); + if (key == null) + { + FMLLog.severe("Attempted to register a entry with a null name: %s", value); + throw new NullPointerException(String.format("Attempted to register a entry with a null name: %s", value)); + } + add(-1, key, value); + } + + @Override + public boolean containsValue(I value) + { + return getKey(value) != null; + } + + @Override + public I getValue(ResourceLocation key) + { + return getObject(key); + } + + @Override + public ResourceLocation getKey(I value) + { + return getNameForObject(value); + } + + @Override + public List getValues() + { + return Lists.newArrayList(this.iterator()); + } + + @Override + public Set> getEntries() + { + return Sets.newHashSet(new Iterator>() + { + Iterator itr = FMLControlledNamespacedRegistry.this.iterator(); + + @Override + public boolean hasNext() + { + return itr.hasNext(); + } + + @Override + public Entry next() + { + final I value = itr.next(); + final ResourceLocation key = FMLControlledNamespacedRegistry.this.getKey(value); + return new Entry() + { + @Override + public ResourceLocation getKey() + { + return key; + } + + @Override + public I getValue() + { + return value; + } + + @Override + public I setValue(I value) + { + throw new UnsupportedOperationException("Setting the value in an iterator is not allowed"); + } + }; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("This is a READ ONLY view of this registry."); + } + }); + } + + @SuppressWarnings("unchecked") + @Override + public T getSlaveMap(ResourceLocation slaveMapName, Class type) + { + return (T)slaves.get(slaveMapName); + } } 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 b1e50740c..3258b9018 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameData.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameData.java @@ -14,6 +14,7 @@ package net.minecraftforge.fml.common.registry; import java.util.Map; +import com.google.common.collect.HashBiMap; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; @@ -27,7 +28,6 @@ import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; public class GameData { @@ -35,12 +35,22 @@ public class GameData static final int MAX_BLOCK_ID = 4095; static final int MIN_ITEM_ID = 4096; static final int MAX_ITEM_ID = 31999; - public static final int MIN_POTION_ID = 0; // 0-~31 are vanilla, forge start at 32 - public static final int MAX_POTION_ID = 255; // S1DPacketEntityEffect sends bytes, we can only use 255 - public static final int MIN_BIOME_ID = 0; // 0-~31 are vanilla, forge start at 32 - public static final int MAX_BIOME_ID = 255; // S1DPacketEntityEffect sends bytes, we can only use 255 + 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 ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap"); + private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid"); private static final GameData mainData = new GameData(); + + public GameData() + { + iBlockRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BLOCKS, Block.class, new ResourceLocation("minecraft:air"), MIN_BLOCK_ID, MAX_BLOCK_ID, true, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE); + 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); + } // public api /** @@ -96,10 +106,10 @@ public class GameData } // internal registry objects - private final FMLControlledNamespacedRegistry iBlockRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BLOCKS, Block.class, new ResourceLocation("minecraft:air"), MAX_BLOCK_ID, MIN_BLOCK_ID, true, BlockStateCapture.INSTANCE); - private final FMLControlledNamespacedRegistry iItemRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ITEMS, Item.class, null, MAX_ITEM_ID, MIN_ITEM_ID, true, ItemBlockCapture.INSTANCE); - private final FMLControlledNamespacedRegistry iPotionRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONS, Potion.class, null, MAX_POTION_ID, MIN_POTION_ID, false, PotionArrayCapture.INSTANCE); - private final FMLControlledNamespacedRegistry iBiomeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BIOMES, BiomeGenBase.class, null, MAX_BIOME_ID, MIN_BIOME_ID, false, BiomeCapture.INSTANCE); + private final FMLControlledNamespacedRegistry iBlockRegistry; + private final FMLControlledNamespacedRegistry iItemRegistry; + private final FMLControlledNamespacedRegistry iPotionRegistry; + private final FMLControlledNamespacedRegistry iBiomeRegistry; int registerItem(Item item, String name) // from GameRegistry { @@ -152,42 +162,45 @@ public class GameData void registerSubstitutionAlias(String name, GameRegistry.Type type, Object toReplace) throws ExistingSubstitutionException { ResourceLocation nameToSubstitute = new ResourceLocation(name); + final BiMap blockItemMap = getBlockItemMap(); if (type == GameRegistry.Type.BLOCK) { iBlockRegistry.addSubstitutionAlias(Loader.instance().activeModContainer().getModId(), nameToSubstitute, (Block)toReplace); Block orig = iBlockRegistry.activateSubstitution(nameToSubstitute); - if (BLOCK_TO_ITEM.containsKey(orig)) + if (blockItemMap.containsKey(orig)) { - Item i = BLOCK_TO_ITEM.get(orig); - BLOCK_TO_ITEM.forcePut((Block)toReplace,i); + Item i = blockItemMap.get(orig); + blockItemMap.forcePut((Block)toReplace,i); } } else if (type == GameRegistry.Type.ITEM) { iItemRegistry.addSubstitutionAlias(Loader.instance().activeModContainer().getModId(), nameToSubstitute, (Item)toReplace); Item orig = iItemRegistry.activateSubstitution(nameToSubstitute); - if (BLOCK_TO_ITEM.containsValue(orig)) + if (blockItemMap.containsValue(orig)) { - Block b = BLOCK_TO_ITEM.inverse().get(orig); - BLOCK_TO_ITEM.forcePut(b, (Item)toReplace); + Block b = blockItemMap.inverse().get(orig); + blockItemMap.forcePut(b, (Item)toReplace); } } } - private static BiMap BLOCK_TO_ITEM = HashBiMap.create(); - - //Internal: DO NOT USE, will change without warning. - public static Map getBlockItemMap() + @SuppressWarnings("unchecked") + public static BiMap getBlockItemMap() { - return BLOCK_TO_ITEM; + return (BiMap)getMain().iItemRegistry.getSlaveMap(BLOCK_TO_ITEM, BiMap.class); + } + static > K register(K object, ResourceLocation location) + { + final IForgeRegistry registry = PersistentRegistryManager.findRegistry(object); + registry.register(object); + return object; } - private static ClearableObjectIntIdentityMap BLOCKSTATE_TO_ID = new ClearableObjectIntIdentityMap(); - - //Internal: DO NOT USE, will change without warning. - public static ClearableObjectIntIdentityMap getBlockStateIDMap() + @SuppressWarnings("unchecked") + public static ObjectIntIdentityMap getBlockStateIDMap() { - return BLOCKSTATE_TO_ID; + return (ObjectIntIdentityMap)getMain().iBlockRegistry.getSlaveMap(BLOCKSTATE_TO_ID, ObjectIntIdentityMap.class); } //Lets us clear the map so we can rebuild it. @@ -200,56 +213,116 @@ public class GameData } } - public RegistryDelegate makeDelegate(T obj, Class rootClass) + public > RegistryDelegate makeDelegate(T obj, Class rootClass) { return PersistentRegistryManager.makeDelegate(obj, rootClass); } - private static class BlockStateCapture implements FMLControlledNamespacedRegistry.AddCallback + private static class BlockCallbacks implements IForgeRegistry.AddCallback,IForgeRegistry.ClearCallback,IForgeRegistry.CreateCallback { - static final BlockStateCapture INSTANCE = new BlockStateCapture(); + static final BlockCallbacks INSTANCE = new BlockCallbacks(); + @SuppressWarnings("unchecked") @Override - public void onAdd(Block block, int blockId) + public void onAdd(Block block, int blockId, Map slaves) { + ClearableObjectIntIdentityMap blockstateMap = (ClearableObjectIntIdentityMap)slaves.get(BLOCKSTATE_TO_ID); for (IBlockState state : block.getBlockState().getValidStates()) { - GameData.BLOCKSTATE_TO_ID.put(state, blockId << 4 | block.getMetaFromState(state)); + blockstateMap.put(state, blockId << 4 | block.getMetaFromState(state)); } } + + @SuppressWarnings("unchecked") + @Override + public void onClear(Map slaveset) + { + ClearableObjectIntIdentityMap blockstateMap = (ClearableObjectIntIdentityMap)slaveset.get(BLOCKSTATE_TO_ID); + blockstateMap.clear(); + } + + @SuppressWarnings("unchecked") + @Override + public void onCreate(Map slaveset) + { + final ClearableObjectIntIdentityMap idMap = new ClearableObjectIntIdentityMap(); + ((Map)slaveset).put(BLOCKSTATE_TO_ID, idMap); + + } } - private static class ItemBlockCapture implements FMLControlledNamespacedRegistry.AddCallback + private static class ItemCallbacks implements IForgeRegistry.AddCallback,IForgeRegistry.ClearCallback,IForgeRegistry.CreateCallback { - static final ItemBlockCapture INSTANCE = new ItemBlockCapture(); + static final ItemCallbacks INSTANCE = new ItemCallbacks(); @Override - public void onAdd(Item item, int blockId) + public void onAdd(Item item, int blockId, Map slaves) { if (item instanceof ItemBlock) { ItemBlock itemBlock = (ItemBlock)item; - BLOCK_TO_ITEM.forcePut(itemBlock.getBlock().delegate.get(), item); + @SuppressWarnings("unchecked") BiMap blockToItem = (BiMap)slaves.get(BLOCK_TO_ITEM); + blockToItem.forcePut(itemBlock.getBlock().delegate.get(), item); } } + + @SuppressWarnings("unchecked") + @Override + public void onClear(Map slaveset) + { + Map map = (Map)slaveset.get(BLOCK_TO_ITEM); + map.clear(); + } + + @SuppressWarnings("unchecked") + @Override + public void onCreate(Map slaveset) + { + final HashBiMap map = HashBiMap.create(); + ((Map)slaveset).put(BLOCK_TO_ITEM, map); + } } - private static class PotionArrayCapture implements FMLControlledNamespacedRegistry.AddCallback + private static class PotionCallbacks implements IForgeRegistry.AddCallback,IForgeRegistry.ClearCallback,IForgeRegistry.CreateCallback { - static final PotionArrayCapture INSTANCE = new PotionArrayCapture(); + static final PotionCallbacks INSTANCE = new PotionCallbacks(); @Override - public void onAdd(Potion potion, int id) { + public void onAdd(Potion potion, int id, Map slaves) { + // no op for the minute? + } + + @Override + public void onClear(Map slaveset) + { + // no op for the minute? + } + + @Override + public void onCreate(Map slaveset) + { // no op for the minute? } } - private static class BiomeCapture implements FMLControlledNamespacedRegistry.AddCallback + private static class BiomeCallbacks implements IForgeRegistry.AddCallback,IForgeRegistry.ClearCallback,IForgeRegistry.CreateCallback { - static final BiomeCapture INSTANCE = new BiomeCapture(); + static final BiomeCallbacks INSTANCE = new BiomeCallbacks(); @Override - public void onAdd(BiomeGenBase potion, int id) { + public void onAdd(BiomeGenBase potion, int id, Map slaves) { + // no op for the minute? + } + + @Override + public void onClear(Map slaveset) + { + // no op for the minute? + } + + @Override + public void onCreate(Map slaveset) + { // no op for the minute? } } -} \ No newline at end of file +} diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java index ee11a01ec..873c897a3 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java @@ -51,7 +51,6 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import org.apache.logging.log4j.Level; -import com.google.common.base.Objects; import com.google.common.base.Strings; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; @@ -128,14 +127,19 @@ public class GameRegistry sortedGeneratorList = ImmutableList.copyOf(list); } + public static > K register(K object, ResourceLocation location) + { + return GameData.register(object, location); + } /** * Register an item with the item registry with a the name specified in Item.getRegistryName() * * @param item The item to register */ + @Deprecated public static void registerItem(Item item) { - registerItem(item, item.getRegistryName()); + registerItem(item, item.getRegistryName().toString()); } /** @@ -144,6 +148,7 @@ public class GameRegistry * @param item The item to register * @param name The mod-unique name of the item */ + @Deprecated public static void registerItem(Item item, String name) { if (Strings.isNullOrEmpty(name)) @@ -153,20 +158,6 @@ public class GameRegistry GameData.getMain().registerItem(item, name); } - /** - * Register the specified Item with a mod specific name : overrides the standard type based name - * - * @param item The item to register - * @param name The mod-unique name to register it as - null will remove a custom name - * @param modId deprecated, unused - */ - @Deprecated // See version without modID remove in 1.9 - public static Item registerItem(Item item, String name, String modId) - { - registerItem(item, name); - return item; - } - /** * Add a forced persistent substitution alias for the block or item to another block or item. This will have * the effect of using the substituted block or item instead of the original, where ever it is @@ -188,9 +179,10 @@ public class GameRegistry * * @param block The block to register */ + @Deprecated public static Block registerBlock(Block block) { - return registerBlock(block, block.getRegistryName()); + return registerBlock(block, block.getRegistryName().toString()); } /** @@ -199,6 +191,7 @@ public class GameRegistry * @param block The block to register * @param name The mod-unique name to register it as, will get prefixed by your modid. */ + @Deprecated public static Block registerBlock(Block block, String name) { return registerBlock(block, ItemBlock.class, name); @@ -210,6 +203,7 @@ public class GameRegistry * @param block The block to register * @param itemclass The item type to register with it : null registers a block without associated item. */ + @Deprecated public static Block registerBlock(Block block, Class itemclass) { return registerBlock(block, itemclass, block.getRegistryName()); @@ -222,6 +216,7 @@ public class GameRegistry * @param itemclass The item type to register with it : null registers a block without associated item. * @param name The mod-unique name to register it as, will get prefixed by your modid. */ + @Deprecated public static Block registerBlock(Block block, Class itemclass, String name) { return registerBlock(block, itemclass, name, new Object[] {}); @@ -235,9 +230,10 @@ public class GameRegistry * @param itemclass The item type to register with it : null registers a block without associated item. * @param itemCtorArgs Arguments to pass (after the required {@code Block} parameter) to the ItemBlock constructor (optional). */ + @Deprecated public static Block registerBlock(Block block, Class itemclass, Object... itemCtorArgs) { - return registerBlock(block, itemclass, block.getRegistryName(), itemCtorArgs); + return registerBlock(block, itemclass, block.getRegistryName().toString(), itemCtorArgs); } /** @@ -248,6 +244,7 @@ public class GameRegistry * @param name The mod-unique name to register it as, will get prefixed by your modid. * @param itemCtorArgs Arguments to pass (after the required {@code Block} parameter) to the ItemBlock constructor (optional). */ + @Deprecated public static Block registerBlock(Block block, Class itemclass, String name, Object... itemCtorArgs) { if (Strings.isNullOrEmpty(name)) @@ -371,6 +368,7 @@ public class GameRegistry * @param name The name of the block itself * @return The block or null if not found */ + @Deprecated public static Block findBlock(String modId, String name) { return GameData.findBlock(modId, name); @@ -383,6 +381,7 @@ public class GameRegistry * @param name The name of the item itself * @return The item or null if not found */ + @Deprecated public static Item findItem(String modId, String name) { return GameData.findItem(modId, name); diff --git a/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistry.java new file mode 100644 index 000000000..17147cb19 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistry.java @@ -0,0 +1,67 @@ +package net.minecraftforge.fml.common.registry; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.util.ResourceLocation; + +/** + * Main interface for the registry system. Use this to query the registry system. + * + * @param The top level type for the registry + */ +@SuppressWarnings("WeakerAccess") +public interface IForgeRegistry> extends Iterable +{ + public Class getRegistrySuperType(); + + void register(V value); + + boolean containsKey(ResourceLocation key); + boolean containsValue(V value); + + V getValue(ResourceLocation key); + ResourceLocation getKey(V value); + + Set getKeys(); + List getValues(); + Set> getEntries(); + + /** + * Retrieve the slave map of type T from the registry. + * Slave maps are maps which are dependent on registry content in some way. + * @param slaveMapName The name of the slavemap + * @param type The type + * @param Type to return + * @return The slavemap if present + */ + T getSlaveMap(ResourceLocation slaveMapName, Class type); + + /** + * Callback fired when objects are added to the registry. This will fire when the registry is rebuilt + * on the client side from a server side synchronization, or when a world is loaded. + */ + interface AddCallback + { + void onAdd(V obj, int id, Map slaveset); + } + + /** + * Callback fired when the registry is cleared. This is done before a registry is reloaded from client + * or server. + */ + interface ClearCallback + { + void onClear(Map slaveset); + } + + /** + * Callback fired when a registry instance is created. Populate slave maps here. + */ + interface CreateCallback + { + void onCreate(Map slaveset); + } +} diff --git a/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistryEntry.java b/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistryEntry.java new file mode 100644 index 000000000..d24843b87 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/registry/IForgeRegistryEntry.java @@ -0,0 +1,83 @@ +package net.minecraftforge.fml.common.registry; + +import com.google.common.reflect.TypeToken; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.FMLContainer; +import net.minecraftforge.fml.common.FMLLog; +import net.minecraftforge.fml.common.InjectedModContainer; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; + +public interface IForgeRegistryEntry +{ + /** + * Sets a unique name for this Item. This should be used for uniquely identify the instance of the Item. + * This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does. + * Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items. + * + * The supplied name will be prefixed with the currently active mod's modId. + * If the supplied name already has a prefix that is different, it will be used and a warning will be logged. + * + * If a name already exists, or this Item is already registered in a registry, then an IllegalStateException is thrown. + * + * Returns 'this' to allow for chaining. + * + * @param name Unique registry name + * @return This instance + */ + V setRegistryName(ResourceLocation name); + + /** + * A unique identifier for this entry, if this entry is registered already it will return it's official registry name. + * Otherwise it will return the name set in setRegistryName(). + * If neither are valid null is returned. + * + * @return Unique identifier or null. + */ + ResourceLocation getRegistryName(); + + Class getRegistryType(); + + // Default implementation, modders who make extra items SHOULD extend this instead of Object. + // We have to do this until we get default implementations in Java 8. + @SuppressWarnings({ "serial", "unchecked" }) + public static class Impl> implements IForgeRegistryEntry + { + private TypeToken token = new TypeToken(getClass()){}; + public final RegistryDelegate delegate = PersistentRegistryManager.makeDelegate((T)this, (Class)token.getRawType()); + private ResourceLocation registryName = null; + + public final T setRegistryName(String name) + { + if (getRegistryName() != null) + throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName()); + + int index = name.lastIndexOf(':'); + String oldPrefix = index == -1 ? "" : name.substring(0, index); + name = index == -1 ? name : name.substring(index + 1); + ModContainer mc = Loader.instance().activeModContainer(); + String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId(); + if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0) + { + FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", oldPrefix, name); + prefix = oldPrefix; + } + this.registryName = new ResourceLocation(prefix, name); + return (T)this; + } + + //Helper functions + public final T setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); } + public final T setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); } + + public final ResourceLocation getRegistryName() + { + if (delegate.name() != null) return delegate.name(); + return registryName != null ? registryName : null; + } + + @Override + public final Class getRegistryType() { return token.getRawType(); }; + } +} 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 5696d4f62..294f04ff2 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java @@ -39,22 +39,29 @@ import com.google.common.collect.Sets.SetView; * * @author cpw */ +@SuppressWarnings("WeakerAccess") public class PersistentRegistryManager { private enum PersistentRegistry { - ACTIVE, FROZEN, STAGING; + ACTIVE, VANILLA, FROZEN, STAGING; private final BiMap> registries = HashBiMap.create(); - private final BiMap, ResourceLocation> registrySuperTypes = HashBiMap.create(); + private final BiMap>, ResourceLocation> registrySuperTypes = HashBiMap.create(); @SuppressWarnings("unchecked") - FMLControlledNamespacedRegistry getRegistry(ResourceLocation key, Class regType) + private > Class getRegistrySuperType(ResourceLocation key) + { + return (Class)registrySuperTypes.inverse().get(key); + } + + @SuppressWarnings("unchecked") + private > FMLControlledNamespacedRegistry getRegistry(ResourceLocation key, @SuppressWarnings("UnusedParameters") Class regType) { return (FMLControlledNamespacedRegistry)registries.get(key); } - FMLControlledNamespacedRegistry getOrShallowCopyRegistry(ResourceLocation key, Class regType, FMLControlledNamespacedRegistry other) + private > FMLControlledNamespacedRegistry getOrShallowCopyRegistry(ResourceLocation key, Class regType, FMLControlledNamespacedRegistry other) { if (!registries.containsKey(key)) { @@ -64,12 +71,7 @@ public class PersistentRegistryManager return getRegistry(key, regType); } - private FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class registryType, ResourceLocation optionalDefaultKey, int minId, int maxId, boolean hasDelegates) - { - return this.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, hasDelegates, null); - } - - private FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class type, ResourceLocation defaultObjectKey, int minId, int maxId, boolean isDelegated, FMLControlledNamespacedRegistry.AddCallback addCallback) + private > FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class type, ResourceLocation defaultObjectKey, int minId, int maxId, IForgeRegistry.AddCallback addCallback, IForgeRegistry.ClearCallback clearCallback, IForgeRegistry.CreateCallback createCallback) { Set> parents = Sets.newHashSet(); findSuperTypes(type, parents); @@ -80,7 +82,7 @@ public class PersistentRegistryManager FMLLog.severe("Found existing registry of type %1s named %2s, you cannot create a new registry (%3s) with type %4s, as %4s has a parent of that type", foundType, registrySuperTypes.get(foundType), registryName, type); throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type"); } - FMLControlledNamespacedRegistry fmlControlledNamespacedRegistry = new FMLControlledNamespacedRegistry(defaultObjectKey, maxId, minId, type, isDelegated, addCallback); + FMLControlledNamespacedRegistry fmlControlledNamespacedRegistry = new FMLControlledNamespacedRegistry(defaultObjectKey, minId, maxId, type, addCallback, clearCallback, createCallback); registries.put(registryName, fmlControlledNamespacedRegistry); registrySuperTypes.put(type, registryName); return getRegistry(registryName, type); @@ -117,7 +119,7 @@ public class PersistentRegistryManager return registries.containsValue(registry); } - public FMLControlledNamespacedRegistry getRegistry(Class rootClass) + public > FMLControlledNamespacedRegistry getRegistry(Class rootClass) { ResourceLocation rl = registrySuperTypes.get(rootClass); return getRegistry(rl, rootClass); @@ -129,16 +131,25 @@ public class PersistentRegistryManager public static final ResourceLocation POTIONS = new ResourceLocation("minecraft:potions"); public static final ResourceLocation BIOMES = new ResourceLocation("minecraft:biomes"); - public static FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class registryType, ResourceLocation optionalDefaultKey, int maxId, int minId, boolean hasDelegates, FMLControlledNamespacedRegistry.AddCallback addCallback) + 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) { - return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, hasDelegates, addCallback); + return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, addCallback, clearCallback, createCallback); } - public static FMLControlledNamespacedRegistry createRegistry(ResourceLocation registryName, Class registryType, ResourceLocation optionalDefaultKey, int maxId, int minId, boolean hasDelegates) + @SuppressWarnings("unchecked") + static > IForgeRegistry findRegistry(IForgeRegistryEntry entry) { - return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, hasDelegates); + final Class registryType = (Class)entry.getRegistryType(); + final FMLControlledNamespacedRegistry registry = PersistentRegistry.ACTIVE.getRegistry(registryType); + if (registry == null) + { + FMLLog.getLogger().log(Level.ERROR, "Unable to locate registry for registered object of type {}", entry.getClass().getName()); + throw new IllegalArgumentException("Unable to locate registry for registered object"); + } + return registry; } + public static List injectSnapshot(GameDataSnapshot snapshot, boolean injectFrozenData, boolean isLocalWorld) { FMLLog.info("Injecting existing block and item data into this %s instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); @@ -149,13 +160,11 @@ public class PersistentRegistryManager forAllRegistries(PersistentRegistry.ACTIVE, DumpRegistryFunction.OPERATION); forAllRegistries(PersistentRegistry.ACTIVE, ResetDelegatesFunction.OPERATION); - // Empty the blockstate map before loading - GameData.getBlockStateIDMap().clear(); - // Load the snapshot into the "STAGING" registry for (Map.Entry snapshotEntry : snapshot.entries.entrySet()) { - loadPersistentDataToStagingRegistry(injectFrozenData, remaps, missing, snapshotEntry, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(snapshotEntry.getKey())); + final Class registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(snapshotEntry.getKey()); + loadPersistentDataToStagingRegistry(injectFrozenData, remaps, missing, snapshotEntry, registrySuperType); } // Handle dummied blocks @@ -213,7 +222,8 @@ public class PersistentRegistryManager // So we load it from the frozen persistent registry for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadFrozenDataToStagingRegistry(remaps, r.getKey(), PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + final Class registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey()); + loadFrozenDataToStagingRegistry(remaps, r.getKey(), registrySuperType); } } @@ -223,7 +233,8 @@ public class PersistentRegistryManager // Load the STAGING registry into the ACTIVE registry for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.STAGING, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + final Class registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey()); + loadRegistry(r.getKey(), PersistentRegistry.STAGING, PersistentRegistry.ACTIVE, registrySuperType); } // Dump the active registry @@ -254,7 +265,7 @@ public class PersistentRegistryManager } } - private static void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, Class regType) + private static > void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, final Class regType) { FMLControlledNamespacedRegistry fromRegistry = from.getRegistry(registryName, regType); if (fromRegistry == null) @@ -290,14 +301,14 @@ public class PersistentRegistryManager } } - private static void loadFrozenDataToStagingRegistry(Map> remaps, ResourceLocation registryName, Class regType) + private static > void loadFrozenDataToStagingRegistry(Map> remaps, ResourceLocation registryName, Class regType) { FMLControlledNamespacedRegistry frozenRegistry = PersistentRegistry.FROZEN.getRegistry(registryName, regType); FMLControlledNamespacedRegistry newRegistry = PersistentRegistry.STAGING.getOrShallowCopyRegistry(registryName, regType, frozenRegistry); newRegistry.loadIds(frozenRegistry.getEntriesNotIn(newRegistry), Maps.newLinkedHashMap(), remaps.get(registryName), frozenRegistry, registryName); } - private static void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map> remaps, LinkedHashMap> missing, Map.Entry snapEntry, Class regType) + private static > void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map> remaps, LinkedHashMap> missing, Map.Entry snapEntry, Class regType) { ResourceLocation registryName = snapEntry.getKey(); @@ -311,6 +322,7 @@ public class PersistentRegistryManager { FMLLog.severe("An unknown persistent registry type \"%s\" has been encountered. This Forge instance cannot understand it.", registryName); StartupQuery.abort(); + return; // fake exit to shut up null analysis } FMLControlledNamespacedRegistry newRegistry = PersistentRegistry.STAGING.getOrShallowCopyRegistry(registryName, regType, currentRegistry); // Copy the persistent substitution set from the currently active one into the new registry @@ -350,7 +362,8 @@ public class PersistentRegistryManager } for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + final Class registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey()); + loadRegistry(r.getKey(), PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE, registrySuperType); } // the id mapping has reverted, fire remap events for those that care about id changes Loader.instance().fireRemapEvent(ImmutableMap.of(), ImmutableMap.of(), true); @@ -365,7 +378,9 @@ public class PersistentRegistryManager FMLLog.fine("Freezing block and item id maps"); for (Map.Entry> r : PersistentRegistry.ACTIVE.registries.entrySet()) { - loadRegistry(r.getKey(), PersistentRegistry.ACTIVE, PersistentRegistry.FROZEN, PersistentRegistry.ACTIVE.registrySuperTypes.inverse().get(r.getKey())); + // This has to be performed prior to invoking the method so the compiler can precompute the type bounds for the method + final Class registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey()); + loadRegistry(r.getKey(), PersistentRegistry.ACTIVE, PersistentRegistry.FROZEN, registrySuperType); } forAllRegistries(PersistentRegistry.FROZEN, ValidateRegistryFunction.OPERATION); } @@ -576,7 +591,7 @@ public class PersistentRegistryManager public final Map entries = Maps.newHashMap(); } - public static RegistryDelegate makeDelegate(T obj, Class rootClass) + public static > RegistryDelegate makeDelegate(T obj, Class rootClass) { return PersistentRegistry.ACTIVE.getRegistry(rootClass).getDelegate(obj, rootClass); } @@ -617,4 +632,5 @@ public class PersistentRegistryManager return null; } } + } diff --git a/src/main/java/net/minecraftforge/fml/common/registry/RegistryDelegate.java b/src/main/java/net/minecraftforge/fml/common/registry/RegistryDelegate.java index 993542eb3..c0c5583db 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/RegistryDelegate.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/RegistryDelegate.java @@ -23,23 +23,12 @@ public interface RegistryDelegate { */ T get(); - /** - * Get the name of this delegate. This is completely static after registration has completed and will never change. - * - * Deprecated in favour of the resource location. - * - * @see #getResourceName() - * @return The name - */ - @Deprecated - String name(); - /** * Get the unique resource location for this delegate. Completely static after registration has completed, and * will never change. * @return The name */ - ResourceLocation getResourceName(); + ResourceLocation name(); /** * Get the delegate type. It will be dependent on the registry this delegate is sourced from. @@ -67,12 +56,7 @@ public interface RegistryDelegate { } @Override - public String name() { - return name.toString(); - } - - @Override - public ResourceLocation getResourceName() { return name; } + public ResourceLocation name() { return name; } @Override public Class type() @@ -85,7 +69,7 @@ public interface RegistryDelegate { this.referent = newTarget; } - void setResourceName(ResourceLocation name) { this.name = name; } + void setName(ResourceLocation name) { this.name = name; } @Override public boolean equals(Object obj) diff --git a/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java index 577edc265..f0cfb52a3 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java @@ -12,8 +12,6 @@ package net.minecraftforge.fml.common.registry; -import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Random; @@ -42,10 +40,6 @@ import net.minecraft.world.gen.structure.StructureComponent; import net.minecraft.world.gen.structure.StructureVillagePieces; import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight; import net.minecraft.world.gen.structure.StructureVillagePieces.Village; -import net.minecraftforge.fml.common.FMLLog; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - /** * Registry for villager trading control * @@ -57,9 +51,6 @@ public class VillagerRegistry private static final VillagerRegistry INSTANCE = new VillagerRegistry(); private Map, IVillageCreationHandler> villageCreationHandlers = Maps.newHashMap(); - private List newVillagerIds = Lists.newArrayList(); - @SideOnly(Side.CLIENT) - private Map newVillagers; private VillagerRegistry() { @@ -110,39 +101,6 @@ public class VillagerRegistry return INSTANCE; } - /** - * Register your villager id - * - * @param id - */ - @Deprecated // Doesn't work at all. - public void registerVillagerId(int id) - { - if (newVillagerIds.contains(id)) - { - FMLLog.severe("Attempt to register duplicate villager id %d", id); - throw new RuntimeException(); - } - newVillagerIds.add(id); - } - - /** - * Register a new skin for a villager type - * - * @param villagerId - * @param villagerSkin - */ - @SideOnly(Side.CLIENT) - @Deprecated // Doesn't work at all. - public void registerVillagerSkin(int villagerId, ResourceLocation villagerSkin) - { - if (newVillagers == null) - { - newVillagers = Maps.newHashMap(); - } - newVillagers.put(villagerId, villagerSkin); - } - /** * Register a new village creation handler * @@ -153,34 +111,6 @@ public class VillagerRegistry villageCreationHandlers.put(handler.getComponentClass(), handler); } - /** - * Callback to setup new villager types - * - * @param villagerType - * @param defaultSkin - */ - @SideOnly(Side.CLIENT) - @Deprecated // Doesn't work at all. - public static ResourceLocation getVillagerSkin(int villagerType, ResourceLocation defaultSkin) - { - if (instance().newVillagers != null && instance().newVillagers.containsKey(villagerType)) - { - return instance().newVillagers.get(villagerType); - } - return defaultSkin; - } - - /** - * Returns a list of all added villager types - * - * @return newVillagerIds - */ - @Deprecated // Doesn't work at all. - public static Collection getRegisteredVillagers() - { - return Collections.unmodifiableCollection(instance().newVillagerIds); - } - public static void addExtraVillageComponents(List list, Random random, int i) { List parts = list; @@ -207,7 +137,8 @@ public class VillagerRegistry } private boolean hasInit = false; - private FMLControlledNamespacedRegistry professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 1024, 0, true, null); + private FMLControlledNamespacedRegistry professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 0, 1024, true, null, null, null); + public IForgeRegistry getRegistry() { return this.professions; } private void init() @@ -250,18 +181,17 @@ public class VillagerRegistry } } - public static class VillagerProfession + public static class VillagerProfession extends IForgeRegistryEntry.Impl { private ResourceLocation name; private ResourceLocation texture; private List careers = Lists.newArrayList(); - public final RegistryDelegate delegate = PersistentRegistryManager.makeDelegate(this, VillagerProfession.class); public VillagerProfession(String name, String texture) { this.name = new ResourceLocation(name); this.texture = new ResourceLocation(texture); - ((RegistryDelegate.Delegate)delegate).setResourceName(this.name); + this.setRegistryName(this.name); } private void register(VillagerCareer career) @@ -271,6 +201,22 @@ public class VillagerRegistry career.id = careers.size(); careers.add(career); } + + public ResourceLocation getSkin() { return this.texture; } + public VillagerCareer getCareer(int id) + { + for (VillagerCareer car : this.careers) + { + if (car.id == id) + return car; + } + return this.careers.get(0); + } + + public int getRandomCareer(Random rand) + { + return this.careers.get(rand.nextInt(this.careers.size())).id; + } } public static class VillagerCareer @@ -278,6 +224,7 @@ public class VillagerRegistry private VillagerProfession profession; private String name; private int id; + private ITradeList[][] trades; public VillagerCareer(VillagerProfession parent, String name) { @@ -286,8 +233,19 @@ public class VillagerRegistry parent.register(this); } - private VillagerCareer init(EntityVillager.ITradeList[][] traids) + public String getName() { + return this.name; + } + + public ITradeList[][] getTrades() + { + return this.trades; + } + + private VillagerCareer init(EntityVillager.ITradeList[][] trades) + { + this.trades = trades; return this; } @@ -316,9 +274,7 @@ public class VillagerRegistry public static void setRandomProfession(EntityVillager entity, Random rand) { Set entries = INSTANCE.professions.getKeys(); - int prof = rand.nextInt(entries.size()); - //TODO: Grab id range from internal registry - entity.setProfession(rand.nextInt(5)); + entity.setProfession(rand.nextInt(entries.size())); } //TODO: Figure out a good generic system for this. Put on hold for Patches. diff --git a/src/main/java/net/minecraftforge/oredict/OreDictionary.java b/src/main/java/net/minecraftforge/oredict/OreDictionary.java index 806e38217..8de0550e7 100644 --- a/src/main/java/net/minecraftforge/oredict/OreDictionary.java +++ b/src/main/java/net/minecraftforge/oredict/OreDictionary.java @@ -326,7 +326,7 @@ public class OreDictionary // HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet // IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about. // APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game. - ResourceLocation registryName = stack.getItem().delegate.getResourceName(); + ResourceLocation registryName = stack.getItem().delegate.name(); int id; if (registryName == null) { @@ -488,7 +488,7 @@ public class OreDictionary // HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet // IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about. // APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game. - ResourceLocation registryName = ore.getItem().delegate.getResourceName(); + ResourceLocation registryName = ore.getItem().delegate.name(); int hash; if (registryName == null) { @@ -555,7 +555,7 @@ public class OreDictionary for (ItemStack ore : ores) { // HACK: use the registry name's ID. It is unique and it knows about substitutions - ResourceLocation name = ore.getItem().delegate.getResourceName(); + ResourceLocation name = ore.getItem().delegate.name(); int hash; if (name == null) {