From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:51:26 +0800 Subject: [PATCH] Alternative block placement Protocol 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/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java index dceb2b683064bbf4286c3fe71e0fd0c5a644cb07..19649f75889d1c4243519eb8ccb46f4b9abd0f68 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java @@ -148,7 +148,7 @@ public class BlockItem extends Item { @Nullable protected BlockState getPlacementState(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 12c6c8aeec89a0a55633c62fe98f5a3aa75fd476..1f0e7c391d02b18e2c89700025713ec3d759f2ea 100644 --- a/net/minecraft/world/item/StandingAndWallBlockItem.java +++ b/net/minecraft/world/item/StandingAndWallBlockItem.java @@ -27,14 +27,14 @@ public class StandingAndWallBlockItem extends BlockItem { @Nullable @Override protected BlockState getPlacementState(BlockPlaceContext context) { - BlockState stateForPlacement = this.wallBlock.getStateForPlacement(context); + BlockState stateForPlacement = this.wallBlock.getRealStateForPlacement(context); // Leaves - alternativeBlockPlacement BlockState blockState = null; LevelReader level = context.getLevel(); BlockPos clickedPos = context.getClickedPos(); for (Direction direction : context.getNearestLookingDirections()) { if (direction != this.attachmentDirection.getOpposite()) { - BlockState blockState1 = direction == this.attachmentDirection ? this.getBlock().getStateForPlacement(context) : stateForPlacement; + BlockState blockState1 = direction == this.attachmentDirection ? this.getBlock().getRealStateForPlacement(context) : stateForPlacement; // Leaves - alternativeBlockPlacement if (blockState1 != null && this.canPlace(level, blockState1, clickedPos)) { blockState = blockState1; break; diff --git a/net/minecraft/world/level/block/Block.java b/net/minecraft/world/level/block/Block.java index 57574f93763ab98a4bc109f56cfc3af08962a878..c9318bda7ea2cb25939516fb1c3cc90488bb8e6c 100644 --- a/net/minecraft/world/level/block/Block.java +++ b/net/minecraft/world/level/block/Block.java @@ -478,6 +478,33 @@ public class Block extends BlockBehaviour implements ItemLike { public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) { } + // Leaves start - alternativeBlockPlacement + @Nullable + public BlockState getRealStateForPlacement(BlockPlaceContext 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); + if (tryState != null) { + return tryState; + } + } + case CARPET_FIX -> { + BlockState tryState = org.leavesmc.leaves.protocol.CarpetAlternativeBlockPlacement.alternativeBlockPlacementFix(this, ctx); + if (tryState != null) { + return tryState; + } + } + case LITEMATICA -> { + if (vanillaState != null) { + return org.leavesmc.leaves.protocol.LitematicaEasyPlaceProtocol.applyPlacementProtocol(vanillaState, ctx); + } + } + } + return vanillaState; + } + // Leaves end - alternativeBlockPlacement + @Nullable public BlockState getStateForPlacement(BlockPlaceContext context) { return this.defaultBlockState();