Reimplement ItemStack Obfuscation (#11817)
Reimplementation of the itemstack obfuscation config that leverages the component patch map codec to drop unwanted components on items or replaces them with sanitized versions. Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
@@ -21,14 +21,15 @@
|
||||
+ if (value.isEmpty() || value.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
|
||||
buffer.writeVarInt(0);
|
||||
} else {
|
||||
buffer.writeVarInt(value.getCount());
|
||||
- buffer.writeVarInt(value.getCount());
|
||||
+ buffer.writeVarInt(io.papermc.paper.util.ItemComponentSanitizer.sanitizeCount(io.papermc.paper.util.ItemObfuscationSession.currentSession(), value, value.getCount())); // Paper - potentially sanitize count
|
||||
ITEM_STREAM_CODEC.encode(buffer, value.getItemHolder());
|
||||
+ // Spigot start - filter
|
||||
+ // value = value.copy();
|
||||
+ // CraftItemStack.setItemMeta(value, CraftItemStack.getItemMeta(value)); // Paper - This is no longer with raw NBT being handled in metadata
|
||||
+ // Paper start - adventure; conditionally render translatable components
|
||||
+ boolean prev = net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.get();
|
||||
+ try {
|
||||
+ try (final io.papermc.paper.util.SafeAutoClosable ignored = io.papermc.paper.util.ItemObfuscationSession.withContext(c -> c.itemStack(value))) { // pass the itemstack as context to the obfuscation session
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true);
|
||||
DataComponentPatch.STREAM_CODEC.encode(buffer, value.components.asPatch());
|
||||
+ } finally {
|
||||
|
||||
Reference in New Issue
Block a user