Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 7842d68

Browse files
BillyGalbreathgranny
authored andcommitted
Ability for hoe to replant crops and nether warts
1 parent 6de1d9a commit 7842d68

5 files changed

Lines changed: 65 additions & 97 deletions

File tree

patches/server/0218-Ability-for-hoe-to-replant-crops-and-nether-warts.patch

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--- a/net/minecraft/world/level/block/BushBlock.java
2+
+++ b/net/minecraft/world/level/block/BushBlock.java
3+
@@ -62,4 +_,24 @@
4+
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
5+
return pathComputationType == PathComputationType.AIR && !this.hasCollision || super.isPathfindable(state, pathComputationType);
6+
}
7+
+
8+
+ // Purpur start - Ability for hoe to replant crops
9+
+ 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) {
10+
+ player.awardStat(net.minecraft.stats.Stats.BLOCK_MINED.get(this));
11+
+ player.causeFoodExhaustion(0.005F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.BLOCK_MINED);
12+
+ java.util.List<net.minecraft.world.item.ItemStack> dropList = Block.getDrops(state, (net.minecraft.server.level.ServerLevel) world, pos, blockEntity, player, itemInHand);
13+
+
14+
+ boolean planted = false;
15+
+ for (net.minecraft.world.item.ItemStack itemToDrop : dropList) {
16+
+ if (!planted && itemToDrop.getItem() == itemToReplant) {
17+
+ world.setBlock(pos, defaultBlockState(), 3);
18+
+ itemToDrop.setCount(itemToDrop.getCount() - 1);
19+
+ planted = true;
20+
+ }
21+
+ Block.popResource(world, pos, itemToDrop);
22+
+ }
23+
+
24+
+ state.spawnAfterBreak((net.minecraft.server.level.ServerLevel) world, pos, itemInHand, true);
25+
+ }
26+
+ // Purpur end - Ability for hoe to replant crops
27+
}

purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/CropBlock.java.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@
99
serverLevel.destroyBlock(pos, true, entity);
1010
}
1111

12+
@@ -217,4 +_,15 @@
13+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
14+
builder.add(AGE);
15+
}
16+
+
17+
+ // Purpur start - Ability for hoe to replant crops
18+
+ @Override
19+
+ 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) {
20+
+ if (world.purpurConfig.hoeReplantsCrops && itemInHand.getItem() instanceof net.minecraft.world.item.HoeItem) {
21+
+ super.playerDestroyAndReplant(world, player, pos, state, blockEntity, itemInHand, getBaseSeedId());
22+
+ } else {
23+
+ super.playerDestroy(world, player, pos, state, blockEntity, itemInHand, includeDrops, dropExp);
24+
+ }
25+
+ }
26+
+ // Purpur end - Ability for hoe to replant crops
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/net/minecraft/world/level/block/NetherWartBlock.java
2+
+++ b/net/minecraft/world/level/block/NetherWartBlock.java
3+
@@ -70,4 +_,15 @@
4+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
5+
builder.add(AGE);
6+
}
7+
+
8+
+ // Purpur start - Ability for hoe to replant nether warts
9+
+ @Override
10+
+ 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) {
11+
+ if (world.purpurConfig.hoeReplantsNetherWarts && itemInHand.getItem() instanceof net.minecraft.world.item.HoeItem) {
12+
+ super.playerDestroyAndReplant(world, player, pos, state, blockEntity, itemInHand, Items.NETHER_WART);
13+
+ } else {
14+
+ super.playerDestroy(world, player, pos, state, blockEntity, itemInHand, includeDrops, dropExp);
15+
+ }
16+
+ }
17+
+ // Purpur end - Ability for hoe to replant nether warts
18+
}

purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ private void snowballSettings() {
508508
public Map<Block, Weatherable> axeWeatherables = new HashMap<>();
509509
public Map<Block, Tillable> hoeTillables = new HashMap<>();
510510
public Map<Block, Flattenable> shovelFlattenables = new HashMap<>();
511+
public boolean hoeReplantsCrops = false;
512+
public boolean hoeReplantsNetherWarts = false;
511513
private void toolSettings() {
512514
axeStrippables.clear();
513515
axeWaxables.clear();
@@ -782,6 +784,8 @@ private void toolSettings() {
782784
});
783785
shovelFlattenables.put(block, new Flattenable(into, drops));
784786
});
787+
hoeReplantsCrops = getBoolean("tools.hoe.replant-crops", hoeReplantsCrops);
788+
hoeReplantsNetherWarts = getBoolean("tools.hoe.replant-nether-warts", hoeReplantsNetherWarts);
785789
}
786790

787791
public boolean anvilAllowColors = false;

0 commit comments

Comments
 (0)