From d5dfe0d422ac040618b1ddf752337ea558c2bfb7 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Tue, 27 Jun 2023 14:07:51 +0800 Subject: [PATCH] Shave snow layers (#29) --- ...004-Leaves-Server-Config-And-Command.patch | 9 +++- patches/server/0074-Shave-snow-layers.patch | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 patches/server/0074-Shave-snow-layers.patch diff --git a/patches/server/0004-Leaves-Server-Config-And-Command.patch b/patches/server/0004-Leaves-Server-Config-And-Command.patch index 5f975df..9245163 100644 --- a/patches/server/0004-Leaves-Server-Config-And-Command.patch +++ b/patches/server/0004-Leaves-Server-Config-And-Command.patch @@ -128,10 +128,10 @@ index a53514f2c510b29f596c361de7bc0b405c27e964..269c7ba0707db4fdc45a70000e0be892 .withRequiredArg() diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java new file mode 100644 -index 0000000000000000000000000000000000000000..f901ec32a948fa9705dc53389a279bd466a02fa3 +index 0000000000000000000000000000000000000000..4d8063f34c91ec4fe5a926f9d46555ce0d5bd8d9 --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java -@@ -0,0 +1,762 @@ +@@ -0,0 +1,767 @@ +package top.leavesmc.leaves; + +import com.destroystokyo.paper.util.SneakyThrow; @@ -719,6 +719,11 @@ index 0000000000000000000000000000000000000000..f901ec32a948fa9705dc53389a279bd4 + mendingCompatibilityInfinity = getBoolean("settings.modify.mending-compatibility-infinity", mendingCompatibilityInfinity); + } + ++ public static boolean shaveSnowLayers = true; ++ private static void shaveSnowLayers() { ++ shaveSnowLayers = getBoolean("settings.modify.shave-snow-layers", shaveSnowLayers); ++ } ++ + public static final class WorldConfig { + + public final String worldName; diff --git a/patches/server/0074-Shave-snow-layers.patch b/patches/server/0074-Shave-snow-layers.patch new file mode 100644 index 0000000..8d3191c --- /dev/null +++ b/patches/server/0074-Shave-snow-layers.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: violetc <58360096+s-yh-china@users.noreply.github.com> +Date: Tue, 27 Jun 2023 14:07:00 +0800 +Subject: [PATCH] Shave snow layers + + +diff --git a/src/main/java/net/minecraft/world/item/ShovelItem.java b/src/main/java/net/minecraft/world/item/ShovelItem.java +index c7195f2e12bbd6545f7bffcc2b4ba5cc3d48df20..b8e160b78a9a6d4f73c9becef6ec0b17858b271f 100644 +--- a/src/main/java/net/minecraft/world/item/ShovelItem.java ++++ b/src/main/java/net/minecraft/world/item/ShovelItem.java +@@ -11,10 +11,12 @@ import net.minecraft.tags.BlockTags; + import net.minecraft.world.InteractionResult; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.context.UseOnContext; ++import net.minecraft.world.item.enchantment.EnchantmentHelper; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Block; + import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.level.block.CampfireBlock; ++import net.minecraft.world.level.block.SnowLayerBlock; + import net.minecraft.world.level.block.state.BlockState; + import net.minecraft.world.level.gameevent.GameEvent; + +@@ -34,6 +36,22 @@ public class ShovelItem extends DiggerItem { + return InteractionResult.PASS; + } else { + Player player = context.getPlayer(); ++ // Leaves start - shaveSnowLayers ++ if (top.leavesmc.leaves.LeavesConfig.shaveSnowLayers && blockState.is(Blocks.SNOW)) { ++ int layers = blockState.getValue(SnowLayerBlock.LAYERS); ++ level.setBlock(blockPos, layers > 1 ? blockState.setValue(SnowLayerBlock.LAYERS, layers - 1) : Blocks.AIR.defaultBlockState(), 11); ++ Block.popResource(level, blockPos, new ItemStack(EnchantmentHelper.hasSilkTouch(context.getItemInHand()) ? Items.SNOW : Items.SNOWBALL)); ++ level.playSound(player, blockPos, SoundEvents.SNOW_BREAK, SoundSource.BLOCKS, 1.0F, 1.0F); ++ ++ if(player != null) { ++ context.getItemInHand().hurtAndBreak(1, player, (p) -> { ++ p.broadcastBreakEvent(context.getHand()); ++ }); ++ } ++ ++ return InteractionResult.SUCCESS; ++ } ++ // Leaves end - shaveSnowLayers + BlockState blockState2 = FLATTENABLES.get(blockState.getBlock()); + BlockState blockState3 = null; + Runnable afterAction = null; // Paper