From 7842d68581cd7d8715961f8265e15df7dbfb3fab Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sun, 12 Jan 2025 13:59:28 -0800 Subject: [PATCH] Ability for hoe to replant crops and nether warts --- ...oe-to-replant-crops-and-nether-warts.patch | 97 ------------------- .../world/level/block/BushBlock.java.patch | 27 ++++++ .../world/level/block/CropBlock.java.patch | 16 +++ .../level/block/NetherWartBlock.java.patch | 18 ++++ .../purpurmc/purpur/PurpurWorldConfig.java | 4 + 5 files changed, 65 insertions(+), 97 deletions(-) delete mode 100644 patches/server/0218-Ability-for-hoe-to-replant-crops-and-nether-warts.patch create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/BushBlock.java.patch create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/NetherWartBlock.java.patch diff --git a/patches/server/0218-Ability-for-hoe-to-replant-crops-and-nether-warts.patch b/patches/server/0218-Ability-for-hoe-to-replant-crops-and-nether-warts.patch deleted file mode 100644 index 0c00a5d2f..000000000 --- a/patches/server/0218-Ability-for-hoe-to-replant-crops-and-nether-warts.patch +++ /dev/null @@ -1,97 +0,0 @@ -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/net/minecraft/world/level/block/BushBlock.java b/net/minecraft/world/level/block/BushBlock.java -index eb324fda54ada3ed7941713a784ed2d686ec8c4b..09cc76f3fee4a767c9ec3fa592f2c3c6146344ec 100644 ---- a/net/minecraft/world/level/block/BushBlock.java -+++ b/net/minecraft/world/level/block/BushBlock.java -@@ -55,4 +55,24 @@ public abstract class BushBlock extends Block { - protected boolean isPathfindable(BlockState state, PathComputationType type) { - return type == PathComputationType.AIR && !this.hasCollision ? true : super.isPathfindable(state, 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, (net.minecraft.server.level.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((net.minecraft.server.level.ServerLevel) world, pos, itemInHand, true); -+ } -+ // Purpur end - } -diff --git a/net/minecraft/world/level/block/CropBlock.java b/net/minecraft/world/level/block/CropBlock.java -index 00a06146e119a47eeaf66d240b8dd84e38498676..34f338a246824dbabc7bc386b74cb62c78a8f1b6 100644 ---- a/net/minecraft/world/level/block/CropBlock.java -+++ b/net/minecraft/world/level/block/CropBlock.java -@@ -216,4 +216,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, boolean includeDrops, boolean dropExp) { -+ 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, includeDrops, dropExp); -+ } -+ } -+ // Purpur end - } -diff --git a/net/minecraft/world/level/block/NetherWartBlock.java b/net/minecraft/world/level/block/NetherWartBlock.java -index 7bb4994d6474c8ea59c102009253552020691b8f..b571bca4375ca7caf9b75dbf84009cb0604b66ad 100644 ---- a/net/minecraft/world/level/block/NetherWartBlock.java -+++ b/net/minecraft/world/level/block/NetherWartBlock.java -@@ -68,4 +68,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, boolean includeDrops, boolean dropExp) { -+ 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, includeDrops, dropExp); -+ } -+ } -+ // Purpur end - } -diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -index d1a20069971e46a5bd58a31390b54f9216d9cb64..6b579962256be91923531fa4dac21a34b581386b 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -@@ -509,6 +509,8 @@ public class PurpurWorldConfig { - public Map axeWeatherables = new HashMap<>(); - public Map hoeTillables = new HashMap<>(); - public Map shovelFlattenables = new HashMap<>(); -+ public boolean hoeReplantsCrops = false; -+ public boolean hoeReplantsNetherWarts = false; - private void toolSettings() { - axeStrippables.clear(); - axeWaxables.clear(); -@@ -783,6 +785,8 @@ public class PurpurWorldConfig { - }); - shovelFlattenables.put(block, new Flattenable(into, drops)); - }); -+ hoeReplantsCrops = getBoolean("tools.hoe.replant-crops", hoeReplantsCrops); -+ hoeReplantsNetherWarts = getBoolean("tools.hoe.replant-nether-warts", hoeReplantsNetherWarts); - } - - public boolean anvilAllowColors = false; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/BushBlock.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/BushBlock.java.patch new file mode 100644 index 000000000..fc893f1b7 --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/BushBlock.java.patch @@ -0,0 +1,27 @@ +--- a/net/minecraft/world/level/block/BushBlock.java ++++ b/net/minecraft/world/level/block/BushBlock.java +@@ -62,4 +_,24 @@ + protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) { + return pathComputationType == PathComputationType.AIR && !this.hasCollision || super.isPathfindable(state, pathComputationType); + } ++ ++ // Purpur start - Ability for hoe to replant crops ++ 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, (net.minecraft.server.level.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((net.minecraft.server.level.ServerLevel) world, pos, itemInHand, true); ++ } ++ // Purpur end - Ability for hoe to replant crops + } diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/CropBlock.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/CropBlock.java.patch index 2253c8ff2..f1bbca32a 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/CropBlock.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/CropBlock.java.patch @@ -9,3 +9,19 @@ serverLevel.destroyBlock(pos, true, entity); } +@@ -217,4 +_,15 @@ + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(AGE); + } ++ ++ // Purpur start - Ability for hoe to replant crops ++ @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, boolean includeDrops, boolean dropExp) { ++ 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, includeDrops, dropExp); ++ } ++ } ++ // Purpur end - Ability for hoe to replant crops + } diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/NetherWartBlock.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/NetherWartBlock.java.patch new file mode 100644 index 000000000..39c1ccf96 --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/NetherWartBlock.java.patch @@ -0,0 +1,18 @@ +--- a/net/minecraft/world/level/block/NetherWartBlock.java ++++ b/net/minecraft/world/level/block/NetherWartBlock.java +@@ -70,4 +_,15 @@ + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(AGE); + } ++ ++ // Purpur start - Ability for hoe to replant nether warts ++ @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, boolean includeDrops, boolean dropExp) { ++ 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, includeDrops, dropExp); ++ } ++ } ++ // Purpur end - Ability for hoe to replant nether warts + } diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java index dd28cb782..f29dfed25 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -508,6 +508,8 @@ public class PurpurWorldConfig { public Map axeWeatherables = new HashMap<>(); public Map hoeTillables = new HashMap<>(); public Map shovelFlattenables = new HashMap<>(); + public boolean hoeReplantsCrops = false; + public boolean hoeReplantsNetherWarts = false; private void toolSettings() { axeStrippables.clear(); axeWaxables.clear(); @@ -782,6 +784,8 @@ public class PurpurWorldConfig { }); shovelFlattenables.put(block, new Flattenable(into, drops)); }); + hoeReplantsCrops = getBoolean("tools.hoe.replant-crops", hoeReplantsCrops); + hoeReplantsNetherWarts = getBoolean("tools.hoe.replant-nether-warts", hoeReplantsNetherWarts); } public boolean anvilAllowColors = false;