From ac61d249cce3b93a06b4e67f6ce2e3c1729ba933 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Mon, 16 Sep 2024 17:29:10 -0400 Subject: [PATCH] fix blocks having unsafe nbt values --- .../foundation/utility/NBTProcessors.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index f685969c95..eab6099065 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -58,7 +58,7 @@ public static synchronized void addSurvivalProcessor(BlockEntityType type, addProcessor(AllBlockEntityTypes.CREATIVE_CRATE.get(), itemProcessor("Filter")); addProcessor(AllBlockEntityTypes.PLACARD.get(), itemProcessor("Item")); } - + // Triggered by block tag, not BE type private static final UnaryOperator signProcessor = data -> { for (int i = 0; i < 4; ++i) @@ -86,14 +86,22 @@ public static UnaryOperator itemProcessor(String tagKey) { } public static ItemStack withUnsafeNBTDiscarded(ItemStack stack) { - if (stack.getTag() == null) + CompoundTag tag = stack.getTag(); + if (tag == null) return stack; ItemStack copy = stack.copy(); - stack.getTag() - .getAllKeys() + copy.setTag(withUnsafeNBTDiscarded(tag)); + return copy; + } + + public static CompoundTag withUnsafeNBTDiscarded(CompoundTag tag) { + if (tag == null) + return null; + CompoundTag copy = tag.copy(); + tag.getAllKeys() .stream() .filter(NBTProcessors::isUnsafeItemNBTKey) - .forEach(copy::removeTagKey); + .forEach(copy::remove); return copy; } @@ -136,7 +144,7 @@ public static CompoundTag process(BlockState blockState, BlockEntity blockEntity return signProcessor.apply(compound); if (blockEntity.onlyOpCanSetNbt()) return null; - return compound; + return withUnsafeNBTDiscarded(compound); } }