From 1fb33a4da91c184028cf090347caa1645d65cbb9 Mon Sep 17 00:00:00 2001 From: Alexander Anishin Date: Wed, 13 Nov 2024 14:52:22 +0300 Subject: [PATCH] Fixed duplication of fully grown plants --- src/main/java/tb/common/block/BlockTBPlant.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/tb/common/block/BlockTBPlant.java b/src/main/java/tb/common/block/BlockTBPlant.java index 143479c..1dd6c37 100644 --- a/src/main/java/tb/common/block/BlockTBPlant.java +++ b/src/main/java/tb/common/block/BlockTBPlant.java @@ -8,6 +8,7 @@ import net.minecraft.block.IGrowable; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -52,7 +53,7 @@ public Item getItem(World w, int x, int y, int z) { } protected boolean canPlaceBlockOn(Block b) { - return requiresFarmland ? b == Blocks.farmland : true; + return !requiresFarmland || b == Blocks.farmland; } public void updateTick(World w, int x, int y, int z, Random rnd) { @@ -143,6 +144,12 @@ public void func_149853_b(World w, Random r, int x, int y, int z) { 3); } + @Override + public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) { + // Prevent placement of fully grown plants + worldIn.setBlockMetadataWithNotify(x, y, z, 0, 2); + } + @Override public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int aSide, float pX, float pY, float pZ) { @@ -177,7 +184,7 @@ public int getRenderType() { @Override public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - ArrayList ret = new ArrayList(); + ArrayList ret = new ArrayList<>(); if (this.dropItem != null && metadata >= growthStages - 1) { // You can approximate the fortune bonus by diving https://oeis.org/A000169 with https://oeis.org/A000435