mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Ability for hoe to replant crops and nether warts
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: BillyGalbreath <blake.galbreath@gmail.com>
|
||||
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<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
|
||||
}
|
||||
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<Block, BlockState> 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<Block, BlockState> 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<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();
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user