From c76be4a46188df1a3b1baec1d121e898c5ec832f Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 6 Feb 2019 12:40:23 +0200 Subject: [PATCH] Destroy connected alfalfa blocks when destroyed by a player. Might help with floating plants --- .../minelittlepony/unicopia/block/BlockAlfalfa.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java b/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java index 8a37d32c..97ca3b9c 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockAlfalfa.java @@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.block; import java.util.Random; +import javax.annotation.Nullable; + import com.minelittlepony.unicopia.UItems; import net.minecraft.block.BlockCrops; @@ -169,19 +171,23 @@ public class BlockAlfalfa extends BlockCrops { return getHalf(state) != Half.BOTTOM || super.canBlockStay(world, pos, state); } + public void onPlayerDestroy(World worldIn, BlockPos pos, IBlockState state) { + breakConnectedBlocks(worldIn, pos, null); + } + @Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { breakConnectedBlocks(worldIn, pos, player); } - protected void breakConnectedBlocks(World worldIn, BlockPos pos, EntityPlayer player) { + protected void breakConnectedBlocks(World worldIn, BlockPos pos, @Nullable EntityPlayer player) { IBlockState state = worldIn.getBlockState(pos); if (state.getBlock() != this) { return; } - if (player.capabilities.isCreativeMode) { + if (player != null && player.capabilities.isCreativeMode) { worldIn.setBlockToAir(pos); } else { if (worldIn.isRemote) {