Ability for hoe to replant crops and nether warts

This commit is contained in:
BillyGalbreath
2025-01-12 13:59:28 -08:00
committed by granny
parent 6de1d9acfa
commit 7842d68581
5 changed files with 65 additions and 97 deletions

View File

@@ -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<net.minecraft.world.item.ItemStack> 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
}

View File

@@ -9,3 +9,19 @@
serverLevel.destroyBlock(pos, true, entity);
}
@@ -217,4 +_,15 @@
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> 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
}

View File

@@ -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<Block, BlockState> 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
}

View File

@@ -508,6 +508,8 @@ public class PurpurWorldConfig {
public Map<Block, Weatherable> axeWeatherables = new HashMap<>();
public Map<Block, Tillable> hoeTillables = new HashMap<>();
public Map<Block, Flattenable> 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;