Skip to content

Commit 525ac24

Browse files
committed
Item codec fixes
1 parent 3f88d97 commit 525ac24

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/net/minecraft/network/protocol/game/ClientboundSetCursorItemPacket.java
2+
+++ b/net/minecraft/network/protocol/game/ClientboundSetCursorItemPacket.java
3+
@@ -8,7 +_,7 @@
4+
5+
public record ClientboundSetCursorItemPacket(ItemStack contents) implements Packet<ClientGamePacketListener> {
6+
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetCursorItemPacket> STREAM_CODEC = StreamCodec.composite(
7+
- ItemStack.OPTIONAL_STREAM_CODEC, ClientboundSetCursorItemPacket::contents, ClientboundSetCursorItemPacket::new
8+
+ ItemStack.OPTIONAL_TRANSLATED_STREAM_CODEC, ClientboundSetCursorItemPacket::contents, ClientboundSetCursorItemPacket::new // Papyrus - Use for obfuscation
9+
);
10+
11+
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/net/minecraft/network/protocol/game/ClientboundSetPlayerInventoryPacket.java
2+
+++ b/net/minecraft/network/protocol/game/ClientboundSetPlayerInventoryPacket.java
3+
@@ -11,7 +_,7 @@
4+
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetPlayerInventoryPacket> STREAM_CODEC = StreamCodec.composite(
5+
ByteBufCodecs.VAR_INT,
6+
ClientboundSetPlayerInventoryPacket::slot,
7+
- ItemStack.OPTIONAL_STREAM_CODEC,
8+
+ ItemStack.OPTIONAL_TRANSLATED_STREAM_CODEC, // Papyrus - Use for obfuscation
9+
ClientboundSetPlayerInventoryPacket::contents,
10+
ClientboundSetPlayerInventoryPacket::new
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/net/minecraft/network/syncher/EntityDataSerializers.java
2+
+++ b/net/minecraft/network/syncher/EntityDataSerializers.java
3+
@@ -63,7 +_,7 @@
4+
// If the codec is called during an obfuscation session, downgrade the context's obf level to OVERSIZED if it isn't already.
5+
// Entity data cannot be fully obfuscated as entities might render out specific values (e.g. count or custom name).
6+
try (final io.papermc.paper.util.SafeAutoClosable ignored = io.papermc.paper.util.sanitizer.ItemObfuscationSession.withContext(c -> c.level(io.papermc.paper.util.sanitizer.ItemObfuscationSession.ObfuscationLevel.OVERSIZED))) {
7+
- ItemStack.OPTIONAL_STREAM_CODEC.encode(buffer, value);
8+
+ ItemStack.OPTIONAL_TRANSLATED_STREAM_CODEC.encode(buffer, value); // Papyrus - Use for obfuscation
9+
}
10+
}
11+
};

papyrus-server/minecraft-patches/sources/net/minecraft/world/item/ItemStack.java.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
+ Item.STREAM_CODEC.encode(buffer, value.getItemHolder());
6868
+ // Paper start - adventure; conditionally render translatable components
6969
+ try (final io.papermc.paper.util.SafeAutoClosable ignored = io.papermc.paper.util.sanitizer.ItemObfuscationSession.withContext(c -> c.itemStack(value))) { // pass the itemstack as context to the obfuscation session
70-
+ codec.encode(buffer, value.components.asPatch());
70+
+ codec.encode(buffer, value.components.asClientFilteredPatch()); // Papyrus - Filter our components
7171
+ }
7272
+ // Paper end - adventure; conditionally render translatable components
7373
+ }

0 commit comments

Comments
 (0)