From 878ee153ef520d203b848cc484e2c0e3a09065d8 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Wed, 18 Jun 2025 20:03:37 +0800 Subject: [PATCH] fix: fix up Shulker box (#11) (#12) --- .../features/0010-Better-ShulkerBox.patch | 61 +++++++++++++------ .../0014-Old-replaceable-by-mushrooms.patch | 22 +++++++ .../bm/lophine/utils/ShulkerBoxesUtil.java | 36 +++-------- 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/lophine-server/minecraft-patches/features/0010-Better-ShulkerBox.patch b/lophine-server/minecraft-patches/features/0010-Better-ShulkerBox.patch index d215e85..67600b8 100644 --- a/lophine-server/minecraft-patches/features/0010-Better-ShulkerBox.patch +++ b/lophine-server/minecraft-patches/features/0010-Better-ShulkerBox.patch @@ -18,25 +18,33 @@ index a4eeb75eeb1cd69c60cd1c273f23f9744837148f..5596214edb14d30c9ed5af4ffdcdd204 @Override diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java -index 9020f7c83e5bd19e9a9d3748d200ce5772a9cefa..8138eb8ce2184ade08b4244dbd150ec264387f7a 100644 +index 9020f7c83e5bd19e9a9d3748d200ce5772a9cefa..5bd913911075c0d93f4434e88c9cf7f3ac7248fc 100644 --- a/net/minecraft/world/entity/player/Inventory.java +++ b/net/minecraft/world/entity/player/Inventory.java -@@ -470,6 +470,15 @@ public class Inventory implements Container, Nameable { - if (equipmentSlot != null) { - this.equipment.set(equipmentSlot, stack); - } +@@ -299,6 +299,11 @@ public class Inventory implements Container, Nameable { + + int i = this.getMaxStackLeaves(item) - item.getCount(); + int min = Math.min(count, i); + // Lophine start - better shulker box + if (fun.bm.lophine.config.modules.misc.ContainerExpansionConfig.betterShulker) { -+ boolean isMainHand = index == selected; -+ boolean isOffHand = index == 40; -+ if (isMainHand || isOffHand) { -+ fun.bm.lophine.utils.ShulkerBoxesUtil.inventoryCallBack(isMainHand, this.player); -+ } ++ fun.bm.lophine.utils.ShulkerBoxesUtil.inventoryCallBack(player, slot); + } + // Lophine end - better shulker box - } - - public ListTag save(ListTag listTag) { + if (min == 0) { + return count; + } else { +@@ -351,6 +356,11 @@ public class Inventory implements Container, Nameable { + if (slot >= 0) { + this.items.set(slot, stack.copyAndClear()); + this.items.get(slot).setPopTime(5); ++ // Lophine start - better shulker box ++ if (fun.bm.lophine.config.modules.misc.ContainerExpansionConfig.betterShulker) { ++ fun.bm.lophine.utils.ShulkerBoxesUtil.inventoryCallBack(player, slot); ++ } ++ // Lophine end - better shulker box + return true; + } else if (this.player.hasInfiniteMaterials()) { + stack.setCount(0); diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java index 1f7a97b0a52461108fe5a17d2ecc224b1a9f26a1..86854467df17cc72e48360a0f19a4bbe4aaba3e8 100644 --- a/net/minecraft/world/entity/player/Player.java @@ -55,6 +63,22 @@ index 1f7a97b0a52461108fe5a17d2ecc224b1a9f26a1..86854467df17cc72e48360a0f19a4bbe } protected void doCloseContainer() { +diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java +index 45ff5b9a50bdec611f7c1aa4cb77fb0b13b6910c..606025e0e4bfbcc996ce5a54ccf74c74430531a1 100644 +--- a/net/minecraft/world/inventory/AbstractContainerMenu.java ++++ b/net/minecraft/world/inventory/AbstractContainerMenu.java +@@ -658,6 +658,11 @@ public abstract class AbstractContainerMenu { + } + } + } ++ // Lophine start - better shulker box ++ if (fun.bm.lophine.config.modules.misc.ContainerExpansionConfig.betterShulker) { ++ fun.bm.lophine.utils.ShulkerBoxesUtil.inventoryCallBack(player, slotId - 54); ++ } ++ // Lophine end - better shulker box + } + + private boolean tryItemClickBehaviourOverride(Player player, ClickAction action, Slot slot, ItemStack clickedItem, ItemStack carriedItem) { diff --git a/net/minecraft/world/inventory/ShulkerBoxMenu.java b/net/minecraft/world/inventory/ShulkerBoxMenu.java index 903025c659e6a9423224fe65973696405c69ec6a..eb20f83d5aa2c06f60c3941e8a54434737c017c4 100644 --- a/net/minecraft/world/inventory/ShulkerBoxMenu.java @@ -100,22 +124,21 @@ index ecf794f94177fc7b6df483516d920719fbc6fa43..4fda59a4c17009a0009f3d3c13258f4f throw new IllegalArgumentException("Got " + items.size() + " items, but maximum is 256"); } else { diff --git a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java -index 87ebdb6deb66662a38b3eec0dae27eaf859ecabb..ecf15ffc37e65a469bc33406559bfbd122fe810c 100644 +index 87ebdb6deb66662a38b3eec0dae27eaf859ecabb..a36080d522841c4d9b186b475aa6667d1942c0eb 100644 --- a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java +++ b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java -@@ -46,6 +46,11 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl +@@ -46,6 +46,10 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl private ShulkerBoxBlockEntity.AnimationStatus animationStatus = ShulkerBoxBlockEntity.AnimationStatus.CLOSED; private float progress; private float progressOld; + // Lophine start - better shulker box + public boolean haveRealBlock = true; -+ public net.minecraft.world.InteractionHand shulkerHand; -+ public ItemStack finalItem; ++ public int slot; + // Lophine end - better shulker box @Nullable private final DyeColor color; -@@ -236,6 +241,15 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl +@@ -236,6 +240,15 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl return Component.translatable("container.shulkerBox"); } @@ -131,7 +154,7 @@ index 87ebdb6deb66662a38b3eec0dae27eaf859ecabb..ecf15ffc37e65a469bc33406559bfbd1 @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { super.loadAdditional(tag, registries); -@@ -258,12 +272,12 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl +@@ -258,12 +271,12 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl } @Override diff --git a/lophine-server/minecraft-patches/features/0014-Old-replaceable-by-mushrooms.patch b/lophine-server/minecraft-patches/features/0014-Old-replaceable-by-mushrooms.patch index ca0d9fe..c7e4d08 100644 --- a/lophine-server/minecraft-patches/features/0014-Old-replaceable-by-mushrooms.patch +++ b/lophine-server/minecraft-patches/features/0014-Old-replaceable-by-mushrooms.patch @@ -4,6 +4,28 @@ Date: Wed, 18 Jun 2025 14:24:54 +0800 Subject: [PATCH] Old replaceable by mushrooms +diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java +index ba1ccd6eab77e27a38d22c12dba0797d65cc4c4e..373f91df79fc7a7bd6fd137bf53b8a55dd745e31 100644 +--- a/net/minecraft/world/level/Level.java ++++ b/net/minecraft/world/level/Level.java +@@ -11,6 +11,8 @@ import java.util.function.Consumer; + import java.util.function.Predicate; + import java.util.stream.Collectors; + import javax.annotation.Nullable; ++ ++import fun.bm.lophine.config.modules.misc.OldFeatureConfig; + import net.minecraft.CrashReport; + import net.minecraft.CrashReportCategory; + import net.minecraft.ReportedException; +@@ -1111,7 +1113,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup, AutoCl + if (worldData.captureTreeGeneration) { // Folia - region threading + // Paper start - Protect Bedrock and End Portal/Frames from being destroyed + BlockState type = getBlockState(pos); +- if (!type.isDestroyable()) return false; ++ if (!type.isDestroyable() && !(OldFeatureConfig.oldReplaceableByMushrooms && flags == 3)) return false; + // Paper end - Protect Bedrock and End Portal/Frames from being destroyed + CraftBlockState blockstate = worldData.capturedBlockStates.get(pos); // Folia - region threading + if (blockstate == null) { diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java index 834e27ef2f7b342b074ff9e1e390e02f3ca1c399..f5765e3bbf9e735d6f959e1bf6ee1846ee11b4e9 100644 --- a/net/minecraft/world/level/block/state/BlockBehaviour.java diff --git a/lophine-server/src/main/java/fun/bm/lophine/utils/ShulkerBoxesUtil.java b/lophine-server/src/main/java/fun/bm/lophine/utils/ShulkerBoxesUtil.java index 20e9524..95bbdf1 100644 --- a/lophine-server/src/main/java/fun/bm/lophine/utils/ShulkerBoxesUtil.java +++ b/lophine-server/src/main/java/fun/bm/lophine/utils/ShulkerBoxesUtil.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.stats.Stats; import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.SlotAccess; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; @@ -17,7 +18,6 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; import org.jetbrains.annotations.NotNull; import java.util.HashMap; -import java.util.Objects; import java.util.Optional; public class ShulkerBoxesUtil { @@ -117,8 +117,7 @@ public class ShulkerBoxesUtil { shulkerBoxEntity.setItems(items); shulkerBoxEntity.haveRealBlock = false; - shulkerBoxEntity.shulkerHand = hand; - shulkerBoxEntity.finalItem = itemInHand; + shulkerBoxEntity.slot = hand == InteractionHand.MAIN_HAND ? player.getInventory().getSelectedSlot() : 40; shulkerBoxEntity.setLevel(player.level()); shulkerMap.put(player, shulkerBoxEntity); @@ -132,41 +131,24 @@ public class ShulkerBoxesUtil { public static void shulkerBoxEntityCallBack(ShulkerBoxBlockEntity shulkerBoxEntity) { Player player = playerMap.get(shulkerBoxEntity); if (player != null) { - InteractionHand hand = shulkerBoxEntity.shulkerHand; - ItemStack currentItem = player.getItemInHand(hand); + SlotAccess slot = player.getSlot(shulkerBoxEntity.slot); + ItemStack currentItem = slot.get(); ItemStack copy = currentItem.copy(); copy.set(DataComponents.CONTAINER, ItemContainerContents.fromItems(shulkerBoxEntity.getItems())); - player.setItemInHand(hand, copy); - - shulkerBoxEntity.finalItem = copy; + slot.set(copy); } } - public static void inventoryCallBack(boolean isMainHand, Player player) { + public static void inventoryCallBack(Player player, int slotId) { ShulkerBoxBlockEntity entity = shulkerMap.get(player); - if (entity != null && isMainHand == Objects.equals(entity.shulkerHand, InteractionHand.MAIN_HAND)) { - closeScreen(entity, player); + if (entity != null) { + if ((slotId == entity.slot) && player instanceof ServerPlayer serverPlayer) + serverPlayer.closeContainer(); } } - public static void closeScreen(ShulkerBoxBlockEntity entity, Player player) { - if (player instanceof ServerPlayer serverPlayer) { - ItemStack stack1 = entity.finalItem; - ItemStack stack2 = player.containerMenu.getCarried(); - ItemStack stack = stack2.isEmpty() ? stack1 : stack2; - if (!stack.isEmpty()) { - if (!player.isAlive() || serverPlayer.hasDisconnected()) { - player.drop(stack, false); - } else { - player.getInventory().placeItemBackInInventory(stack); - } - } - } - player.closeContainer(); - } - public static void clearMap(Player p) { ShulkerBoxBlockEntity e = shulkerMap.get(p); if (e != null) playerMap.remove(e);