From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Sat, 9 Jan 2021 16:06:40 +0100 Subject: [PATCH] Farmland trampling changes This lets us choose if farmland trampling is fully disabled or only players may trample farmland. This lets us choose if entities can stop trampling if they fall a distance equal to their feather falling level, plus the extra block necessary to trample in the first place. Feather Falling 1 requires you to fall over 3+ blocks to trample. FF 2 requires 4+, etc. diff --git a/src/main/java/net/minecraft/world/level/block/FarmBlock.java b/src/main/java/net/minecraft/world/level/block/FarmBlock.java index aad204181c4f54ee533bfe3fc04a8705b847e371..16eb80e7926cf4fe421c17d7d851d457a2bc0f5d 100644 --- a/src/main/java/net/minecraft/world/level/block/FarmBlock.java +++ b/src/main/java/net/minecraft/world/level/block/FarmBlock.java @@ -97,12 +97,20 @@ public class FarmBlock extends Block { } // Purpur start + if (world.purpurConfig.farmlandTramplingDisabled) return; + if (world.purpurConfig.farmlandTramplingOnlyPlayers && !(entity instanceof Player)) return; if (world.purpurConfig.farmlandAlpha) { Block block = world.getBlockState(pos.below()).getBlock(); if (block instanceof FenceBlock || block instanceof WallBlock) { return; } } + if (world.purpurConfig.farmlandTramplingFeatherFalling) { + Iterator armor = entity.getArmorSlots().iterator(); + if (armor.hasNext() && net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.FALL_PROTECTION, armor.next()) >= (int) entity.fallDistance) { + return; + } + } // Purpur end if (CraftEventFactory.callEntityChangeBlockEvent(entity, pos, Blocks.DIRT.defaultBlockState()).isCancelled()) { return; diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java index e1b8d150f952d2b80ad37caeb273f60c3553aa11..5c021c6aef21ff3534a4b6a95fd1c0d5ac2ea2c1 100644 --- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java @@ -466,10 +466,16 @@ public class PurpurWorldConfig { public boolean farmlandBypassMobGriefing = false; public boolean farmlandGetsMoistFromBelow = false; public boolean farmlandAlpha = false; + public boolean farmlandTramplingDisabled = false; + public boolean farmlandTramplingOnlyPlayers = false; + public boolean farmlandTramplingFeatherFalling = false; private void farmlandSettings() { farmlandBypassMobGriefing = getBoolean("blocks.farmland.bypass-mob-griefing", farmlandBypassMobGriefing); farmlandGetsMoistFromBelow = getBoolean("blocks.farmland.gets-moist-from-below", farmlandGetsMoistFromBelow); farmlandAlpha = getBoolean("blocks.farmland.use-alpha-farmland", farmlandAlpha); + 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); } public boolean furnaceUseLavaFromUnderneath = false;