Merge pull request #6953 from IThundxr/mc1.18/clipboard-fix

Remove unsafe nbt KVs from blocks aswell
This commit is contained in:
simibubi 2024-10-07 16:37:37 +02:00 committed by GitHub
commit 4d466efe80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,14 +86,22 @@ public final class NBTProcessors {
} }
public static ItemStack withUnsafeNBTDiscarded(ItemStack stack) { public static ItemStack withUnsafeNBTDiscarded(ItemStack stack) {
if (stack.getTag() == null) CompoundTag tag = stack.getTag();
if (tag == null)
return stack; return stack;
ItemStack copy = stack.copy(); ItemStack copy = stack.copy();
stack.getTag() copy.setTag(withUnsafeNBTDiscarded(tag));
.getAllKeys() return copy;
}
public static CompoundTag withUnsafeNBTDiscarded(CompoundTag tag) {
if (tag == null)
return null;
CompoundTag copy = tag.copy();
tag.getAllKeys()
.stream() .stream()
.filter(NBTProcessors::isUnsafeItemNBTKey) .filter(NBTProcessors::isUnsafeItemNBTKey)
.forEach(copy::removeTagKey); .forEach(copy::remove);
return copy; return copy;
} }
@ -136,7 +144,7 @@ public final class NBTProcessors {
return signProcessor.apply(compound); return signProcessor.apply(compound);
if (blockEntity.onlyOpCanSetNbt()) if (blockEntity.onlyOpCanSetNbt())
return null; return null;
return compound; return withUnsafeNBTDiscarded(compound);
} }
} }