From 2a4bfb936f8802673b1df725f8771e24288eeeb4 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 21 Apr 2024 22:48:56 +0200 Subject: [PATCH 1/2] Add UserConnection param to item rewriter methods --- .../BackwardsStructuredItemRewriter.java | 5 +- .../api/rewriters/EntityRewriterBase.java | 8 +-- .../api/rewriters/ItemRewriter.java | 13 ++--- .../api/rewriters/ItemRewriterBase.java | 5 +- .../rewriters/LegacyBlockItemRewriter.java | 9 ++-- .../packets/BlockItemPackets1_11.java | 22 ++++---- .../Protocol1_11_1To1_12.java | 2 +- .../data/ShoulderTracker.java | 6 ++- .../packets/BlockItemPackets1_12.java | 19 +++---- .../packets/ItemPackets1_11_1.java | 17 ++++--- .../data/ParticleMapping.java | 2 +- .../packets/BlockItemPackets1_13.java | 18 +++---- .../packets/EntityPackets1_13.java | 4 +- .../packets/PlayerPacket1_13.java | 8 +-- .../packets/BlockItemPackets1_14.java | 19 +++---- .../packets/EntityPackets1_14.java | 2 +- .../Protocol1_13To1_13_1.java | 4 +- .../packets/EntityPackets1_13_1.java | 4 +- .../packets/InventoryPackets1_13_1.java | 6 +-- .../packets/BlockItemPackets1_15.java | 4 +- .../packets/BlockItemPackets1_16.java | 13 ++--- .../packets/EntityPackets1_16.java | 4 +- .../packets/BlockItemPackets1_16_2.java | 2 +- .../packets/BlockItemPackets1_17.java | 6 +-- .../packets/EntityPackets1_17.java | 6 +-- .../packets/BlockItemPackets1_18.java | 2 +- .../packets/EntityPackets1_18.java | 4 +- .../packets/BlockItemPackets1_19.java | 6 +-- .../packets/EntityPackets1_19.java | 8 +-- .../packets/BlockItemPackets1_19_3.java | 12 ++--- .../packets/BlockItemPackets1_19_4.java | 2 +- .../packets/BlockItemPackets1_20.java | 11 ++-- .../Protocol1_20_2To1_20_3.java | 2 +- .../BlockItemPacketRewriter1_20_3.java | 2 +- .../rewriter/EntityPacketRewriter1_20_3.java | 4 +- .../BlockItemPacketRewriter1_20_5.java | 17 ++++--- .../rewriter/EntityPacketRewriter1_20_5.java | 2 +- .../BlockItemPacketRewriter1_20_2.java | 47 +++++++++--------- .../packets/BlockItemPackets1_10.java | 8 +-- .../viabackwards/data/mappings-1.13to1.12.nbt | Bin 85217 -> 85217 bytes 40 files changed, 175 insertions(+), 160 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index c388e88a..bc30e58a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -20,6 +20,7 @@ package com.viaversion.viabackwards.api.rewriters; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.MappedItem; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; @@ -45,7 +46,7 @@ public class BackwardsStructuredItemRewriter { MetaType type = meta.metaType(); if (type == itemType) { - protocol.getItemRewriter().handleItemToClient(meta.value()); + protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()); } else if (type == blockStateType) { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); @@ -201,7 +201,7 @@ public abstract class EntityRewriterBase { MetaType type = meta.metaType(); if (type == itemType) { - protocol.getItemRewriter().handleItemToClient(meta.value()); + protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()); } else if (type == blockStateType) { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); @@ -230,7 +230,7 @@ public abstract class EntityRewriterBase handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); + handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); // Handle Llama handler(wrapper -> { @@ -90,7 +90,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter { Item[] stacks = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); for (int i = 0; i < stacks.length; i++) - stacks[i] = handleItemToClient(stacks[i]); + stacks[i] = handleItemToClient(wrapper.user(), stacks[i]); if (isLlama(wrapper.user())) { Optional horse = getChestedHorse(wrapper.user()); @@ -123,12 +123,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter handleItemToServer(wrapper.get(Type.ITEM1_8, 0))); + handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); // Llama slot handler(wrapper -> { @@ -267,7 +267,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter { if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient((Item) meta.getValue())); + meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); }); } @@ -288,9 +288,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter= 0 && action <= 2) { JsonElement component = wrapper.read(Type.COMPONENT); - wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(component.toString())); + wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, component.toString())); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java index 492a4082..34ac5d18 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/data/ShoulderTracker.java @@ -40,7 +40,11 @@ public class ShoulderTracker extends StoredObject { public void update() { PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12.CHAT_MESSAGE, null, getUser()); - wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(generateString())); + try { + wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, generateString())); + } catch (final Exception e) { + throw new RuntimeException(e); + } wrapper.write(Type.BYTE, (byte) 2); try { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java index 345125b6..52be02b3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java @@ -21,6 +21,7 @@ package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter; import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; @@ -99,12 +100,12 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter { if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient((Item) meta.getValue())); + meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); }); protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_STATUS, new PacketHandlers() { @@ -198,9 +199,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter { if (meta.metaType().type().equals(Type.ITEM1_8)) { // Is Item - meta.setValue(handleItemToClient((Item) meta.getValue())); + meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); } }); } @@ -88,18 +89,18 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter36) minecraft:item -> iconcrack diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index b69d9931..b4252244 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -260,7 +260,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit handler(wrapper -> { final Item[] items = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); for (Item item : items) { - handleItemToClient(item); + handleItemToClient(wrapper.user(), item); } }); } @@ -273,7 +273,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.SHORT); map(Type.ITEM1_13, Type.ITEM1_8); - handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); + handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); } }); @@ -443,7 +443,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); map(Type.ITEM1_13, Type.ITEM1_8); - handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0))); + handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); } }); @@ -471,7 +471,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.SHORT); map(Type.ITEM1_8, Type.ITEM1_13); - handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0))); + handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0))); } }); @@ -485,7 +485,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); map(Type.ITEM1_8, Type.ITEM1_13); - handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0))); + handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0))); } }); } @@ -499,7 +499,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToClient(Item item) { + public Item handleItemToClient(UserConnection connection, Item item) { if (item == null) return null; // Custom mappings/super call moved down @@ -519,7 +519,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit if (rawId == null) { // Look for custom mappings - super.handleItemToClient(item); + super.handleItemToClient(connection, item); // Handle one-way special case if (item.identifier() == -1) { @@ -744,7 +744,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToServer(Item item) { + public Item handleItemToServer(UserConnection connection, Item item) { if (item == null) return null; CompoundTag tag = item.tag(); @@ -812,7 +812,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit // Handle custom mappings int identifier = item.identifier(); item.setIdentifier(rawId); - super.handleItemToServer(item); + super.handleItemToServer(connection, item); // Mapped with original data, we can return here if (item.identifier() != rawId && item.identifier() != -1) return item; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index 2814d62f..a54bfb6f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -291,7 +291,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter { Particle particle = (Particle) meta.getValue(); - ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId()); + ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.id()); int firstArg = 0; int secondArg = 0; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index 25e379a0..0538afb8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -81,16 +81,16 @@ public class PlayerPacket1_13 extends RewriterBase { for (int i = 0; i < size; i++) { //Input Item Item input = wrapper.read(Type.ITEM1_13); - wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(input)); + wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), input)); //Output Item Item output = wrapper.read(Type.ITEM1_13); - wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(output)); + wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), output)); boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item if (secondItem) { //Second Item Item second = wrapper.read(Type.ITEM1_13); - wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(second)); + wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), second)); } wrapper.passthrough(Type.BOOLEAN); //Trade disabled @@ -379,7 +379,7 @@ public class PlayerPacket1_13 extends RewriterBase { case "MC|BEdit": wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK); Item book = wrapper.read(Type.ITEM1_8); - wrapper.write(Type.ITEM1_13, protocol.getItemRewriter().handleItemToServer(book)); + wrapper.write(Type.ITEM1_13, protocol.getItemRewriter().handleItemToServer(wrapper.user(), book)); boolean signing = channel.equals("MC|BSign"); wrapper.write(Type.BOOLEAN, signing); break; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index f234df8c..37ca8f55 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; @@ -69,7 +70,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit @Override protected void registerPackets() { - protocol.registerServerbound(ServerboundPackets1_13.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); + protocol.registerServerbound(ServerboundPackets1_13.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2))); protocol.registerClientbound(ClientboundPackets1_14.OPEN_WINDOW, wrapper -> { int windowId = wrapper.read(Type.VAR_INT); @@ -185,20 +186,20 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit for (int i = 0; i < size; i++) { // Input Item Item input = wrapper.read(Type.ITEM1_13_2); - input = handleItemToClient(input); + input = handleItemToClient(wrapper.user(), input); wrapper.write(Type.ITEM1_13_2, input); // Output Item Item output = wrapper.read(Type.ITEM1_13_2); - output = handleItemToClient(output); + output = handleItemToClient(wrapper.user(), output); wrapper.write(Type.ITEM1_13_2, output); boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item if (secondItem) { // Second Item Item second = wrapper.read(Type.ITEM1_13_2); - second = handleItemToClient(second); + second = handleItemToClient(wrapper.user(), second); wrapper.write(Type.ITEM1_13_2, second); } @@ -228,7 +229,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit map(Type.VAR_INT); // 1 - Slot ID map(Type.ITEM1_13_2); // 2 - Item - handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13_2, 0))); + handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_13_2, 0))); handler(wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); @@ -465,9 +466,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToClient(Item item) { + public Item handleItemToClient(UserConnection connection, Item item) { if (item == null) return null; - super.handleItemToClient(item); + super.handleItemToClient(connection, item); // Lore now uses JSON CompoundTag tag = item.tag(); @@ -491,7 +492,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToServer(Item item) { + public Item handleItemToServer(UserConnection connection, Item item) { if (item == null) return null; // Lore now uses JSON @@ -510,7 +511,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit enchantmentRewriter.handleToServer(item); // Call this last to check for the backup lore above - super.handleItemToServer(item); + super.handleItemToServer(connection, item); return item; } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index ca667da0..56aae7f9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -383,7 +383,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter { - rewriteParticle((Particle) meta.getValue()); + rewriteParticle(event.user(), (Particle) meta.getValue()); }); filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index e1afa44e..550c2588 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -92,7 +92,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { - itemRewriter.handleItemToServer(wrapper.get(Type.ITEM1_13, 0)); + itemRewriter.handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)); wrapper.write(Type.VAR_INT, 0); }); } @@ -181,7 +181,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { if (meta.metaType() == Types1_13.META_TYPES.itemType) { - protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()); + protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()); } else if (meta.metaType() == Types1_13.META_TYPES.blockStateType) { // Convert to new block id int data = (int) meta.getValue(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); } else if (meta.metaType() == Types1_13.META_TYPES.particleType) { - rewriteParticle((Particle) meta.getValue()); + rewriteParticle(event.user(), (Particle) meta.getValue()); } else if (meta.metaType() == Types1_13.META_TYPES.optionalComponentType || meta.metaType() == Types1_13.META_TYPES.componentType) { JsonElement element = meta.value(); protocol.translatableRewriter().processText(element); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java index caccdac5..c425c867 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java @@ -45,16 +45,16 @@ public class InventoryPackets1_13_1 extends ItemRewriter(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES); - protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); + protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2))); registerSetCooldown(ClientboundPackets1_15.COOLDOWN); registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS); @@ -122,7 +122,7 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit int data = wrapper.passthrough(Type.VAR_INT); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); } else if (id == 32) { - Item item = handleItemToClient(wrapper.read(Type.ITEM1_13_2)); + Item item = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2)); wrapper.write(Type.ITEM1_13_2, item); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index fc6831d9..96514d4b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.MapColorRewriter; import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites; import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.BiomeStorage; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; @@ -111,7 +112,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit byte slot; do { slot = wrapper.read(Type.BYTE); - Item item = handleItemToClient(wrapper.read(Type.ITEM1_13_2)); + Item item = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2)); int rawSlot = slot & 0x7F; equipmentData.add(new EquipmentData(rawSlot, item)); } while ((slot & 0xFFFFFF80) != 0); @@ -248,7 +249,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW); registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION); - protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); + protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2))); } private void handleBlockEntity(CompoundTag tag) { @@ -290,10 +291,10 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToClient(Item item) { + public Item handleItemToClient(UserConnection connection, Item item) { if (item == null) return null; - super.handleItemToClient(item); + super.handleItemToClient(connection, item); CompoundTag tag = item.tag(); if (item.identifier() == 771 && tag != null) { @@ -324,11 +325,11 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit } @Override - public Item handleItemToServer(Item item) { + public Item handleItemToServer(UserConnection connection, Item item) { if (item == null) return null; int identifier = item.identifier(); - super.handleItemToServer(item); + super.handleItemToServer(connection, item); CompoundTag tag = item.tag(); if (identifier == 771 && tag != null) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index d3e3149e..aab2218e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -244,11 +244,11 @@ public class EntityPackets1_16 extends EntityRewriter handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); + protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2))); } private void handleBlockEntity(CompoundTag tag) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java index 80a20948..30a15d7c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java @@ -77,7 +77,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); + protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2))); // TODO Since the carried and modified items are typically set incorrectly, the server sends unnecessary // set slot packets after practically every window click, since it thinks the client and server @@ -95,7 +95,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter after a click and send the changed slots here wrapper.write(Type.VAR_INT, 0); // Empty array of slot+item @@ -152,7 +152,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index f5c76ea9..2945038c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -153,17 +153,17 @@ public final class EntityPackets1_17 extends EntityRewriter data = particle.getArguments().remove(0); int blockState = (int) data.getValue(); if (blockState == 7786) { // Light block @@ -111,7 +111,7 @@ public final class EntityPackets1_18 extends EntityRewriter= 8) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java index 6b46c46a..ca6e4679 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java @@ -79,10 +79,10 @@ public final class BlockItemPackets1_19_3 extends ItemRewriterremoveArgument(0).getValue(); if (positionSourceType == 0) { @@ -117,7 +117,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter= 15) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index 8dbc653b..e227d5c5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; @@ -77,7 +78,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem // Move it to the beginning, move out arguments here final Particle particle = wrapper.read(Types1_20_5.PARTICLE); - rewriteParticle(particle); + rewriteParticle(wrapper.user(), particle); wrapper.set(Type.VAR_INT, 0, particle.id()); for (final Particle.ParticleData argument : particle.getArguments()) { argument.write(wrapper); @@ -119,11 +120,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem wrapper.passthrough(Type.VAR_INT); // Container id final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { - final Item input = handleItemToClient(wrapper.read(Types1_20_5.ITEM)); + final Item input = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM)); wrapper.write(Type.ITEM1_20_2, input); - final Item output = handleItemToClient(wrapper.read(Types1_20_5.ITEM)); + final Item output = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM)); wrapper.write(Type.ITEM1_20_2, output); - final Item secondItem = handleItemToClient(wrapper.read(Types1_20_5.ITEM)); + final Item secondItem = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM)); wrapper.write(Type.ITEM1_20_2, secondItem); wrapper.passthrough(Type.BOOLEAN); // Trade disabled @@ -154,19 +155,19 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem } @Override - public @Nullable Item handleItemToClient(@Nullable final Item item) { + public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) { if (item == null) return null; - super.handleItemToClient(item); + super.handleItemToClient(connection, item); return vvProtocol.getItemRewriter().toOldItem(item); } @Override - public @Nullable Item handleItemToServer(@Nullable final Item item) { + public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) { if (item == null) return null; // Convert to structured item first final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(item); - return super.handleItemToServer(structuredItem); + return super.handleItemToServer(connection, structuredItem); } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java index 5a05bdde..fdd6bba0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java @@ -69,7 +69,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { final Item[] items = wrapper.read(Type.ITEM1_20_2_ARRAY); for (final Item item : items) { - handleItemToClient(item); + handleItemToClient(wrapper.user(), item); } wrapper.write(Type.ITEM1_13_2_ARRAY, items); - wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Carried item + wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Carried item }); } }); @@ -163,7 +164,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2)))); + handler(wrapper -> wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)))); } }); protocol.registerClientbound(ClientboundPackets1_20_2.ADVANCEMENTS, wrapper -> { @@ -181,7 +182,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)))); // 1 - Clicked Item + handler(wrapper -> wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)))); // 1 - Clicked Item } }); protocol.registerClientbound(ClientboundPackets1_20_2.SPAWN_PARTICLE, new PacketHandlers() { @@ -280,7 +281,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient((Item) meta.getValue())); + meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); }); // Particle diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.13to1.12.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.13to1.12.nbt index 6b5d115664e930551e5e96d9c50671276811214e..e246587af9b4bbb897bb798360ac6b55fccc0b00 100644 GIT binary patch delta 51 zcmaDjll9?DRzWTX24)8KvecsD%=|nC1_s9M{XC49B)0o_Fiv4<6x=Gv*ub+rQI+wf H5+efug$fRP delta 50 zcmaDjll9?DRzWTX24)8KvecsD%=|nC1_s9Fa@p Date: Sun, 21 Apr 2024 23:37:00 +0200 Subject: [PATCH 2/2] Also to component rewriter methods --- .../api/rewriters/EntityRewriterBase.java | 4 +- .../api/rewriters/ItemRewriter.java | 12 ++-- .../packets/ChatPackets1_12.java | 7 ++- .../packets/EntityPackets1_12.java | 2 +- .../Protocol1_12_2To1_13.java | 8 +-- .../packets/BlockItemPackets1_13.java | 2 +- .../packets/EntityPackets1_13.java | 4 +- .../packets/PlayerPacket1_13.java | 8 +-- .../Protocol1_13To1_13_1.java | 4 +- .../packets/EntityPackets1_13_1.java | 2 +- .../Protocol1_15_2To1_16.java | 6 +- .../chat/TranslatableRewriter1_16.java | 5 +- .../packets/BlockItemPackets1_16.java | 2 +- .../packets/EntityPackets1_16.java | 55 +++++++++---------- .../Protocol1_16_1To1_16_2.java | 2 +- .../Protocol1_18_2To1_19.java | 4 +- .../Protocol1_19_1To1_19_3.java | 4 +- .../packets/BlockItemPackets1_19_4.java | 2 +- .../packets/EntityPackets1_19_4.java | 2 +- .../Protocol1_19_4To1_20.java | 2 +- .../Protocol1_19To1_19_1.java | 4 +- .../Protocol1_20_2To1_20_3.java | 4 +- 22 files changed, 71 insertions(+), 74 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java index 20b7d538..b23e0e47 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java @@ -204,7 +204,7 @@ public abstract class EntityRewriterBase translatableRewriter = protocol.getTranslatableRewriter(); if (translatableRewriter != null) { - translatableRewriter.processText(title); - translatableRewriter.processText(description); + translatableRewriter.processText(wrapper.user(), title); + translatableRewriter.processText(wrapper.user(), description); } final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType())); @@ -195,8 +195,8 @@ public class ItemRewriter translatableRewriter = protocol.getTranslatableRewriter(); if (translatableRewriter != null) { - translatableRewriter.processTag(title); - translatableRewriter.processTag(description); + translatableRewriter.processTag(wrapper.user(), title); + translatableRewriter.processTag(wrapper.user(), description); } final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType())); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java index 513a35fa..1da32b56 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java @@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.rewriter.RewriterBase; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.libs.gson.JsonElement; @@ -31,8 +32,8 @@ public class ChatPackets1_12 extends RewriterBase { public static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter(null, ComponentRewriter.ReadType.JSON) { @Override - public void processText(JsonElement element) { - super.processText(element); + public void processText(UserConnection connection, JsonElement element) { + super.processText(connection, element); if (element == null || !element.isJsonObject()) { return; } @@ -64,7 +65,7 @@ public class ChatPackets1_12 extends RewriterBase { protected void registerPackets() { protocol.registerClientbound(ClientboundPackets1_12.CHAT_MESSAGE, wrapper -> { JsonElement element = wrapper.passthrough(Type.COMPONENT); - COMPONENT_REWRITER.processText(element); + COMPONENT_REWRITER.processText(wrapper.user(), element); }); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java index ddf0fbf4..3f750143 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java @@ -191,7 +191,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter { if (meta.metaType() == MetaType1_12.Chat) { - ChatPackets1_12.COMPONENT_REWRITER.processText((JsonElement) meta.getValue()); + ChatPackets1_12.COMPONENT_REWRITER.processText(event.user(), (JsonElement) meta.getValue()); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index fab7c8ea..be9c54a4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -148,25 +148,25 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { byte mode = wrapper.get(Type.BYTE, 0); if (mode == 0 || mode == 2) { JsonElement value = wrapper.read(Type.COMPONENT); - String legacyValue = protocol.jsonToLegacy(value); + String legacyValue = protocol.jsonToLegacy(wrapper.user(), value); wrapper.write(Type.STRING, ChatUtil.fromLegacy(legacyValue, 'f', 32)); int type = wrapper.read(Type.VAR_INT); wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer"); @@ -219,7 +219,7 @@ public class PlayerPacket1_13 extends RewriterBase { byte action = wrapper.get(Type.BYTE, 0); if (action == 0 || action == 2) { JsonElement displayName = wrapper.read(Type.COMPONENT); - String legacyTextDisplayName = protocol.jsonToLegacy(displayName); + String legacyTextDisplayName = protocol.jsonToLegacy(wrapper.user(), displayName); wrapper.write(Type.STRING, ChatUtil.fromLegacy(legacyTextDisplayName, 'f', 32)); byte flags = wrapper.read(Type.BYTE); @@ -234,11 +234,11 @@ public class PlayerPacket1_13 extends RewriterBase { JsonElement prefixComponent = wrapper.read(Type.COMPONENT); JsonElement suffixComponent = wrapper.read(Type.COMPONENT); - String prefix = protocol.jsonToLegacy(prefixComponent); + String prefix = protocol.jsonToLegacy(wrapper.user(), prefixComponent); if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) { prefix += "ยง" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r"); } - String suffix = protocol.jsonToLegacy(suffixComponent); + String suffix = protocol.jsonToLegacy(wrapper.user(), suffixComponent); wrapper.write(Type.STRING, ChatUtil.fromLegacyPrefix(prefix, 'f', 16)); wrapper.write(Type.STRING, ChatUtil.fromLegacy(suffix, '\0', 16)); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index 550c2588..4ce70194 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -105,7 +105,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { JsonElement title = wrapper.passthrough(Type.COMPONENT); - translatableRewriter.processText(title); + translatableRewriter.processText(wrapper.user(), title); if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) { if (title.isJsonObject() && title.getAsJsonObject().size() == 1 @@ -151,7 +151,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { int action = wrapper.get(Type.VAR_INT, 0); if (action == 0 || action == 3) { - translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)); + translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); if (action == 0) { wrapper.passthrough(Type.FLOAT); wrapper.passthrough(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java index db0657ba..b3907155 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java @@ -142,7 +142,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT))); + handler(wrapper -> translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT))); map(Type.BYTE); read(Type.UUID); // Sender } @@ -94,7 +94,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT))); + handler(wrapper -> translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT))); handler(wrapper -> { int windowType = wrapper.get(Type.VAR_INT, 1); if (windowType == 20) { // Smithing table diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java index f4f0fde5..46ba8d2f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java @@ -19,6 +19,7 @@ package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonPrimitive; @@ -52,8 +53,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter pagesTag = tag.getListTag("pages", StringTag.class); if (pagesTag != null) { for (StringTag page : pagesTag) { - JsonElement jsonElement = protocol.getTranslatableRewriter().processText(page.getValue()); + JsonElement jsonElement = protocol.getTranslatableRewriter().processText(connection, page.getValue()); page.setValue(jsonElement.toString()); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index aab2218e..f3d9285d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -203,36 +203,31 @@ public class EntityPackets1_16 extends EntityRewriter { - int action = packetWrapper.passthrough(Type.VAR_INT); - int playerCount = packetWrapper.passthrough(Type.VAR_INT); - for (int i = 0; i < playerCount; i++) { - packetWrapper.passthrough(Type.UUID); - if (action == 0) { // Add - packetWrapper.passthrough(Type.STRING); - int properties = packetWrapper.passthrough(Type.VAR_INT); - for (int j = 0; j < properties; j++) { - packetWrapper.passthrough(Type.STRING); - packetWrapper.passthrough(Type.STRING); - packetWrapper.passthrough(Type.OPTIONAL_STRING); - } - packetWrapper.passthrough(Type.VAR_INT); - packetWrapper.passthrough(Type.VAR_INT); - // Display Name - protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.OPTIONAL_COMPONENT)); - } else if (action == 1) { // Update Game Mode - packetWrapper.passthrough(Type.VAR_INT); - } else if (action == 2) { // Update Ping - packetWrapper.passthrough(Type.VAR_INT); - } else if (action == 3) { // Update Display Name - // Display name - protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.OPTIONAL_COMPONENT)); - } // 4 = Remove Player + protocol.registerClientbound(ClientboundPackets1_16.PLAYER_INFO, wrapper -> { + int action = wrapper.passthrough(Type.VAR_INT); + int playerCount = wrapper.passthrough(Type.VAR_INT); + for (int i = 0; i < playerCount; i++) { + wrapper.passthrough(Type.UUID); + if (action == 0) { // Add + wrapper.passthrough(Type.STRING); + int properties = wrapper.passthrough(Type.VAR_INT); + for (int j = 0; j < properties; j++) { + wrapper.passthrough(Type.STRING); + wrapper.passthrough(Type.STRING); + wrapper.passthrough(Type.OPTIONAL_STRING); } - }); + wrapper.passthrough(Type.VAR_INT); + wrapper.passthrough(Type.VAR_INT); + // Display Name + protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.passthrough(Type.OPTIONAL_COMPONENT)); + } else if (action == 1) { // Update Game Mode + wrapper.passthrough(Type.VAR_INT); + } else if (action == 2) { // Update Ping + wrapper.passthrough(Type.VAR_INT); + } else if (action == 3) { // Update Display Name + // Display name + protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.passthrough(Type.OPTIONAL_COMPONENT)); + } // 4 = Remove Player } }); } @@ -252,7 +247,7 @@ public class EntityPackets1_16 extends EntityRewriter { JsonElement message = wrapper.passthrough(Type.COMPONENT); - translatableRewriter.processText(message); + translatableRewriter.processText(wrapper.user(), message); byte position = wrapper.passthrough(Type.BYTE); if (position == 2) { // https://bugs.mojang.com/browse/MC-119145 wrapper.clearPacket(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java index 67990a89..2ff5b2a6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java @@ -200,7 +200,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol { final JsonElement content = wrapper.passthrough(Type.COMPONENT); - translatableRewriter.processText(content); + translatableRewriter.processText(wrapper.user(), content); // Screw everything that isn't a system or game info type (which would only happen on funny 1.19.0 servers) final int typeId = wrapper.read(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index f990d838..88118d27 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -309,7 +309,7 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { final JsonElement content = wrapper.read(Type.COMPONENT); - translatableRewriter.processText(content); + translatableRewriter.processText(wrapper.user(), content); final int chatTypeId = wrapper.read(Type.VAR_INT); final JsonElement senderName = wrapper.read(Type.COMPONENT); final JsonElement targetName = wrapper.read(Type.OPTIONAL_COMPONENT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java index f6165271..ba535c92 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java @@ -59,7 +59,7 @@ public final class BlockItemPackets1_19_4 extends ItemRewriter { // TODO Maybe spawn an extra entity to ride the armor stand for blocks and items diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java index f02cf8b4..15c286c2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/Protocol1_19_4To1_20.java @@ -87,7 +87,7 @@ public final class Protocol1_19_4To1_20 extends BackwardsProtocol { wrapper.passthrough(Type.VAR_INT); // Duration wrapper.write(Type.INT, -1); // Killer ID - unused (who knows for how long?) - translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)); + translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java index ef1fb750..ae56fa7b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java @@ -171,14 +171,14 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol { final JsonElement content = wrapper.passthrough(Type.COMPONENT); - translatableRewriter.processText(content); + translatableRewriter.processText(wrapper.user(), content); final boolean overlay = wrapper.read(Type.BOOLEAN); wrapper.write(Type.VAR_INT, overlay ? GAME_INFO_ID : SYSTEM_CHAT_ID); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java index d4b3a455..084c7023 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/Protocol1_20_2To1_20_3.java @@ -370,13 +370,13 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol