From 357a03dfe593ea10c8d1274460a49f65e59932f5 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Fri, 25 Jul 2025 10:47:18 +0800 Subject: [PATCH] Fix LitematicaEasyPlaceProtocol * 2 --- ...Alternative-block-placement-Protocol.patch | 33 ++++--------------- .../features/0050-Creative-fly-no-clip.patch | 4 +-- .../protocol/LitematicaEasyPlaceProtocol.java | 24 +++----------- 3 files changed, 14 insertions(+), 47 deletions(-) diff --git a/leaves-server/minecraft-patches/features/0029-Alternative-block-placement-Protocol.patch b/leaves-server/minecraft-patches/features/0029-Alternative-block-placement-Protocol.patch index 89a56f14..c2c5ef80 100644 --- a/leaves-server/minecraft-patches/features/0029-Alternative-block-placement-Protocol.patch +++ b/leaves-server/minecraft-patches/features/0029-Alternative-block-placement-Protocol.patch @@ -9,34 +9,15 @@ MasaGadget(https://github.com/plusls/MasaGadget) litematica(https://github.com/maruohon/litematica) diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java -index 6db566adf2d0df1d26221eda04aa01738df6d3d2..14387fa191fb52aaa8b25396292c1d528a6aed17 100644 +index 6db566adf2d0df1d26221eda04aa01738df6d3d2..8f112f382190d606a87f38da8bcdf8dd5f31d1c5 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java -@@ -150,6 +150,27 @@ public class BlockItem extends Item { +@@ -149,7 +149,7 @@ public class BlockItem extends Item { + @Nullable protected BlockState getPlacementState(BlockPlaceContext context) { - BlockState stateForPlacement = this.getBlock().getStateForPlacement(context); -+ // Leaves start - alternativeBlockPlacement -+ switch (org.leavesmc.leaves.LeavesConfig.protocol.alternativeBlockPlacement) { -+ case CARPET -> { -+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(getBlock(), context); -+ if (tryState != null) { -+ stateForPlacement = tryState; -+ } -+ } -+ case CARPET_FIX -> { -+ BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacementFix(getBlock(), context); -+ if (tryState != null) { -+ stateForPlacement = tryState; -+ } -+ } -+ case LITEMATICA -> { -+ if (stateForPlacement != null && this.canPlace(context, stateForPlacement)) { -+ return org.leavesmc.leaves.protocol.LitematicaEasyPlaceProtocol.applyPlacementProtocol(stateForPlacement, context); -+ } -+ } -+ } -+ // Leaves end - alternativeBlockPlacement +- BlockState stateForPlacement = this.getBlock().getStateForPlacement(context); ++ BlockState stateForPlacement = this.getBlock().getRealStateForPlacement(context); // Leaves - alternativeBlockPlacement return stateForPlacement != null && this.canPlace(context, stateForPlacement) ? stateForPlacement : null; } @@ -62,7 +43,7 @@ index 12c6c8aeec89a0a55633c62fe98f5a3aa75fd476..1f0e7c391d02b18e2c89700025713ec3 blockState = blockState1; break; diff --git a/net/minecraft/world/level/block/Block.java b/net/minecraft/world/level/block/Block.java -index 958914e40fceda5d67a98154817b4c5ce478a62d..02ea7616e0c19032374959f59a9ab186e91c5f7b 100644 +index 958914e40fceda5d67a98154817b4c5ce478a62d..3c5fd8efbe577c9b262870444984ad249097b8c2 100644 --- a/net/minecraft/world/level/block/Block.java +++ b/net/minecraft/world/level/block/Block.java @@ -439,6 +439,33 @@ public class Block extends BlockBehaviour implements ItemLike { @@ -72,7 +53,7 @@ index 958914e40fceda5d67a98154817b4c5ce478a62d..02ea7616e0c19032374959f59a9ab186 + // Leaves start - alternativeBlockPlacement + @Nullable + public BlockState getRealStateForPlacement(BlockPlaceContext ctx) { -+ BlockState vanillaState = getStateForPlacement(ctx); ++ BlockState vanillaState = this.getStateForPlacement(ctx); + switch (org.leavesmc.leaves.LeavesConfig.protocol.alternativeBlockPlacement) { + case CARPET -> { + BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(this, ctx); diff --git a/leaves-server/minecraft-patches/features/0050-Creative-fly-no-clip.patch b/leaves-server/minecraft-patches/features/0050-Creative-fly-no-clip.patch index ac0770e8..2a41dbcb 100644 --- a/leaves-server/minecraft-patches/features/0050-Creative-fly-no-clip.patch +++ b/leaves-server/minecraft-patches/features/0050-Creative-fly-no-clip.patch @@ -65,10 +65,10 @@ index 8ec6f52f58bcc985fdc758a692798a35d6c86378..0d046133ea2b6d47e089cb792cf3bc3a public boolean canBeHitByProjectile() { return !this.isSpectator() && super.canBeHitByProjectile(); diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java -index eff2c0418e1dc8dff1b9045d8f6ff619100964d1..8b6bbdf44a840e19722d42aec91fa1f8805f917b 100644 +index a46a50d1385897cc7fcf0d6976f0de7e8078d260..593e65ef3a768d4039047e42e666c8382a5d38eb 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java -@@ -206,8 +206,9 @@ public class BlockItem extends Item { +@@ -185,8 +185,9 @@ public class BlockItem extends Item { protected boolean canPlace(BlockPlaceContext context, BlockState state) { Player player = context.getPlayer(); // CraftBukkit start diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java index c50bb56d..cbb88179 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java @@ -1,6 +1,5 @@ package org.leavesmc.leaves.protocol; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -10,7 +9,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BedBlock; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.RepeaterBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; @@ -24,8 +23,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; public class LitematicaEasyPlaceProtocol { @@ -53,10 +50,6 @@ public class LitematicaEasyPlaceProtocol { BlockStateProperties.ROTATION_16 ); - public static final ImmutableMap, BiFunction> DYNAMIC_PROPERTIES = ImmutableMap.of( - BlockStateProperties.WATERLOGGED, (state, original) -> state.setValue(BlockStateProperties.WATERLOGGED, original.is(Blocks.WATER)) - ); - public static BlockState applyPlacementProtocol(BlockState state, BlockPlaceContext context) { return applyPlacementProtocolV3(state, UseContext.from(context, context.getHand())); } @@ -71,17 +64,6 @@ public class LitematicaEasyPlaceProtocol { } EnumProperty property = CarpetAlternativeBlockPlacement.getFirstDirectionProperty(state); - BlockState original = context.getWorld().getBlockStateIfLoaded(context.pos); - if (original == null) { - return oldState; - } - - for (Map.Entry, BiFunction> entry : DYNAMIC_PROPERTIES.entrySet()) { - if (state.hasProperty(entry.getKey())) { - state = entry.getValue().apply(state, original); - } - } - if (property != null && property != BlockStateProperties.VERTICAL_DIRECTION) { state = applyDirectionProperty(state, context, property, protocolValue); @@ -140,6 +122,10 @@ public class LitematicaEasyPlaceProtocol { LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value", e); } + if (state.getBlock() instanceof RepeaterBlock repeaterBlock) { + state = state.setValue(RepeaterBlock.LOCKED, repeaterBlock.isLocked(context.getWorld(), context.getPos(), state)); + } + if (state.canSurvive(context.getWorld(), context.getPos())) { return state; } else {