simplify stackableShulkerBoxes rule

This commit is contained in:
gnembon committed 2024-02-29 11:11:18 +01:00
1 parent 4e57eecf2d
commit a0bd6e22ac
6 files changed
+29 -190

No files matched your search

@@ -1,49 +0,0 @@
package carpet.helpers;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import static net.minecraft.nbt.Tag.TAG_COMPOUND;
import static net.minecraft.nbt.Tag.TAG_LIST;
public class InventoryHelper
{
public static boolean cleanUpShulkerBoxTag(ItemStack stack)
{
boolean changed = false;
CompoundTag tag = stack.getTag();
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
return false;
CompoundTag bet = tag.getCompound("BlockEntityTag");
if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty())
{
bet.remove("Items");
changed = true;
}
if (bet.isEmpty() || (bet.size() == 1 && bet.getString("id").equals("minecraft:shulker_box")))
{
tag.remove("BlockEntityTag");
changed = true;
}
if (tag.isEmpty())
{
stack.setTag(null);
changed = true;
}
return changed;
}
public static boolean shulkerBoxHasItems(ItemStack stack)
{
CompoundTag tag = stack.getTag();
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
return false;
CompoundTag bet = tag.getCompound("BlockEntityTag");
return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty();
}
}