Skip to content

Commit

Permalink
Match empty tags with null tags (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Feb 3, 2024
1 parent 2d5fde2 commit 9931895
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.core.item.ItemStackBridge;
import io.izzel.arclight.i18n.ArclightConfig;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
Expand All @@ -25,8 +26,10 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;
import java.util.function.Consumer;

@Mixin(ItemStack.class)
Expand Down Expand Up @@ -98,4 +101,20 @@ public void setItem(Item item) {
this.item = item;
this.delegate = ForgeRegistries.ITEMS.getDelegateOrThrow(item);
}

@Redirect(method = "isSameItemSameTags", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Objects;equals(Ljava/lang/Object;Ljava/lang/Object;)Z"))
private static boolean arclight$lenientItemMatch(Object a, Object b) {
if (ArclightConfig.spec().getCompat().isLenientItemTagMatch()) {
var tagA = (CompoundTag) a;
var tagB = (CompoundTag) b;
if (tagB != null) {
var tmp = tagA;
tagA = tagB;
tagB = tmp;
}
return tagA == null || (tagA.isEmpty() ? (tagB == null || tagB.isEmpty()) : tagA.equals(tagB));
} else {
return Objects.equals(a, b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class CompatSpec {
@Setting("valid-username-regex")
private String validUsernameRegex;

@Setting("lenient-item-tag-match")
private boolean lenientItemTagMatch;

public Map<String, MaterialPropertySpec> getMaterials() {
return materials;
}
Expand Down Expand Up @@ -64,4 +67,8 @@ public boolean isForwardPermissionReverse() {
public String getValidUsernameRegex() {
return validUsernameRegex;
}

public boolean isLenientItemTagMatch() {
return lenientItemTagMatch;
}
}
1 change: 1 addition & 0 deletions i18n-config/src/main/resources/META-INF/arclight.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ compatibility {
]
forward-permission = true
valid-username-regex = ""
lenient-item-tag-match = true
}
async-catcher {
dump = true
Expand Down
3 changes: 3 additions & 0 deletions i18n-config/src/main/resources/META-INF/i18n/en_us.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,8 @@ comments {
"Following allows any username to login:"
"valid-username-regex = \".+\""
]
lenient-item-tag-match.comment = [
"Allows items with an empty nbt tag stack on no tag items"
]
}
}
3 changes: 3 additions & 0 deletions i18n-config/src/main/resources/META-INF/i18n/zh_cn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,8 @@ comments {
"如果允许任何用户名可以使用"
"valid-username-regex = \".+\""
]
lenient-item-tag-match.comment = [
"允许空 NBT 标签的物品和没有 NBT 标签的物品堆叠"
]
}
}

0 comments on commit 9931895

Please sign in to comment.