Match empty tags with null tags (#1159)
This commit is contained in:
parent
2d5fde2862
commit
9931895b6b
|
@ -2,6 +2,7 @@ package io.izzel.arclight.common.mixin.core.world.item;
|
||||||
|
|
||||||
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
|
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
|
||||||
import io.izzel.arclight.common.bridge.core.item.ItemStackBridge;
|
import io.izzel.arclight.common.bridge.core.item.ItemStackBridge;
|
||||||
|
import io.izzel.arclight.i18n.ArclightConfig;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
@ -25,8 +26,10 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Mixin(ItemStack.class)
|
@Mixin(ItemStack.class)
|
||||||
|
@ -98,4 +101,20 @@ public abstract class ItemStackMixin extends CapabilityProvider<ItemStack> imple
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.delegate = ForgeRegistries.ITEMS.getDelegateOrThrow(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ public class CompatSpec {
|
||||||
@Setting("valid-username-regex")
|
@Setting("valid-username-regex")
|
||||||
private String validUsernameRegex;
|
private String validUsernameRegex;
|
||||||
|
|
||||||
|
@Setting("lenient-item-tag-match")
|
||||||
|
private boolean lenientItemTagMatch;
|
||||||
|
|
||||||
public Map<String, MaterialPropertySpec> getMaterials() {
|
public Map<String, MaterialPropertySpec> getMaterials() {
|
||||||
return materials;
|
return materials;
|
||||||
}
|
}
|
||||||
|
@ -64,4 +67,8 @@ public class CompatSpec {
|
||||||
public String getValidUsernameRegex() {
|
public String getValidUsernameRegex() {
|
||||||
return validUsernameRegex;
|
return validUsernameRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLenientItemTagMatch() {
|
||||||
|
return lenientItemTagMatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ compatibility {
|
||||||
]
|
]
|
||||||
forward-permission = true
|
forward-permission = true
|
||||||
valid-username-regex = ""
|
valid-username-regex = ""
|
||||||
|
lenient-item-tag-match = true
|
||||||
}
|
}
|
||||||
async-catcher {
|
async-catcher {
|
||||||
dump = true
|
dump = true
|
||||||
|
|
|
@ -129,5 +129,8 @@ comments {
|
||||||
"Following allows any username to login:"
|
"Following allows any username to login:"
|
||||||
"valid-username-regex = \".+\""
|
"valid-username-regex = \".+\""
|
||||||
]
|
]
|
||||||
|
lenient-item-tag-match.comment = [
|
||||||
|
"Allows items with an empty nbt tag stack on no tag items"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,5 +133,8 @@ comments {
|
||||||
"如果允许任何用户名可以使用"
|
"如果允许任何用户名可以使用"
|
||||||
"valid-username-regex = \".+\""
|
"valid-username-regex = \".+\""
|
||||||
]
|
]
|
||||||
|
lenient-item-tag-match.comment = [
|
||||||
|
"允许空 NBT 标签的物品和没有 NBT 标签的物品堆叠"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user