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/0057-Container-open-passthrough.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

81 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 21:31:03 +0800
Subject: [PATCH] Container open passthrough
diff --git a/net/minecraft/world/entity/decoration/ItemFrame.java b/net/minecraft/world/entity/decoration/ItemFrame.java
index f9a97000b75db7999b1cbe1f72d680d4d7b803b7..91164be32436c003f2456d4510466779e1b576d8 100644
--- a/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -408,6 +408,20 @@ public class ItemFrame extends HangingEntity {
return InteractionResult.PASS;
}
} else {
+ // Leaves start - itemFrameContainerPassthrough
+ if (org.leavesmc.leaves.LeavesConfig.modify.containerPassthrough && !player.isShiftKeyDown()) {
+ BlockPos pos1 = this.pos.relative(this.direction.getOpposite());
+ if (level().getBlockEntity(pos1) instanceof net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) {
+ BlockState blockState = level().getBlockState(pos1);
+ net.minecraft.world.phys.BlockHitResult hitResult = new net.minecraft.world.phys.BlockHitResult(Vec3.atCenterOf(pos1), this.direction, pos1, false);
+ if (flag1) {
+ return blockState.useItemOn(itemInHand, level(), player, hand, hitResult);
+ } else {
+ return blockState.useWithoutItem(level(), player, hitResult);
+ }
+ }
+ }
+ // Leaves end - itemFrameContainerPassthrough
// Paper start - Add PlayerItemFrameChangeEvent
io.papermc.paper.event.player.PlayerItemFrameChangeEvent event = new io.papermc.paper.event.player.PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), this.getItem().asBukkitCopy(), io.papermc.paper.event.player.PlayerItemFrameChangeEvent.ItemFrameChangeAction.ROTATE);
if (!event.callEvent()) {
diff --git a/net/minecraft/world/level/block/SignBlock.java b/net/minecraft/world/level/block/SignBlock.java
index a06896de4401f184e8c5cc8bad829e6412eaff22..00067809380fb3cff1dd54876c28c7a8d5b0aaee 100644
--- a/net/minecraft/world/level/block/SignBlock.java
+++ b/net/minecraft/world/level/block/SignBlock.java
@@ -105,6 +105,18 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
} else {
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
+ // Leaves start - signContainerPassthrough
+ } else if (org.leavesmc.leaves.LeavesConfig.modify.containerPassthrough) {
+ BlockPos pos1 = pos.relative(hitResult.getDirection().getOpposite());
+ if (this instanceof WallSignBlock || this instanceof WallHangingSignBlock) {
+ pos1 = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getOpposite());
+ }
+ if (level.getBlockEntity(pos1) instanceof net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) {
+ BlockState state1 = level.getBlockState(pos1);
+ return state1.useItemOn(stack, level, player, hand, hitResult.withPosition(pos1));
+ }
+ return InteractionResult.PASS;
+ // Leaves end - signContainerPassthrough
} else {
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
@@ -130,6 +142,25 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
return InteractionResult.SUCCESS_SERVER;
} else if (flag) {
return InteractionResult.SUCCESS_SERVER;
+ // Leaves start - signContainerPassthrough
+ } else if (org.leavesmc.leaves.LeavesConfig.modify.containerPassthrough) {
+ if (player.isShiftKeyDown()) {
+ if (!this.otherPlayerIsEditingSign(player, signBlockEntity) && player.mayBuild() && this.hasEditableText(player, signBlockEntity, isFacingFrontText)) {
+ this.openTextEdit(player, signBlockEntity, isFacingFrontText);
+ return InteractionResult.SUCCESS;
+ }
+ }
+
+ BlockPos pos1 = pos.relative(hitResult.getDirection().getOpposite());
+ if (this instanceof WallSignBlock || this instanceof WallHangingSignBlock) {
+ pos1 = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getOpposite());
+ }
+ if (level.getBlockEntity(pos1) instanceof net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) {
+ BlockState state1 = level.getBlockState(pos1);
+ return state1.useWithoutItem(level, player, hitResult.withPosition(pos1));
+ }
+ return InteractionResult.PASS;
+ // Leaves end - signContainerPassthrough
} else if (!this.otherPlayerIsEditingSign(player, signBlockEntity)
&& player.mayBuild()
&& this.hasEditableText(player, signBlockEntity, isFacingFrontText)) {