Skip to content

Commit f1d7c63

Browse files
authored
Fix ItemStack matcher check (#373)
* fix matcher check * make nbt matchers check item + meta * make copies for other when/with methods
1 parent 6b4fc5a commit f1d7c63

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

src/main/java/com/cleanroommc/groovyscript/compat/vanilla/ItemStackMixinExpansion.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ default ItemStackMixinExpansion exactCopy() {
6666

6767
@Override
6868
default boolean test(ItemStack stack) {
69-
if (!OreDictionary.itemMatches(grs$getItemStack(), stack, false) || (grs$getMatcher() != null && !grs$getMatcher().test(stack))) {
69+
var matcher = grs$getMatcher();
70+
if (matcher != null) {
71+
if (!matcher.test(stack)) return false;
72+
} else if (!OreDictionary.itemMatches(grs$getItemStack(), stack, false)) {
7073
return false;
7174
}
72-
if (grs$getNbtMatcher() != null) {
75+
var nbtMatcher = grs$getNbtMatcher();
76+
if (nbtMatcher != null) {
7377
NBTTagCompound nbt = stack.getTagCompound();
74-
return nbt != null && grs$getNbtMatcher().test(nbt);
78+
return nbt != null && nbtMatcher.test(nbt);
7579
}
7680
return true;
7781
}
@@ -190,26 +194,27 @@ default INbtIngredient withNbtExact(NBTTagCompound nbt) {
190194
}
191195

192196
default INbtIngredient withNbtFilter(Predicate<NBTTagCompound> nbtFilter) {
193-
this.grs$setNbtMatcher(nbtFilter == null ? nbt -> true : nbtFilter);
194-
return this;
197+
ItemStackMixinExpansion itemStackMixin = exactCopy();
198+
itemStackMixin.grs$setNbtMatcher(nbtFilter == null ? nbt -> true : nbtFilter);
199+
return itemStackMixin;
195200
}
196201

197202
default INbtIngredient whenNoNbt() {
198-
setNbt(null);
199-
grs$setMatcher(self -> {
200-
NBTTagCompound nbt = self.getTagCompound();
201-
return nbt == null || nbt.isEmpty();
202-
});
203-
return this;
203+
var itemStackMixin = of(when(stack -> {
204+
NBTTagCompound nbt = stack.getTagCompound();
205+
return OreDictionary.itemMatches(grs$getItemStack(), stack, false) && (nbt == null || nbt.isEmpty());
206+
}));
207+
itemStackMixin.setNbt(null);
208+
return itemStackMixin;
204209
}
205210

206211
default INbtIngredient whenAnyNbt() {
207-
setNbt(new NBTTagCompound());
208-
grs$setMatcher(self -> {
209-
NBTTagCompound nbt = self.getTagCompound();
210-
return nbt != null && !nbt.isEmpty();
211-
});
212-
return this;
212+
var itemStackMixin = of(when(stack -> {
213+
NBTTagCompound nbt = stack.getTagCompound();
214+
return OreDictionary.itemMatches(grs$getItemStack(), stack, false) && nbt != null && !nbt.isEmpty();
215+
}));
216+
itemStackMixin.setNbt(new NBTTagCompound());
217+
return itemStackMixin;
213218
}
214219

215220
default ItemStack withMeta(int meta) {

0 commit comments

Comments
 (0)