From 13b17f3d23e83e3ed3ea3b936c9eccc3a5d916c0 Mon Sep 17 00:00:00 2001 From: AngelBottomless <35677394+aria1th@users.noreply.github.com> Date: Fri, 17 Dec 2021 22:42:32 +0900 Subject: [PATCH] 1.18 change getTag->getNbt areTagsEqual -> areNbtEqual --- .../itemscroller/util/InventoryUtils.java | 4 +- .../dy/masa/itemscroller/util/ItemType.java | 198 +++++++++--------- 2 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 5612a70a2..77ef0829f 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -68,7 +68,7 @@ public static String getStackString(ItemStack stack) { Identifier rl = Registry.ITEM.getId(stack.getItem()); return String.format("[%s - display: %s - NBT: %s] (%s)", rl != null ? rl.toString() : "null", - stack.getName().getString(), stack.getTag() != null ? stack.getTag().toString() : "", + stack.getName().getString(), stack.getNbt() != null ? stack.getNbt().toString() : "", stack.toString()); } @@ -1665,7 +1665,7 @@ private static List getSlotNumbersOfEmptySlotsInPlayerInventory(ScreenH } public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2) { - return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areTagsEqual(stack1, stack2); + return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areNbtEqual(stack1, stack2); } private static boolean areSlotsInSameInventory(Slot slot1, Slot slot2) { diff --git a/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java b/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java index 7b71745ed..2ab951760 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java @@ -1,99 +1,99 @@ -package fi.dy.masa.itemscroller.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.Nonnull; -import net.minecraft.item.ItemStack; - -/** - * Wrapper class for ItemStack, which implements equals() - * for the item, damage and NBT, but not stackSize. - */ -public class ItemType -{ - private final ItemStack stack; - - public ItemType(@Nonnull ItemStack stack) - { - this.stack = stack.copy(); - } - - public ItemStack getStack() - { - return this.stack; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - //result = prime * result + ((stack == null) ? 0 : stack.hashCode()); - result = prime * result + this.stack.getItem().hashCode(); - result = prime * result + (this.stack.getTag() != null ? this.stack.getTag().hashCode() : 0); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - ItemType other = (ItemType) obj; - - if (InventoryUtils.isStackEmpty(this.stack) || InventoryUtils.isStackEmpty(other.stack)) - { - if (InventoryUtils.isStackEmpty(this.stack) != InventoryUtils.isStackEmpty(other.stack)) - return false; - } - else - { - if (this.stack.getItem() != other.stack.getItem()) - { - return false; - } - - return ItemStack.areTagsEqual(this.stack, other.stack); - } - - return true; - } - - /** - * Returns a map that has a list of the indices for each different item in the input list - * @param stacks - * @return - */ - public static Map> getSlotsPerItem(ItemStack[] stacks) - { - Map> mapSlots = new HashMap>(); - - for (int i = 0; i < stacks.length; i++) - { - ItemStack stack = stacks[i]; - - if (InventoryUtils.isStackEmpty(stack) == false) - { - ItemType item = new ItemType(stack); - List slots = mapSlots.get(item); - - if (slots == null) - { - slots = new ArrayList(); - mapSlots.put(item, slots); - } - - slots.add(i); - } - } - - return mapSlots; - } -} +package fi.dy.masa.itemscroller.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import net.minecraft.item.ItemStack; + +/** + * Wrapper class for ItemStack, which implements equals() + * for the item, damage and NBT, but not stackSize. + */ +public class ItemType +{ + private final ItemStack stack; + + public ItemType(@Nonnull ItemStack stack) + { + this.stack = stack.copy(); + } + + public ItemStack getStack() + { + return this.stack; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + //result = prime * result + ((stack == null) ? 0 : stack.hashCode()); + result = prime * result + this.stack.getItem().hashCode(); + result = prime * result + (this.stack.getNbt() != null ? this.stack.getNbt().hashCode() : 0); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + ItemType other = (ItemType) obj; + + if (InventoryUtils.isStackEmpty(this.stack) || InventoryUtils.isStackEmpty(other.stack)) + { + if (InventoryUtils.isStackEmpty(this.stack) != InventoryUtils.isStackEmpty(other.stack)) + return false; + } + else + { + if (this.stack.getItem() != other.stack.getItem()) + { + return false; + } + + return ItemStack.areNbtEqual(this.stack, other.stack); + } + + return true; + } + + /** + * Returns a map that has a list of the indices for each different item in the input list + * @param stacks + * @return + */ + public static Map> getSlotsPerItem(ItemStack[] stacks) + { + Map> mapSlots = new HashMap>(); + + for (int i = 0; i < stacks.length; i++) + { + ItemStack stack = stacks[i]; + + if (InventoryUtils.isStackEmpty(stack) == false) + { + ItemType item = new ItemType(stack); + List slots = mapSlots.get(item); + + if (slots == null) + { + slots = new ArrayList(); + mapSlots.put(item, slots); + } + + slots.add(i); + } + } + + return mapSlots; + } +}