|
6 | 6 | import net.minecraft.world.item.BlockItem;
|
7 | 7 | import net.minecraft.world.item.ItemStack;
|
8 | 8 | import net.minecraft.world.level.block.ShulkerBoxBlock;
|
| 9 | +import org.jetbrains.annotations.NotNull; |
9 | 10 | import org.jetbrains.annotations.Nullable;
|
| 11 | +import top.hendrixshen.magiclib.compat.minecraft.api.nbt.TagCompatApi; |
10 | 12 |
|
11 | 13 | public class ShulkerBoxItemUtil {
|
12 | 14 | public static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;
|
13 | 15 |
|
14 | 16 | public static boolean isEmptyShulkerBoxItem(ItemStack itemStack) {
|
15 |
| - if (isShulkerBoxBlockItem(itemStack)) { |
16 |
| - CompoundTag nbt = itemStack.getTag(); |
17 |
| - if (nbt != null && nbt.contains("BlockEntityTag", 10)) { |
18 |
| - CompoundTag tag = nbt.getCompound("BlockEntityTag"); |
19 |
| - if (tag.contains("Items", 9)) { |
20 |
| - ListTag tagList = tag.getList("Items", 10); |
21 |
| - return tagList.size() <= 0; |
22 |
| - } |
23 |
| - } |
24 |
| - return true; |
25 |
| - } else { |
| 17 | + if (!ShulkerBoxItemUtil.isShulkerBoxBlockItem(itemStack)) { |
26 | 18 | return false;
|
27 | 19 | }
|
| 20 | + |
| 21 | + CompoundTag nbt = itemStack.getTag(); |
| 22 | + |
| 23 | + if (nbt == null || !nbt.contains("BlockEntityTag", TagCompatApi.TAG_COMPOUND)) { |
| 24 | + return true; |
| 25 | + } |
| 26 | + |
| 27 | + CompoundTag tag = nbt.getCompound("BlockEntityTag"); |
| 28 | + |
| 29 | + if (tag.contains("Items", TagCompatApi.TAG_LIST)) { |
| 30 | + ListTag tagList = tag.getList("Items", TagCompatApi.TAG_COMPOUND); |
| 31 | + return tagList.isEmpty(); |
| 32 | + } |
| 33 | + |
| 34 | + return true; |
28 | 35 | }
|
29 | 36 |
|
30 |
| - public static boolean isShulkerBoxBlockItem(ItemStack itemStack) { |
31 |
| - return itemStack.getItem() instanceof BlockItem && ((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock; |
| 37 | + public static boolean isShulkerBoxBlockItem(@NotNull ItemStack itemStack) { |
| 38 | + return itemStack.getItem() instanceof BlockItem && |
| 39 | + ((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock; |
32 | 40 | }
|
33 | 41 |
|
34 |
| - public static int cmpShulkerBox(@Nullable CompoundTag a, @Nullable CompoundTag b) { |
| 42 | + public static int compareShulkerBox(@Nullable CompoundTag a, @Nullable CompoundTag b) { |
35 | 43 | int aSize = 0, bSize = 0;
|
| 44 | + |
36 | 45 | if (a != null) {
|
37 | 46 | CompoundTag tag = a.getCompound("BlockEntityTag");
|
38 |
| - if (tag.contains("Items", 9)) { |
39 |
| - ListTag tagList = tag.getList("Items", 10); |
| 47 | + |
| 48 | + if (tag.contains("Items", TagCompatApi.TAG_LIST)) { |
| 49 | + ListTag tagList = tag.getList("Items", TagCompatApi.TAG_COMPOUND); |
40 | 50 | aSize = tagList.size();
|
41 | 51 | }
|
42 | 52 | }
|
43 | 53 |
|
44 | 54 | if (b != null) {
|
45 | 55 | CompoundTag tag = b.getCompound("BlockEntityTag");
|
46 |
| - if (tag.contains("Items", 9)) { |
47 |
| - ListTag tagList = tag.getList("Items", 10); |
| 56 | + |
| 57 | + if (tag.contains("Items", TagCompatApi.TAG_LIST)) { |
| 58 | + ListTag tagList = tag.getList("Items", TagCompatApi.TAG_COMPOUND); |
48 | 59 | bSize = tagList.size();
|
49 | 60 | }
|
50 | 61 | }
|
| 62 | + |
51 | 63 | return aSize - bSize;
|
52 | 64 | }
|
53 | 65 |
|
|
0 commit comments