diff --git a/patches/minecraft/net/minecraft/block/FlowerPotBlock.java.patch b/patches/minecraft/net/minecraft/block/FlowerPotBlock.java.patch index 39150888f8..e92decbe73 100644 --- a/patches/minecraft/net/minecraft/block/FlowerPotBlock.java.patch +++ b/patches/minecraft/net/minecraft/block/FlowerPotBlock.java.patch @@ -1,11 +1,88 @@ --- a/net/minecraft/block/FlowerPotBlock.java +++ b/net/minecraft/block/FlowerPotBlock.java -@@ -19,7 +19,7 @@ +@@ -19,14 +19,35 @@ import net.minecraft.world.World; public class FlowerPotBlock extends Block { - private static final Map field_196451_b = Maps.newHashMap(); -+ private static final Map field_196451_b = Maps.newHashMap(); //TODO: Delegates protected static final VoxelShape field_196450_a = Block.func_208617_a(5.0D, 0.0D, 5.0D, 11.0D, 6.0D, 11.0D); - private final Block field_196452_c; +- private final Block field_196452_c; ++ private final FlowerPotBlock emptyPot; ++ private final Map, net.minecraftforge.registries.IRegistryDelegate> fullPots; ++ private final net.minecraftforge.registries.IRegistryDelegate field_196452_c; ++ @Deprecated // Mods should use the constructor below + public FlowerPotBlock(Block p_i48395_1_, Block.Properties p_i48395_2_) { ++ this((FlowerPotBlock) Blocks.field_150457_bL, p_i48395_1_, p_i48395_2_); ++ } ++ ++ /** ++ * For mod use, eliminates the need to extend this class, and prevents modded ++ * flower pots from altering vanilla behavior. ++ * ++ * @param emptyPot The empty pot for this pot, or null for self. ++ * @param p_i48395_1_ The flower block. ++ * @param p_i48395_2_ ++ */ ++ public FlowerPotBlock(FlowerPotBlock emptyPot, Block p_i48395_1_, Block.Properties p_i48395_2_) { + super(p_i48395_2_); +- this.field_196452_c = p_i48395_1_; +- field_196451_b.put(p_i48395_1_, this); ++ this.field_196452_c = p_i48395_1_.delegate; ++ if (emptyPot == null) { ++ this.fullPots = Maps.newHashMap(); ++ this.emptyPot = this; ++ } else { ++ this.emptyPot = emptyPot; ++ this.fullPots = emptyPot.fullPots; ++ this.fullPots.put(p_i48395_1_.delegate, this.delegate); ++ } + } + + public VoxelShape func_220053_a(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) { +@@ -40,9 +61,9 @@ + public boolean func_220051_a(BlockState p_220051_1_, World p_220051_2_, BlockPos p_220051_3_, PlayerEntity p_220051_4_, Hand p_220051_5_, BlockRayTraceResult p_220051_6_) { + ItemStack itemstack = p_220051_4_.func_184586_b(p_220051_5_); + Item item = itemstack.func_77973_b(); +- Block block = item instanceof BlockItem ? field_196451_b.getOrDefault(((BlockItem)item).func_179223_d(), Blocks.field_150350_a) : Blocks.field_150350_a; ++ Block block = item instanceof BlockItem ? fullPots.getOrDefault(((BlockItem)item).func_179223_d().delegate, Blocks.field_150350_a.delegate).get() : Blocks.field_150350_a; + boolean flag = block == Blocks.field_150350_a; +- boolean flag1 = this.field_196452_c == Blocks.field_150350_a; ++ boolean flag1 = this.field_196452_c.get() == Blocks.field_150350_a; + if (flag != flag1) { + if (flag1) { + p_220051_2_.func_180501_a(p_220051_3_, block.func_176223_P(), 3); +@@ -51,14 +72,14 @@ + itemstack.func_190918_g(1); + } + } else { +- ItemStack itemstack1 = new ItemStack(this.field_196452_c); ++ ItemStack itemstack1 = new ItemStack(this.field_196452_c.get()); + if (itemstack.func_190926_b()) { + p_220051_4_.func_184611_a(p_220051_5_, itemstack1); + } else if (!p_220051_4_.func_191521_c(itemstack1)) { + p_220051_4_.func_71019_a(itemstack1, false); + } + +- p_220051_2_.func_180501_a(p_220051_3_, Blocks.field_150457_bL.func_176223_P(), 3); ++ p_220051_2_.func_180501_a(p_220051_3_, emptyPot.func_176223_P(), 3); + } + } + +@@ -66,7 +87,7 @@ + } + + public ItemStack func_185473_a(IBlockReader p_185473_1_, BlockPos p_185473_2_, BlockState p_185473_3_) { +- return this.field_196452_c == Blocks.field_150350_a ? super.func_185473_a(p_185473_1_, p_185473_2_, p_185473_3_) : new ItemStack(this.field_196452_c); ++ return this.field_196452_c.get() == Blocks.field_150350_a ? super.func_185473_a(p_185473_1_, p_185473_2_, p_185473_3_) : new ItemStack(this.field_196452_c.get()); + } + + public BlockState func_196271_a(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, IWorld p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) { +@@ -78,6 +99,6 @@ + } + + public Block func_220276_d() { +- return this.field_196452_c; ++ return this.field_196452_c.get(); + } + } diff --git a/src/main/resources/forge.exc b/src/main/resources/forge.exc index b0d26a1b94..faf8e0c9ae 100644 --- a/src/main/resources/forge.exc +++ b/src/main/resources/forge.exc @@ -1,5 +1,5 @@ net/minecraft/block/FireBlock.tryCatchFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;ILnet/minecraft/util/Direction;)V=|p_176536_1_,p_176536_2_,p_176536_3_,p_176536_4_,p_176536_5_,face - +net/minecraft/block/FlowerPotBlock.(Lnet/minecraft/block/FlowerPotBlock;Lnet/minecraft/block/Block;Lnet/minecraft/block/Block$Properties;)V=|emptyPot,p_i48395_1_,p_i48395_2_ net/minecraft/block/RedstoneWireBlock.canConnectTo(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Direction;)Z=|p_176343_0_,world,pos,p_176343_1_ net/minecraft/block/PoweredRailBlock.(Lnet/minecraft/block/Block$Properties;Z)=|p_i48349_1_,isActivator diff --git a/src/test/java/net/minecraftforge/debug/block/FlowerPotTest.java b/src/test/java/net/minecraftforge/debug/block/FlowerPotTest.java new file mode 100644 index 0000000000..c7d850b3ce --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/block/FlowerPotTest.java @@ -0,0 +1,59 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.debug.block; + +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.block.FlowerPotBlock; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.registries.ObjectHolder; + +@Mod(FlowerPotTest.MODID) +@Mod.EventBusSubscriber(bus = Bus.MOD) +public class FlowerPotTest +{ + static final String MODID = "flower_pot_test"; + static final String BLOCK_ID = "test_flower_pot"; + + @ObjectHolder(BLOCK_ID) + public static FlowerPotBlock EMPTY_FLOWER_POT; + + @ObjectHolder(BLOCK_ID) + public static FlowerPotBlock OAK_FLOWER_POT; + + @SubscribeEvent + public static void registerBlocks(RegistryEvent.Register event) + { + FlowerPotBlock empty = new FlowerPotBlock(null, Blocks.AIR, Block.Properties.from(Blocks.FLOWER_POT)); + event.getRegistry().register(empty.setRegistryName(BLOCK_ID)); + event.getRegistry().register(new FlowerPotBlock(empty, Blocks.OAK_SAPLING, Block.Properties.from(empty)).setRegistryName(BLOCK_ID + "_oak")); + } + + @SubscribeEvent + public static void registerItems(RegistryEvent.Register event) + { + event.getRegistry().register(new BlockItem(EMPTY_FLOWER_POT, new Item.Properties()).setRegistryName(MODID, BLOCK_ID)); + } +} diff --git a/src/test/java/net/minecraftforge/debug/block/StickyBlockTest.java b/src/test/java/net/minecraftforge/debug/block/StickyBlockTest.java index edd80c5517..9f9b58d41d 100644 --- a/src/test/java/net/minecraftforge/debug/block/StickyBlockTest.java +++ b/src/test/java/net/minecraftforge/debug/block/StickyBlockTest.java @@ -27,10 +27,11 @@ import net.minecraft.item.Item; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.registries.ObjectHolder; @Mod(StickyBlockTest.MODID) -@Mod.EventBusSubscriber +@Mod.EventBusSubscriber(bus = Bus.MOD) public class StickyBlockTest { static final String MODID = "custom_slime_block_test"; diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index d950081cc3..2dceda89fd 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -51,3 +51,5 @@ loaderVersion="[28,)" modId="data_gen_test" [[mods]] modId="piston_event_test" +[[mods]] + modId="flower_pot_test" diff --git a/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot.json b/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot.json new file mode 100644 index 0000000000..8f9ab79e8d --- /dev/null +++ b/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "block/flower_pot" } + } +} diff --git a/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot_oak.json b/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot_oak.json new file mode 100644 index 0000000000..47837f102b --- /dev/null +++ b/src/test/resources/assets/flower_pot_test/blockstates/test_flower_pot_oak.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "block/potted_oak_sapling" } + } +} diff --git a/src/test/resources/assets/flower_pot_test/models/item/test_flower_pot.json b/src/test/resources/assets/flower_pot_test/models/item/test_flower_pot.json new file mode 100644 index 0000000000..320004b20f --- /dev/null +++ b/src/test/resources/assets/flower_pot_test/models/item/test_flower_pot.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "item/flower_pot" + } +}