Skip to content

Commit

Permalink
Fix #165 [+] button does not work on items with NBT that is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Feb 11, 2016
1 parent 9426e38 commit 0de3ad0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -4,4 +4,4 @@ curse_project_id=238222

version_major=2
version_minor=25
version_patch=10
version_patch=11
6 changes: 5 additions & 1 deletion src/main/java/mezz/jei/NbtIgnoreList.java
Expand Up @@ -64,7 +64,7 @@ public NBTTagCompound getNbt(@Nullable ItemStack itemStack) {
}

NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null) {
if (nbtTagCompound == null || nbtTagCompound.hasNoTags()) {
return null;
}

Expand All @@ -85,6 +85,10 @@ public NBTTagCompound getNbt(@Nullable ItemStack itemStack) {
for (String ignoredKey : ignoredKeys) {
nbtTagCompoundCopy.removeTag(ignoredKey);
}

if (nbtTagCompoundCopy.hasNoTags()) {
return null;
}
return nbtTagCompoundCopy;
}
}
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/api/INbtIgnoreList.java
Expand Up @@ -23,7 +23,7 @@ public interface INbtIgnoreList {

/**
* Get NBT from an itemStack, minus the NBT that is being ignored.
* Returns null if the itemStack has no NBT.
* Returns null if the itemStack has no NBT or the resulting NBT would be empty.
* @since JEI 2.16.0
*/
@Nullable
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/api/package-info.java
@@ -1,4 +1,4 @@
@API(apiVersion = "3.0.0", owner = "JEI", provides = "JustEnoughItemsAPI")
@API(apiVersion = "3.0.1", owner = "JEI", provides = "JustEnoughItemsAPI")
package mezz.jei.api;

import net.minecraftforge.fml.common.API;
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;

import mezz.jei.Internal;
import mezz.jei.network.IPacketId;
import mezz.jei.network.PacketIdServer;

Expand Down Expand Up @@ -36,7 +35,7 @@ public void writePacketData(PacketBuffer buf) throws IOException {
public void readPacketData(PacketBuffer buf, EntityPlayer player) throws IOException {
itemStack = buf.readItemStackFromBuffer();
ItemStack playerItem = player.inventory.getItemStack();
if (Internal.getStackHelper().isIdentical(itemStack, playerItem)) {
if (ItemStack.areItemStacksEqual(itemStack, playerItem)) {
player.inventory.setItemStack(null);
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/mezz/jei/util/StackHelper.java
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;

Expand All @@ -25,6 +26,7 @@
import net.minecraftforge.oredict.OreDictionary;

import mezz.jei.Internal;
import mezz.jei.api.INbtIgnoreList;
import mezz.jei.api.recipe.IStackHelper;
import mezz.jei.gui.ingredients.IGuiIngredient;

Expand Down Expand Up @@ -74,7 +76,7 @@ public Slot getSlotWithStack(@Nonnull Container container, @Nonnull Iterable<Int
Slot slot = container.getSlot(slotNumber);
if (slot != null) {
ItemStack slotStack = slot.getStack();
if (stackHelper.isIdentical(stack, slotStack)) {
if (stackHelper.isEquivalent(stack, slotStack)) {
return slot;
}
}
Expand Down Expand Up @@ -110,7 +112,7 @@ public boolean containsSameStacks(@Nonnull Iterable<ItemStack> stacks, @Nonnull
return true;
}

/* Returns an ItemStack from "stacks" if it isIdentical to an ItemStack from "contains" */
/* Returns an ItemStack from "stacks" if it isEquivalent to an ItemStack from "contains" */
@Nullable
public ItemStack containsStack(@Nullable Iterable<ItemStack> stacks, @Nullable Iterable<ItemStack> contains) {
if (stacks == null || contains == null) {
Expand All @@ -127,22 +129,25 @@ public ItemStack containsStack(@Nullable Iterable<ItemStack> stacks, @Nullable I
return null;
}

/* Returns an ItemStack from "stacks" if it isIdentical to "contains" */
/* Returns an ItemStack from "stacks" if it isEquivalent to "contains" */
@Nullable
public ItemStack containsStack(@Nullable Iterable<ItemStack> stacks, @Nullable ItemStack contains) {
if (stacks == null || contains == null) {
return null;
}

for (ItemStack stack : stacks) {
if (isIdentical(contains, stack)) {
if (isEquivalent(contains, stack)) {
return stack;
}
}
return null;
}

public boolean isIdentical(@Nullable ItemStack lhs, @Nullable ItemStack rhs) {
/**
* Similar to ItemStack.areItemStacksEqual but ignores NBT on items without subtypes, and uses the INbtIgnoreList
*/
public boolean isEquivalent(@Nullable ItemStack lhs, @Nullable ItemStack rhs) {
if (lhs == rhs) {
return true;
}
Expand All @@ -161,7 +166,14 @@ public boolean isIdentical(@Nullable ItemStack lhs, @Nullable ItemStack rhs) {
}
}

return ItemStack.areItemStackTagsEqual(lhs, rhs);
if (lhs.getHasSubtypes()) {
INbtIgnoreList nbtIgnoreList = Internal.getHelpers().getNbtIgnoreList();
NBTTagCompound lhsNbt = nbtIgnoreList.getNbt(lhs);
NBTTagCompound rhsNbt = nbtIgnoreList.getNbt(rhs);
return Objects.equals(lhsNbt, rhsNbt);
} else {
return true;
}
}

@Override
Expand Down

0 comments on commit 0de3ad0

Please sign in to comment.