9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0029-Alternative-block-placement-Protocol.patch
Lumine1909 f09fbb247d 1.21.5 (#470)
---------

Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>
Co-authored-by: Fortern <blueten.ki@gmail.com>
Co-authored-by: MC_XiaoHei <xor7xiaohei@gmail.com>
Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com>
Co-authored-by: MC_XiaoHei <xiaohei.xor7@outlook.com>
2025-06-05 18:41:51 +08:00

102 lines
5.4 KiB
Diff

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 2fbbbac9f1472354bd507926a85c25f48291edfe..98c94e0957933828be79e6326d782af6aa738dd9 100644
--- a/net/minecraft/world/item/BlockItem.java
+++ b/net/minecraft/world/item/BlockItem.java
@@ -151,6 +151,27 @@ 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
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 f289e37f77e1c9d3b0f6c29da1b99f0d5f156e37..848409f44e766ce2a5b74563bf2fd4a6b5d63d33 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 {
public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) {
}
+ // Leaves start - alternativeBlockPlacement
+ @Nullable
+ public BlockState getRealStateForPlacement(BlockPlaceContext ctx) {
+ BlockState vanillaState = 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();