From 3b4f7e0f8805cfafeb1ec484550d7dcac5d0bd80 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 14 Jan 2025 18:47:02 +0800 Subject: [PATCH] fix: fix shulker box related bugs --- CHANGELOG.md | 3 ++ ...t.java => ItemStuffStorableComponent.java} | 5 ++- .../item/interfaces/ItemShulkerBoxStack.java | 3 +- .../BlockShulkerBoxBaseComponentImpl.java | 4 +-- .../item/component/ItemBaseComponentImpl.java | 2 +- ...va => ItemStuffStorableComponentImpl.java} | 4 +-- .../item/impl/ItemShulkerBoxStackImpl.java | 4 +-- .../server/item/type/ItemTypeInitializer.java | 36 +++++++++---------- 8 files changed, 32 insertions(+), 29 deletions(-) rename api/src/main/java/org/allaymc/api/item/component/{ItemItemStorableComponent.java => ItemStuffStorableComponent.java} (74%) rename server/src/main/java/org/allaymc/server/item/component/{ItemItemStorableComponentImpl.java => ItemStuffStorableComponentImpl.java} (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 436831ad57..042da16032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ Unless otherwise specified, any version comparison below is the comparison of se - (API) Methods `BlockEntityFurnaceBaseComponent#getStoredXP` and `BlockEntityFurnaceBaseComponent#setStoredXP` now accept `int` instead of `float`. - (API) Renamed `Structure#pickStructure` to `Structure#pick`. +- (API) Renamed `ItemItemStorableComponentImpl` to `ItemStuffStorableComponentImpl`, and now `ItemShulkerBoxStack` + extends `ItemStuffStorableComponent`. - Removed useless class `PackageClassLoaderUtils`, dependency `org.reflections.reflections` is also removed. - Added `-dev` suffix to api version in development build. - Changed `ContainerActionProcessorHolder` to a final class instead of an interface, because this abstraction is @@ -75,6 +77,7 @@ Unless otherwise specified, any version comparison below is the comparison of se - (API) `BlockHangingSignBehavior` now extends `BlockEntityHolderComponent` which was forgotten to be added. +- Fixed the `ClassCastException` when breaking shulker box. - Fixed the bug that interacting with door doesn't have any sound. - Waxing copper-made block using honeycomb won't call `BlockFadeEvent` now. - Fixed the bug that player can still open enchant table even if he is sneaking. diff --git a/api/src/main/java/org/allaymc/api/item/component/ItemItemStorableComponent.java b/api/src/main/java/org/allaymc/api/item/component/ItemStuffStorableComponent.java similarity index 74% rename from api/src/main/java/org/allaymc/api/item/component/ItemItemStorableComponent.java rename to api/src/main/java/org/allaymc/api/item/component/ItemStuffStorableComponent.java index c9833d1a75..bb9289db71 100644 --- a/api/src/main/java/org/allaymc/api/item/component/ItemItemStorableComponent.java +++ b/api/src/main/java/org/allaymc/api/item/component/ItemStuffStorableComponent.java @@ -6,12 +6,11 @@ import java.util.List; /** - * ItemItemStorableComponent is used in item that can store items, - * such as shulker boxes. + * ItemStuffStorableComponent is used in item that can store items, such as shulker boxes. * * @author daoge_cmd */ -public interface ItemItemStorableComponent extends ItemComponent { +public interface ItemStuffStorableComponent extends ItemComponent { /** * Get the stored items. * diff --git a/api/src/main/java/org/allaymc/api/item/interfaces/ItemShulkerBoxStack.java b/api/src/main/java/org/allaymc/api/item/interfaces/ItemShulkerBoxStack.java index 35b5f5e69d..85d8a30e59 100644 --- a/api/src/main/java/org/allaymc/api/item/interfaces/ItemShulkerBoxStack.java +++ b/api/src/main/java/org/allaymc/api/item/interfaces/ItemShulkerBoxStack.java @@ -1,6 +1,7 @@ package org.allaymc.api.item.interfaces; import org.allaymc.api.item.ItemStack; +import org.allaymc.api.item.component.ItemStuffStorableComponent; -public interface ItemShulkerBoxStack extends ItemStack { +public interface ItemShulkerBoxStack extends ItemStack, ItemStuffStorableComponent { } diff --git a/server/src/main/java/org/allaymc/server/block/component/BlockShulkerBoxBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/block/component/BlockShulkerBoxBaseComponentImpl.java index 4493656a56..931f6d088b 100644 --- a/server/src/main/java/org/allaymc/server/block/component/BlockShulkerBoxBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/block/component/BlockShulkerBoxBaseComponentImpl.java @@ -8,7 +8,7 @@ import org.allaymc.api.entity.Entity; import org.allaymc.api.entity.interfaces.EntityPlayer; import org.allaymc.api.item.ItemStack; -import org.allaymc.api.item.component.ItemItemStorableComponent; +import org.allaymc.api.item.component.ItemStuffStorableComponent; import org.allaymc.server.component.annotation.Dependency; import org.cloudburstmc.protocol.bedrock.data.GameType; @@ -41,7 +41,7 @@ protected ItemStack createShulkerBoxDrop(BlockStateWithPos blockState) { var container = blockEntity.getContainer(); var containerItems = container.saveNBT(); var drop = blockState.blockState().toItemStack(); - ((ItemItemStorableComponent) drop).setStoredItems(containerItems); + ((ItemStuffStorableComponent) drop).setStoredItems(containerItems); return drop; } diff --git a/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java index 2f77931dca..81d0fbd2dc 100644 --- a/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java @@ -355,7 +355,7 @@ protected void tryApplyBlockEntityNBT(Dimension dimension, Vector3ic placeBlockP builder.remove("x"); builder.remove("y"); builder.remove("z"); - blockEntity.loadNBT(this.blockEntityNBT); + blockEntity.loadNBT(builder.build()); } protected void tryConsumeItem(EntityPlayer player) { diff --git a/server/src/main/java/org/allaymc/server/item/component/ItemItemStorableComponentImpl.java b/server/src/main/java/org/allaymc/server/item/component/ItemStuffStorableComponentImpl.java similarity index 91% rename from server/src/main/java/org/allaymc/server/item/component/ItemItemStorableComponentImpl.java rename to server/src/main/java/org/allaymc/server/item/component/ItemStuffStorableComponentImpl.java index 433c1e5101..71892b5bb1 100644 --- a/server/src/main/java/org/allaymc/server/item/component/ItemItemStorableComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/item/component/ItemStuffStorableComponentImpl.java @@ -3,7 +3,7 @@ import lombok.Setter; import org.allaymc.api.blockentity.component.BlockEntityContainerHolderComponent; import org.allaymc.api.eventbus.EventHandler; -import org.allaymc.api.item.component.ItemItemStorableComponent; +import org.allaymc.api.item.component.ItemStuffStorableComponent; import org.allaymc.server.item.component.event.CItemLoadExtraTagEvent; import org.allaymc.server.item.component.event.CItemPlacedAsBlockEvent; import org.allaymc.server.item.component.event.CItemSaveExtraTagEvent; @@ -17,7 +17,7 @@ /** * @author daoge_cmd */ -public class ItemItemStorableComponentImpl implements ItemItemStorableComponent { +public class ItemStuffStorableComponentImpl implements ItemStuffStorableComponent { @Setter protected List storedItems = List.of(); diff --git a/server/src/main/java/org/allaymc/server/item/impl/ItemShulkerBoxStackImpl.java b/server/src/main/java/org/allaymc/server/item/impl/ItemShulkerBoxStackImpl.java index 834eeab3e6..42c248e2ba 100644 --- a/server/src/main/java/org/allaymc/server/item/impl/ItemShulkerBoxStackImpl.java +++ b/server/src/main/java/org/allaymc/server/item/impl/ItemShulkerBoxStackImpl.java @@ -2,7 +2,7 @@ import lombok.experimental.Delegate; import org.allaymc.api.component.interfaces.Component; -import org.allaymc.api.item.component.ItemItemStorableComponent; +import org.allaymc.api.item.component.ItemStuffStorableComponent; import org.allaymc.api.item.initinfo.ItemStackInitInfo; import org.allaymc.api.item.interfaces.ItemShulkerBoxStack; import org.allaymc.server.component.interfaces.ComponentProvider; @@ -11,7 +11,7 @@ public class ItemShulkerBoxStackImpl extends ItemStackImpl implements ItemShulkerBoxStack { @Delegate - protected ItemItemStorableComponent itemStorableComponent; + protected ItemStuffStorableComponent stuffStorableComponent; public ItemShulkerBoxStackImpl(ItemStackInitInfo initInfo, List> componentProviders) { super(initInfo, componentProviders); diff --git a/server/src/main/java/org/allaymc/server/item/type/ItemTypeInitializer.java b/server/src/main/java/org/allaymc/server/item/type/ItemTypeInitializer.java index 5f90092057..a5567c47c4 100644 --- a/server/src/main/java/org/allaymc/server/item/type/ItemTypeInitializer.java +++ b/server/src/main/java/org/allaymc/server/item/type/ItemTypeInitializer.java @@ -580,92 +580,92 @@ public static void initShulkerBox() { ItemTypes.BLACK_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.BLACK_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.BLUE_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.BLUE_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.BROWN_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.BROWN_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.CYAN_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.CYAN_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.GRAY_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.GRAY_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.GREEN_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.GREEN_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.LIGHT_BLUE_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.LIGHT_BLUE_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.LIGHT_GRAY_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.LIGHT_GRAY_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.LIME_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.LIME_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.MAGENTA_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.MAGENTA_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.ORANGE_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.ORANGE_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.PINK_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.PINK_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.PURPLE_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.PURPLE_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.RED_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.RED_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.UNDYED_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.UNDYED_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.WHITE_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.WHITE_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); ItemTypes.YELLOW_SHULKER_BOX = AllayItemType .builder(ItemShulkerBoxStackImpl.class) .vanillaItem(ItemId.YELLOW_SHULKER_BOX) - .addComponent(ItemItemStorableComponentImpl::new, ItemItemStorableComponentImpl.class) + .addComponent(ItemStuffStorableComponentImpl::new, ItemStuffStorableComponentImpl.class) .build(); }