Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsafe nbt KVs from blocks aswell #6953

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompoundTag> signProcessor = data -> {
for (int i = 0; i < 4; ++i)
Expand Down Expand Up @@ -86,14 +86,22 @@ public static UnaryOperator<CompoundTag> 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;
}

Expand Down Expand Up @@ -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);
}

}