Skip to content

Commit 9625f79

Browse files
committed
Tweak sortInventory logic
- Make colored block sort like creative tab Signed-off-by: Hendrix-Shen <[email protected]>
1 parent 1219502 commit 9625f79

File tree

12 files changed

+406
-83
lines changed

12 files changed

+406
-83
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.plusls.ommc.api.sortInventory;
2+
3+
import net.minecraft.world.item.DyeColor;
4+
5+
public interface IDyeBlock {
6+
DyeColor ommc$getColor();
7+
}

src/main/java/com/plusls/ommc/feature/sortInventory/ShulkerBoxItemUtil.java

+30-18
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,60 @@
66
import net.minecraft.world.item.BlockItem;
77
import net.minecraft.world.item.ItemStack;
88
import net.minecraft.world.level.block.ShulkerBoxBlock;
9+
import org.jetbrains.annotations.NotNull;
910
import org.jetbrains.annotations.Nullable;
11+
import top.hendrixshen.magiclib.compat.minecraft.api.nbt.TagCompatApi;
1012

1113
public class ShulkerBoxItemUtil {
1214
public static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;
1315

1416
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)) {
2618
return false;
2719
}
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;
2835
}
2936

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;
3240
}
3341

34-
public static int cmpShulkerBox(@Nullable CompoundTag a, @Nullable CompoundTag b) {
42+
public static int compareShulkerBox(@Nullable CompoundTag a, @Nullable CompoundTag b) {
3543
int aSize = 0, bSize = 0;
44+
3645
if (a != null) {
3746
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);
4050
aSize = tagList.size();
4151
}
4252
}
4353

4454
if (b != null) {
4555
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);
4859
bSize = tagList.size();
4960
}
5061
}
62+
5163
return aSize - bSize;
5264
}
5365

0 commit comments

Comments
 (0)