Skip to content

Commit

Permalink
Fixed duplication of fully grown plants
Browse files Browse the repository at this point in the history
  • Loading branch information
OneEyeMaker committed Nov 13, 2024
1 parent f7826a5 commit 1fb33a4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/tb/common/block/BlockTBPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -177,7 +184,7 @@ public int getRenderType() {

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
ArrayList<ItemStack> 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
Expand Down

0 comments on commit 1fb33a4

Please sign in to comment.