From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Tue, 28 Dec 2021 16:22:20 -0600 Subject: [PATCH] Ability for hoe to replant crops and nether warts diff --git a/src/main/java/net/minecraft/world/level/block/BushBlock.java b/src/main/java/net/minecraft/world/level/block/BushBlock.java index 1f8cf302d2309aec2955832ffafd87f14934e141..4dbadec09f38e63b4b19ea127ce43a822baff081 100644 --- a/src/main/java/net/minecraft/world/level/block/BushBlock.java +++ b/src/main/java/net/minecraft/world/level/block/BushBlock.java @@ -50,4 +50,24 @@ public class BushBlock extends Block { public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType type) { return type == PathComputationType.AIR && !this.hasCollision ? true : super.isPathfindable(state, world, pos, type); } + + // Purpur start + public void playerDestroyAndReplant(net.minecraft.world.level.Level world, net.minecraft.world.entity.player.Player player, BlockPos pos, BlockState state, @javax.annotation.Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.world.item.ItemStack itemInHand, net.minecraft.world.level.ItemLike itemToReplant) { + player.awardStat(net.minecraft.stats.Stats.BLOCK_MINED.get(this)); + player.causeFoodExhaustion(0.005F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.BLOCK_MINED); + java.util.List dropList = Block.getDrops(state, (ServerLevel) world, pos, blockEntity, player, itemInHand); + + boolean planted = false; + for (net.minecraft.world.item.ItemStack itemToDrop : dropList) { + if (!planted && itemToDrop.getItem() == itemToReplant) { + world.setBlock(pos, defaultBlockState(), 3); + itemToDrop.setCount(itemToDrop.getCount() - 1); + planted = true; + } + Block.popResource(world, pos, itemToDrop); + } + + state.spawnAfterBreak((ServerLevel) world, pos, itemInHand); + } + // Purpur end } diff --git a/src/main/java/net/minecraft/world/level/block/CropBlock.java b/src/main/java/net/minecraft/world/level/block/CropBlock.java index e054edf9e7c4eef231e155516433c6faeb2ca540..8f035b1f1486f0e4d00e586fccf1a008ef8aaf36 100644 --- a/src/main/java/net/minecraft/world/level/block/CropBlock.java +++ b/src/main/java/net/minecraft/world/level/block/CropBlock.java @@ -199,4 +199,15 @@ public class CropBlock extends BushBlock implements BonemealableBlock { protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(CropBlock.AGE); } + + // Purpur start + @Override + public void playerDestroy(Level world, net.minecraft.world.entity.player.Player player, BlockPos pos, BlockState state, @javax.annotation.Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, ItemStack itemInHand) { + if (world.purpurConfig.hoeReplantsCrops && itemInHand.getItem() instanceof net.minecraft.world.item.HoeItem) { + super.playerDestroyAndReplant(world, player, pos, state, blockEntity, itemInHand, getBaseSeedId()); + } else { + super.playerDestroy(world, player, pos, state, blockEntity, itemInHand); + } + } + // Purpur end } diff --git a/src/main/java/net/minecraft/world/level/block/NetherWartBlock.java b/src/main/java/net/minecraft/world/level/block/NetherWartBlock.java index cc8e94dc7ad93a9b7cf71315f5910daa35bc0778..c0ef9c9c438a2716f5d2cd589a0b4e8538b5b347 100644 --- a/src/main/java/net/minecraft/world/level/block/NetherWartBlock.java +++ b/src/main/java/net/minecraft/world/level/block/NetherWartBlock.java @@ -60,4 +60,15 @@ public class NetherWartBlock extends BushBlock { protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(NetherWartBlock.AGE); } + + // Purpur start + @Override + public void playerDestroy(net.minecraft.world.level.Level world, net.minecraft.world.entity.player.Player player, BlockPos pos, BlockState state, @javax.annotation.Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, ItemStack itemInHand) { + if (world.purpurConfig.hoeReplantsNetherWarts && itemInHand.getItem() instanceof net.minecraft.world.item.HoeItem) { + super.playerDestroyAndReplant(world, player, pos, state, blockEntity, itemInHand, Items.NETHER_WART); + } else { + super.playerDestroy(world, player, pos, state, blockEntity, itemInHand); + } + } + // Purpur end } diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java index 042d93e68f883eda989a08bcffe7be0ff61c8d9b..7810776e47817c16caee500344f8c1d812b5782e 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -545,6 +545,8 @@ public class PurpurWorldConfig { public Map axeWaxables = new HashMap<>(); public Map axeWeatherables = new HashMap<>(); public Map hoeTillables = new HashMap<>(); + public boolean hoeReplantsCrops = false; + public boolean hoeReplantsNetherWarts = false; private void toolSettings() { axeStrippables.clear(); axeWaxables.clear(); @@ -686,6 +688,8 @@ public class PurpurWorldConfig { }); hoeTillables.put(block, new Tillable(condition, into, drops)); }); + hoeReplantsCrops = getBoolean("tools.hoe.replant-crops", hoeReplantsCrops); + hoeReplantsNetherWarts = getBoolean("tools.hoe.replant-nether-warts", hoeReplantsNetherWarts); } public boolean anvilAllowColors = false;