From 17faace2580cca86bf2ed6ff83fc297e0a0dba5f Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sun, 12 Jan 2025 14:15:15 -0800 Subject: [PATCH] Configurable farmland trample height This is _not_ in block height or an exact science. During my testing I found very inconsistent values for the fallDistance variable. Here are the results of those tests (https://imgur.com/BojltJF): Value set -> Actual fall distance needed to trample 1.0 -> 1.25 1.5 -> 1.75 2.0 -> 2.25 2.5 -> 2.87 3.0 -> 3.5 3.5 -> 4.25 4.0 -> 4.25 4.5 -> 5.0 5.0 -> 5.87 5.5 -> 5.87 --- ...Configurable-farmland-trample-height.patch | 56 ------------------- .../world/level/block/FarmBlock.java.patch | 9 +++ .../purpurmc/purpur/PurpurWorldConfig.java | 2 + 3 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 patches/server/0224-Configurable-farmland-trample-height.patch diff --git a/patches/server/0224-Configurable-farmland-trample-height.patch b/patches/server/0224-Configurable-farmland-trample-height.patch deleted file mode 100644 index 022af4ca2..000000000 --- a/patches/server/0224-Configurable-farmland-trample-height.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: BillyGalbreath -Date: Tue, 4 Jan 2022 11:56:48 -0600 -Subject: [PATCH] Configurable farmland trample height - -This is _not_ in block height or an exact science. -During my testing I found very inconsistent values -for the fallDistance variable. Here are the results -of those tests (https://imgur.com/BojltJF): - -Value set -> Actual fall distance needed to trample - 1.0 -> 1.25 - 1.5 -> 1.75 - 2.0 -> 2.25 - 2.5 -> 2.87 - 3.0 -> 3.5 - 3.5 -> 4.25 - 4.0 -> 4.25 - 4.5 -> 5.0 - 5.0 -> 5.87 - 5.5 -> 5.87 - 6.0 -> 6.75 - -diff --git a/net/minecraft/world/level/block/FarmBlock.java b/net/minecraft/world/level/block/FarmBlock.java -index fc5a755c558714442c1e12e88ee05764d6c1d9f4..f1ef2eda3282b3bcd99e388dc56d5542cd93bedb 100644 ---- a/net/minecraft/world/level/block/FarmBlock.java -+++ b/net/minecraft/world/level/block/FarmBlock.java -@@ -112,7 +112,7 @@ public class FarmBlock extends Block { - public void fallOn(Level world, BlockState state, BlockPos pos, Entity entity, float fallDistance) { - super.fallOn(world, state, pos, entity, fallDistance); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage. - if (world instanceof ServerLevel worldserver) { -- if (world.random.nextFloat() < fallDistance - 0.5F && entity instanceof LivingEntity && (entity instanceof Player || worldserver.purpurConfig.farmlandBypassMobGriefing ^ worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { // Purpur - Add mobGriefing bypass to everything affected -+ if ((worldserver.purpurConfig.farmlandTrampleHeight >= 0D ? fallDistance >= worldserver.purpurConfig.farmlandTrampleHeight : world.random.nextFloat() < fallDistance - 0.5F) && entity instanceof LivingEntity && (entity instanceof Player || worldserver.purpurConfig.farmlandBypassMobGriefing ^ worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { // Purpur - Add mobGriefing bypass to everything affected // Purpur - Configurable farmland trample height - // CraftBukkit start - Interact soil - org.bukkit.event.Cancellable cancellable; - if (entity instanceof Player) { -diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -index d71abce6d9dc812d46eda7acff5249621e5b0ae7..c5e894560b3ac371da123a339355fa89dd442ee4 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -@@ -936,6 +936,7 @@ public class PurpurWorldConfig { - public boolean farmlandTramplingDisabled = false; - public boolean farmlandTramplingOnlyPlayers = false; - public boolean farmlandTramplingFeatherFalling = false; -+ public double farmlandTrampleHeight = -1D; - private void farmlandSettings() { - farmlandBypassMobGriefing = getBoolean("blocks.farmland.bypass-mob-griefing", farmlandBypassMobGriefing); - farmlandGetsMoistFromBelow = getBoolean("blocks.farmland.gets-moist-from-below", farmlandGetsMoistFromBelow); -@@ -943,6 +944,7 @@ public class PurpurWorldConfig { - farmlandTramplingDisabled = getBoolean("blocks.farmland.disable-trampling", farmlandTramplingDisabled); - farmlandTramplingOnlyPlayers = getBoolean("blocks.farmland.only-players-trample", farmlandTramplingOnlyPlayers); - farmlandTramplingFeatherFalling = getBoolean("blocks.farmland.feather-fall-distance-affects-trampling", farmlandTramplingFeatherFalling); -+ farmlandTrampleHeight = getDouble("blocks.farmland.trample-height", farmlandTrampleHeight); - } - - public double floweringAzaleaGrowthChance = 0.0D; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/FarmBlock.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/FarmBlock.java.patch index e2cbbaf28..7f0aa19b6 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/FarmBlock.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/level/block/FarmBlock.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/world/level/block/FarmBlock.java +++ b/net/minecraft/world/level/block/FarmBlock.java +@@ -112,7 +_,7 @@ + public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) { + super.fallOn(level, state, pos, entity, fallDistance); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage. + if (level instanceof ServerLevel serverLevel +- && level.random.nextFloat() < fallDistance - 0.5F ++ && (serverLevel.purpurConfig.farmlandTrampleHeight >= 0D ? fallDistance >= serverLevel.purpurConfig.farmlandTrampleHeight : level.random.nextFloat() < fallDistance - 0.5F) // // Purpur - Configurable farmland trample height + && entity instanceof LivingEntity + && (entity instanceof Player || serverLevel.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) + && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { @@ -129,6 +_,27 @@ return; } 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 bbbc55999..98d5ed5d5 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -935,6 +935,7 @@ public class PurpurWorldConfig { public boolean farmlandTramplingDisabled = false; public boolean farmlandTramplingOnlyPlayers = false; public boolean farmlandTramplingFeatherFalling = false; + public double farmlandTrampleHeight = -1D; private void farmlandSettings() { farmlandBypassMobGriefing = getBoolean("blocks.farmland.bypass-mob-griefing", farmlandBypassMobGriefing); farmlandGetsMoistFromBelow = getBoolean("blocks.farmland.gets-moist-from-below", farmlandGetsMoistFromBelow); @@ -942,6 +943,7 @@ public class PurpurWorldConfig { farmlandTramplingDisabled = getBoolean("blocks.farmland.disable-trampling", farmlandTramplingDisabled); farmlandTramplingOnlyPlayers = getBoolean("blocks.farmland.only-players-trample", farmlandTramplingOnlyPlayers); farmlandTramplingFeatherFalling = getBoolean("blocks.farmland.feather-fall-distance-affects-trampling", farmlandTramplingFeatherFalling); + farmlandTrampleHeight = getDouble("blocks.farmland.trample-height", farmlandTrampleHeight); } public double floweringAzaleaGrowthChance = 0.0D;