From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Mon, 3 Feb 2025 13:51:26 +0800 Subject: [PATCH] Leaves: Alternative block placement Protocol Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com> As a part of : Leaves (https://github.com/LeavesMC/Leaves) Licensed under: MIT This patch is Powered by carpet-extra(https://github.com/gnembon/carpet-extra) MasaGadget(https://github.com/plusls/MasaGadget) litematica(https://github.com/maruohon/litematica) diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java index 6b3d1cdfdee2a815807ac32a6fc2f353215a13ab..77b9cd3d14eddc735d9131597916405fde4230ec 100644 --- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -2175,7 +2175,7 @@ public class ServerGamePacketListenerImpl if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.player.level(), pos.getX() >> 4, pos.getZ() >> 4, 8) && this.player.isWithinBlockInteractionRange(pos, 1.0)) { // Folia - do not allow players to interact with blocks outside the current region Vec3 distance = location.subtract(Vec3.atCenterOf(pos)); double limit = 1.0000001; - if (Math.abs(distance.x()) < 1.0000001 && Math.abs(distance.y()) < 1.0000001 && Math.abs(distance.z()) < 1.0000001) { + if (fun.bm.lophine.config.modules.function.protocol.AlternativeBlockPlacementProtocolConfig.needIgnoreDistance() ||Math.abs(distance.x()) < 1.0000001 && Math.abs(distance.y()) < 1.0000001 && Math.abs(distance.z()) < 1.0000001) { // Leaves - disableDistanceCheckForUseItem Direction direction = blockHit.getDirection(); this.player.resetLastActionTime(); int maxY = level.getMaxY(); diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java index b94c4f0a6908a37d8a07dba6ff3ece7193aca1b5..0f4ac8eeb8f5f866b22a81f255f7169754437bfc 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java @@ -140,7 +140,7 @@ public class BlockItem extends Item { } protected @Nullable BlockState getPlacementState(final BlockPlaceContext context) { - BlockState stateForPlacement = this.getBlock().getStateForPlacement(context); + BlockState stateForPlacement = this.getBlock().getRealStateForPlacement(context); // Leaves - alternativeBlockPlacement return stateForPlacement != null && this.canPlace(context, stateForPlacement) ? stateForPlacement : null; } diff --git a/net/minecraft/world/item/StandingAndWallBlockItem.java b/net/minecraft/world/item/StandingAndWallBlockItem.java index bb352c44fa951367907ebe403c59f03f3c21786f..1f17f966882320b3a2ced50b3f73925cd0dfa14c 100644 --- a/net/minecraft/world/item/StandingAndWallBlockItem.java +++ b/net/minecraft/world/item/StandingAndWallBlockItem.java @@ -26,14 +26,14 @@ public class StandingAndWallBlockItem extends BlockItem { @Override protected @Nullable BlockState getPlacementState(final BlockPlaceContext context) { - BlockState wallState = this.wallBlock.getStateForPlacement(context); + BlockState wallState = this.wallBlock.getRealStateForPlacement(context); // Leaves - alternativeBlockPlacement BlockState stateForPlacement = null; LevelReader level = context.getLevel(); BlockPos pos = context.getClickedPos(); for (Direction direction : context.getNearestLookingDirections()) { if (direction != this.attachmentDirection.getOpposite()) { - BlockState possibleState = direction == this.attachmentDirection ? this.getBlock().getStateForPlacement(context) : wallState; + BlockState possibleState = direction == this.attachmentDirection ? this.getBlock().getRealStateForPlacement(context) : wallState; // Leaves - alternativeBlockPlacement if (possibleState != null && this.canPlace(level, possibleState, pos)) { stateForPlacement = possibleState; break; diff --git a/net/minecraft/world/level/block/Block.java b/net/minecraft/world/level/block/Block.java index 1af396a051cc47dccb973ca864cf1ec2e8b756ed..64066a091628ad00d914043ae7ecd8bd29d85e5e 100644 --- a/net/minecraft/world/level/block/Block.java +++ b/net/minecraft/world/level/block/Block.java @@ -517,6 +517,32 @@ public class Block extends BlockBehaviour implements ItemLike { public void stepOn(final Level level, final BlockPos pos, final BlockState onState, final Entity entity) { } + // Leaves start - alternativeBlockPlacement + public @Nullable BlockState getRealStateForPlacement(final BlockPlaceContext context) { + BlockState vanillaState = this.getStateForPlacement(context); + switch (fun.bm.lophine.config.modules.function.protocol.AlternativeBlockPlacementProtocolConfig.alternativeBlockPlacement) { + case fun.bm.lophine.enums.EnumAlternativePlaceType.CARPET -> { + BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacement(this, context); + if (tryState != null) { + return tryState; + } + } + case fun.bm.lophine.enums.EnumAlternativePlaceType.CARPET_FIX -> { + BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacementFix(this, context); + if (tryState != null) { + return tryState; + } + } + case fun.bm.lophine.enums.EnumAlternativePlaceType.LITEMATICA -> { + if (vanillaState != null) { + return org.leavesmc.leaves.protocol.LitematicaEasyPlaceProtocol.applyPlacementProtocol(vanillaState, context); + } + } + } + return vanillaState; + } + // Leaves end - alternativeBlockPlacement + public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) { return this.defaultBlockState(); }