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
violetc d5c9306a7f 1.21.4 (#413)
* init 1.21.4, and boom!

* build change, but weight not work

* just work

* Build changes, and delete timings

* Fix API patches (#406)

* Fix API patches

* merge

---------

Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>

* 0006/0129

* 0009/0129

* 0011/0129

* 0018/0129

* 0030/0129

* 0035/0129

* 0043/0129

* 0048/0129

* 0049/0129

* 0057/0129

* 0065/0129

* 0086/0129 (#408)

* 0072/0129

* 0080/0129

* Readd patch infos

* 0086/0129

* Delete applied patches

* 0087/0129

* 0091/0129

* 0097/0129

* 0101/0129

* 102/129

* 0107/0129

* 0112/0129

* 0118/0129

* 0129/0129, 100% patched

* fix some

* server work

* Protocol... (#409)

* Jade v7

* Fix changed part for Jade

* Formatting imports, add Lms Paster protocol

* REI payloads 5/8

* Add REI support, remove unnecessary content in Jade

* Rename

* Make jade better

* Make action work

* fix action jar

* Fix some protocol

* Fix bot action, and entity tickCount

* Fix Warden GameEventListener register on load

* Fix extra Raider drop

* Fix grindstone overstacking

* Update Paper, and some doc

* Merge

* [ci skip] Update Action

---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
2025-02-14 23:55:46 +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 68e50c6ade879d263424f244070677cb81c34c33..e619a872d51bf0be64ff594c916c89a5bbf1d3fc 100644
--- a/net/minecraft/world/item/BlockItem.java
+++ b/net/minecraft/world/item/BlockItem.java
@@ -158,6 +158,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 37f561ae2eca0d118c63f519fabdcfe9cb710826..43e338e75b7ded9f80e4ff2ce1a7dac043c93ea1 100644
--- a/net/minecraft/world/level/block/Block.java
+++ b/net/minecraft/world/level/block/Block.java
@@ -392,6 +392,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();