Skip to content

Commit

Permalink
1.18 change getTag->getNbt
Browse files Browse the repository at this point in the history
areTagsEqual -> areNbtEqual
  • Loading branch information
aria1th authored Dec 17, 2021
1 parent bbfb191 commit 13b17f3
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() : "<no NBT>",
stack.getName().getString(), stack.getNbt() != null ? stack.getNbt().toString() : "<no NBT>",
stack.toString());
}

Expand Down Expand Up @@ -1665,7 +1665,7 @@ private static List<Integer> 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) {
Expand Down
198 changes: 99 additions & 99 deletions src/main/java/fi/dy/masa/itemscroller/util/ItemType.java
Original file line number Diff line number Diff line change
@@ -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<ItemType, List<Integer>> getSlotsPerItem(ItemStack[] stacks)
{
Map<ItemType, List<Integer>> mapSlots = new HashMap<ItemType, List<Integer>>();

for (int i = 0; i < stacks.length; i++)
{
ItemStack stack = stacks[i];

if (InventoryUtils.isStackEmpty(stack) == false)
{
ItemType item = new ItemType(stack);
List<Integer> slots = mapSlots.get(item);

if (slots == null)
{
slots = new ArrayList<Integer>();
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<ItemType, List<Integer>> getSlotsPerItem(ItemStack[] stacks)
{
Map<ItemType, List<Integer>> mapSlots = new HashMap<ItemType, List<Integer>>();

for (int i = 0; i < stacks.length; i++)
{
ItemStack stack = stacks[i];

if (InventoryUtils.isStackEmpty(stack) == false)
{
ItemType item = new ItemType(stack);
List<Integer> slots = mapSlots.get(item);

if (slots == null)
{
slots = new ArrayList<Integer>();
mapSlots.put(item, slots);
}

slots.add(i);
}
}

return mapSlots;
}
}

0 comments on commit 13b17f3

Please sign in to comment.