Merge branch 'refs/heads/dev' into preview

# Conflicts:
#	common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java
#	common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java
This commit is contained in:
Nassim Jahnke 2024-04-21 23:39:36 +02:00
commit 0996fc9270
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
51 changed files with 251 additions and 239 deletions

View File

@ -19,6 +19,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedItem;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
@ -46,7 +47,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) {
return null;
}
@ -56,7 +57,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
// Handle name and lore components
StringTag name = display.getStringTag("Name");
if (name != null) {
String newValue = protocol.getTranslatableRewriter().processText(name.getValue()).toString();
String newValue = protocol.getTranslatableRewriter().processText(connection, name.getValue()).toString();
if (!newValue.equals(name.getValue())) {
saveStringTag(display, name, "Name");
}
@ -68,7 +69,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
if (lore != null) {
boolean changed = false;
for (StringTag loreEntry : lore) {
String newValue = protocol.getTranslatableRewriter().processText(loreEntry.getValue()).toString();
String newValue = protocol.getTranslatableRewriter().processText(connection, loreEntry.getValue()).toString();
if (!changed && !newValue.equals(loreEntry.getValue())) {
// Backup original lore before doing any modifications
changed = true;
@ -83,7 +84,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
MappedItem data = protocol.getMappingData() != null ? protocol.getMappingData().getMappedItem(item.identifier()) : null;
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
if (item.tag() == null) {
@ -111,10 +112,10 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
if (item.tag() != null) {
Tag originalId = item.tag().remove(nbtTagName("id"));
if (originalId instanceof IntTag) {
@ -142,11 +143,11 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
final JsonElement description = wrapper.passthrough(Type.COMPONENT);
final TranslatableRewriter<C> 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.read(itemType()));
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
@ -186,11 +187,11 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
final Tag description = wrapper.passthrough(Type.TAG);
final TranslatableRewriter<C> 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.read(itemType()));
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type

View File

@ -18,6 +18,7 @@
package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
@ -46,9 +47,9 @@ public abstract class BackwardsItemRewriterBase<C extends ClientboundPacketType,
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
restoreDisplayTag(item);
return item;

View File

@ -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;
@ -47,7 +48,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
@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;
}
@ -64,7 +65,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
final StructuredData<Tag> customNameData = data.getNonEmpty(StructuredDataKey.CUSTOM_NAME);
if (customNameData != null) {
final Tag originalName = customNameData.value().copy();
protocol.getTranslatableRewriter().processTag(customNameData.value());
protocol.getTranslatableRewriter().processTag(connection, customNameData.value());
if (!customNameData.value().equals(originalName)) {
saveTag(createCustomTag(item), originalName, "Name");
}
@ -73,7 +74,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
if (loreData != null) {
for (final Tag tag : loreData.value()) {
protocol.getTranslatableRewriter().processTag(tag);
protocol.getTranslatableRewriter().processTag(connection, tag);
}
}
}
@ -107,7 +108,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
@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;
}

View File

@ -192,7 +192,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
filter().handler((event, meta) -> {
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));
@ -202,10 +202,10 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type == particleType) {
rewriteParticle(meta.value());
rewriteParticle(event.user(), meta.value());
} else if (type == optionalComponentType || type == componentType) {
JsonElement text = meta.value();
protocol.getTranslatableRewriter().processText(text);
protocol.getTranslatableRewriter().processText(event.user(), text);
}
});
}
@ -222,7 +222,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
if (type == itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value()));
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
} else if (type == blockStateType) {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
@ -232,14 +232,14 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type == particleType) {
rewriteParticle(meta.value());
rewriteParticle(event.user(), meta.value());
} else if (type == particlesType) {
Particle[] particles = meta.value();
for (final Particle particle : particles) {
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
}
} else if (type == optionalComponentType || type == componentType) {
protocol.getTranslatableRewriter().processTag(meta.value());
protocol.getTranslatableRewriter().processTag(event.user(), meta.value());
}
});
}

View File

@ -22,6 +22,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
@ -141,13 +142,13 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
if (item.tag() == null) {
item.setTag(new CompoundTag());
@ -186,9 +187,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
}
@Override
public @Nullable Item handleItemToServer(@Nullable final Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
if (item.tag() != null) {
Tag originalId = item.tag().remove(nbtTagName("id"));
if (originalId instanceof IntTag) {

View File

@ -64,7 +64,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM1_8); // 2 - Slot Value
handler(wrapper -> 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<ClientboundPac
handler(wrapper -> {
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<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
@ -123,12 +123,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -150,7 +150,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.VAR_INT); // 4 - Mode
map(Type.ITEM1_8); // 5 - Clicked Item
handler(wrapper -> 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<ClientboundPac
protocol.getEntityRewriter().filter().handler((event, meta) -> {
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<ClientboundPac
}
@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 (tag == null) return item;
@ -303,9 +303,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
CompoundTag tag = item.tag();
if (tag == null) return item;

View File

@ -58,7 +58,7 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
int action = wrapper.passthrough(Type.VAR_INT);
if (action >= 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()));
}
});

View File

@ -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 {

View File

@ -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<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem)
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
@ -146,7 +147,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
Item item = wrapper.get(Type.ITEM1_8, 0);
handleItemToServer(item);
handleItemToServer(wrapper.user(), item);
});
}
});
@ -179,7 +180,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
protocol.getEntityRewriter().filter().handler((event, meta) -> {
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<ClientboundPac
}
@Override
public @Nullable Item handleItemToClient(Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
if (item.tag() != null) {
CompoundTag backupTag = new CompoundTag();
@ -233,9 +234,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public @Nullable Item handleItemToServer(Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
if (item.tag() != null) {
Tag tag = item.tag().remove("Via|LongArrayTags");

View File

@ -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<Protocol1_11_1To1_12> {
public static final ComponentRewriter<ClientboundPackets1_12> COMPONENT_REWRITER = new ComponentRewriter<ClientboundPackets1_12>(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<Protocol1_11_1To1_12> {
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);
});
}
}

View File

@ -191,7 +191,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
filter().handler((event, meta) -> {
if (meta.metaType() == MetaType1_12.Chat) {
ChatPackets1_12.COMPONENT_REWRITER.processText((JsonElement) meta.getValue());
ChatPackets1_12.COMPONENT_REWRITER.processText(event.user(), (JsonElement) meta.getValue());
}
});

View File

@ -21,6 +21,7 @@ package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
@ -53,12 +54,12 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -76,7 +77,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
// Handle item metadata
protocol.getEntityRewriter().filter().handler((event, meta) -> {
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 LegacyBlockItemRewriter<ClientboundPacket
}
@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);
enchantmentRewriter.handleToClient(item);
return item;
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
enchantmentRewriter.handleToServer(item);
return item;

View File

@ -148,25 +148,25 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
return translatableRewriter;
}
public String jsonToLegacy(String value) {
public String jsonToLegacy(UserConnection connection, String value) {
if (value.isEmpty()) {
return "";
}
try {
return jsonToLegacy(JsonParser.parseString(value));
return jsonToLegacy(connection, JsonParser.parseString(value));
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public String jsonToLegacy(@Nullable JsonElement value) {
public String jsonToLegacy(UserConnection connection, @Nullable JsonElement value) {
if (value == null || value.isJsonNull()) {
return "";
}
translatableToLegacyRewriter.processText(value);
translatableToLegacyRewriter.processText(connection, value);
return ComponentUtil.jsonToLegacy(value);
}
}

View File

@ -117,7 +117,7 @@ public class ParticleMapping {
}
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
Item item = protocol.getItemRewriter().handleItemToClient(null, newItem);
return new int[]{item.identifier(), item.data()};
}
}), // (27->36) minecraft:item -> iconcrack

View File

@ -261,7 +261,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
handler(wrapper -> {
final Item[] items = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0);
for (Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
});
}
@ -274,7 +274,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
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)));
}
});
@ -444,7 +444,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
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)));
}
});
@ -472,7 +472,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
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)));
}
});
@ -486,7 +486,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
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)));
}
});
}
@ -500,7 +500,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
// Custom mappings/super call moved down
@ -520,7 +520,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
if (rawId == null) {
// Look for custom mappings
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
// Handle one-way special case
if (item.identifier() == -1) {
@ -571,7 +571,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
StringTag name = display.getStringTag("Name");
if (name != null) {
display.putString(extraNbtTag + "|Name", name.getValue());
name.setValue(protocol.jsonToLegacy(name.getValue()));
name.setValue(protocol.jsonToLegacy(connection, name.getValue()));
}
}
@ -745,7 +745,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
CompoundTag tag = item.tag();
@ -813,7 +813,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
// 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;

View File

@ -283,15 +283,15 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
int typeId = meta.metaType().typeId();
if (typeId == 4) {
JsonElement element = meta.value();
protocol.translatableRewriter().processText(element);
protocol.translatableRewriter().processText(event.user(), element);
meta.setMetaType(MetaType1_12.Chat);
} else if (typeId == 5) {
// Rewrite optional chat to string
JsonElement element = meta.value();
meta.setTypeAndValue(MetaType1_12.String, protocol.jsonToLegacy(element));
meta.setTypeAndValue(MetaType1_12.String, protocol.jsonToLegacy(event.user(), element));
} else if (typeId == 6) {
Item item = (Item) meta.getValue();
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(item));
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(event.user(), item));
} else if (typeId == 15) {
// Discontinue particles
event.cancel();
@ -333,7 +333,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> {
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;

View File

@ -81,16 +81,16 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
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
@ -201,7 +201,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
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<Protocol1_12_2To1_13> {
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<Protocol1_12_2To1_13> {
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));
@ -379,7 +379,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
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;

View File

@ -24,6 +24,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 BackwardsItemRewriter<ClientboundPacke
@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 BackwardsItemRewriter<ClientboundPacke
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 BackwardsItemRewriter<ClientboundPacke
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 BackwardsItemRewriter<ClientboundPacke
}
@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 BackwardsItemRewriter<ClientboundPacke
}
@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 BackwardsItemRewriter<ClientboundPacke
enchantmentRewriter.handleToServer(item);
// Call this last to check for the backup lore above
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
return item;
}
}

View File

@ -383,7 +383,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
});
filter().type(EntityTypes1_14.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> {
rewriteParticle((Particle) meta.getValue());
rewriteParticle(event.user(), (Particle) meta.getValue());
});
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> {

View File

@ -92,7 +92,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
map(Type.ITEM1_13);
map(Type.BOOLEAN);
handler(wrapper -> {
itemRewriter.handleItemToServer(wrapper.get(Type.ITEM1_13, 0));
itemRewriter.handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0));
wrapper.write(Type.VAR_INT, 0);
});
}
@ -105,7 +105,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
map(Type.STRING); // Window Type
handler(wrapper -> {
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<ClientboundPackets1_
handler(wrapper -> {
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);
@ -178,7 +178,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
Item icon = wrapper.passthrough(Type.ITEM1_13);
itemRewriter.handleItemToClient(icon);
itemRewriter.handleItemToClient(wrapper.user(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)

View File

@ -133,16 +133,16 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
// Rewrite items & blocks
filter().handler((event, meta) -> {
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);
protocol.translatableRewriter().processText(event.user(), element);
}
});

View File

@ -45,16 +45,16 @@ public class InventoryPackets1_13_1 extends ItemRewriter<ClientboundPackets1_13,
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(input);
handleItemToClient(wrapper.user(), input);
//Output Item
Item output = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(output);
handleItemToClient(wrapper.user(), output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(second);
handleItemToClient(wrapper.user(), second);
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled

View File

@ -45,7 +45,7 @@ public class BlockItemPackets1_15 extends BackwardsItemRewriter<ClientboundPacke
new RecipeRewriter<>(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);
@ -123,7 +123,7 @@ public class BlockItemPackets1_15 extends BackwardsItemRewriter<ClientboundPacke
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);
}

View File

@ -76,14 +76,14 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
JsonElement description = object.get("description");
if (description == null) return;
translatableRewriter.processText(description);
translatableRewriter.processText(wrapper.user(), description);
wrapper.set(Type.STRING, 0, object.toString());
});
registerClientbound(ClientboundPackets1_16.CHAT_MESSAGE, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> 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<ClientboundPackets1_
public void register() {
map(Type.VAR_INT); // Window Id
map(Type.VAR_INT); // Window Type
handler(wrapper -> 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

View File

@ -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<ClientboundPa
}
@Override
public void processText(JsonElement value) {
super.processText(value);
public void processText(UserConnection connection, JsonElement value) {
super.processText(connection, value);
if (value == null || !value.isJsonObject()) return;

View File

@ -24,6 +24,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;
@ -112,7 +113,7 @@ public class BlockItemPackets1_16 extends BackwardsItemRewriter<ClientboundPacke
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);
@ -249,7 +250,7 @@ public class BlockItemPackets1_16 extends BackwardsItemRewriter<ClientboundPacke
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) {
@ -291,10 +292,10 @@ public class BlockItemPackets1_16 extends BackwardsItemRewriter<ClientboundPacke
}
@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) {
@ -313,7 +314,7 @@ public class BlockItemPackets1_16 extends BackwardsItemRewriter<ClientboundPacke
ListTag<StringTag> 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());
}
}
@ -325,11 +326,11 @@ public class BlockItemPackets1_16 extends BackwardsItemRewriter<ClientboundPacke
}
@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) {

View File

@ -203,36 +203,31 @@ public class EntityPackets1_16 extends EntityRewriter<ClientboundPackets1_16, Pr
}
});
protocol.registerClientbound(ClientboundPackets1_16.PLAYER_INFO, new PacketHandlers() {
@Override
public void register() {
handler(packetWrapper -> {
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
}
});
}
@ -244,15 +239,15 @@ public class EntityPackets1_16 extends EntityRewriter<ClientboundPackets1_16, Pr
MetaType type = meta.metaType();
if (type == Types1_14.META_TYPES.itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()));
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()));
} else if (type == Types1_14.META_TYPES.blockStateType) {
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
} else if (type == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) meta.getValue());
rewriteParticle(event.user(), (Particle) meta.getValue());
} else if (type == Types1_14.META_TYPES.optionalComponentType) {
JsonElement text = meta.value();
if (text != null) {
protocol.getTranslatableRewriter().processText(text);
protocol.getTranslatableRewriter().processText(event.user(), text);
}
}
});

View File

@ -75,7 +75,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
registerClientbound(ClientboundPackets1_16_2.CHAT_MESSAGE, wrapper -> {
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();

View File

@ -134,7 +134,7 @@ public class BlockItemPackets1_16_2 extends BackwardsItemRewriter<ClientboundPac
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> 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) {

View File

@ -77,7 +77,7 @@ public final class BlockItemPackets1_17 extends BackwardsItemRewriter<Clientboun
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> 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 BackwardsItemRewriter<Clientboun
byte button = wrapper.passthrough(Type.BYTE); // Button
wrapper.read(Type.SHORT); // Action id - removed
int mode = wrapper.passthrough(Type.VAR_INT); // Mode
Item clicked = handleItemToServer(wrapper.read(Type.ITEM1_13_2)); // Clicked item
Item clicked = handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)); // Clicked item
// The 1.17 client would check the entire inventory for changes before -> 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 BackwardsItemRewriter<Clientboun
wrapper.user().get(PlayerLastCursorItem.class).setLastCursorItem(carried);
}
wrapper.write(Type.ITEM1_13_2, handleItemToClient(carried));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), carried));
});
protocol.registerServerbound(ServerboundPackets1_16_2.WINDOW_CONFIRMATION, null, wrapper -> {

View File

@ -152,17 +152,17 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
MetaType type = meta.metaType();
if (type == Types1_16.META_TYPES.particleType) {
Particle particle = (Particle) meta.getValue();
if (particle.getId() == 16) { // Dust / Dust Transition
if (particle.id() == 16) { // Dust / Dust Transition
// Remove transition target color values 4-6
particle.getArguments().subList(4, 7).clear();
} else if (particle.getId() == 37) { // Vibration Signal
} else if (particle.id() == 37) { // Vibration Signal
// No nice mapping possible without tracking entity positions and doing particle tasks
particle.setId(0);
particle.getArguments().clear();
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_16.META_TYPES.poseType) {
// Goat LONG_JUMP added at 6
int pose = meta.value();

View File

@ -112,7 +112,7 @@ public final class BlockItemPackets1_18 extends BackwardsItemRewriter<Clientboun
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
}
int newId = protocol.getMappingData().getNewParticleId(id);

View File

@ -99,7 +99,7 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
MetaType type = meta.metaType();
if (type == Types1_17.META_TYPES.particleType) {
Particle particle = meta.value();
if (particle.getId() == 3) { // Block marker
if (particle.id() == 3) { // Block marker
Particle.ParticleData<?> 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<ClientboundPackets1_
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
}
});

View File

@ -200,7 +200,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
return;
}
translatableRewriter.processText(decorationResult.content());
translatableRewriter.processText(wrapper.user(), decorationResult.content());
wrapper.write(Type.COMPONENT, decorationResult.content());
wrapper.write(Type.BYTE, decorationResult.overlay() ? (byte) 2 : 1);
wrapper.write(Type.UUID, sender);
@ -216,7 +216,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
public void register() {
handler(wrapper -> {
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);

View File

@ -70,12 +70,12 @@ public final class BlockItemPackets1_19 extends BackwardsItemRewriter<Clientboun
final int size = wrapper.read(Type.VAR_INT);
wrapper.write(Type.UNSIGNED_BYTE, (short) size);
for (int i = 0; i < size; i++) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // First item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // First item
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
final Item secondItem = wrapper.read(Type.ITEM1_13_2);
if (secondItem != null) {
handleItemToClient(secondItem);
handleItemToClient(wrapper.user(), secondItem);
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.ITEM1_13_2, secondItem);
} else {

View File

@ -243,21 +243,21 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
if (type == Types1_18.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.getId() == particleMappings.id("sculk_charge")) {
if (particle.id() == particleMappings.id("sculk_charge")) {
//TODO
event.cancel();
return;
} else if (particle.getId() == particleMappings.id("shriek")) {
} else if (particle.id() == particleMappings.id("shriek")) {
//TODO
event.cancel();
return;
} else if (particle.getId() == particleMappings.id("vibration")) {
} else if (particle.id() == particleMappings.id("vibration")) {
// Can't do without the position
event.cancel();
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_18.META_TYPES.poseType) {
final int pose = meta.value();
if (pose >= 8) {

View File

@ -309,7 +309,7 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
final JsonElement unsignedContent = wrapper.read(Type.OPTIONAL_COMPONENT);
final JsonElement content = unsignedContent != null ? unsignedContent : ComponentUtil.plainToJson(plainContent);
translatableRewriter.processText(content);
translatableRewriter.processText(wrapper.user(), content);
final int filterMaskType = wrapper.read(Type.VAR_INT);
if (filterMaskType == 2) {
wrapper.read(Type.LONG_ARRAY_PRIMITIVE); // Mask
@ -331,7 +331,7 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
});
registerClientbound(ClientboundPackets1_19_3.DISGUISED_CHAT, ClientboundPackets1_19_1.SYSTEM_CHAT, wrapper -> {
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);

View File

@ -79,10 +79,10 @@ public final class BlockItemPackets1_19_3 extends BackwardsItemRewriter<Clientbo
for (int j = 0; j < ingredients; j++) {
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
}
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
break;
}
case "crafting_shaped": {
@ -92,10 +92,10 @@ public final class BlockItemPackets1_19_3 extends BackwardsItemRewriter<Clientbo
for (int j = 0; j < ingredients; j++) {
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
}
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
break;
}
case "smelting":
@ -106,9 +106,9 @@ public final class BlockItemPackets1_19_3 extends BackwardsItemRewriter<Clientbo
wrapper.read(Type.VAR_INT); // Crafting book category
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
break;

View File

@ -59,7 +59,7 @@ public final class BlockItemPackets1_19_4 extends BackwardsItemRewriter<Clientbo
wrapper.set(Type.VAR_INT, 1, windowType - 1);
}
protocol.getTranslatableRewriter().processText(wrapper.get(Type.COMPONENT, 0));
protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.get(Type.COMPONENT, 0));
});
}
});
@ -84,7 +84,7 @@ public final class BlockItemPackets1_19_4 extends BackwardsItemRewriter<Clientbo
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
rewrite(wrapper.passthrough(Type.ITEM1_13_2)); // Result
rewrite(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
// Remove notification boolean
wrapper.read(Type.BOOLEAN);

View File

@ -163,7 +163,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
event.createExtraMeta(new Metadata(3, Types1_19_3.META_TYPES.booleanType, true)); // Show custom name
final JsonElement element = meta.value();
protocol.getTranslatableRewriter().processText(element);
protocol.getTranslatableRewriter().processText(event.user(), element);
}));
filter().type(EntityTypes1_19_4.DISPLAY).handler((event, meta) -> {
// TODO Maybe spawn an extra entity to ride the armor stand for blocks and items

View File

@ -87,7 +87,7 @@ public final class Protocol1_19_4To1_20 extends BackwardsProtocol<ClientboundPac
registerClientbound(ClientboundPackets1_19_4.COMBAT_KILL, wrapper -> {
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));
});
}

View File

@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.storage.BackSignEditStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -60,7 +61,7 @@ public final class BlockItemPackets1_20 extends BackwardsItemRewriter<Clientboun
protocol.registerClientbound(ClientboundPackets1_19_4.CHUNK_DATA, new PacketHandlers() {
@Override
protected void register() {
handler(blockRewriter.chunkDataHandler1_19(ChunkType1_18::new, BlockItemPackets1_20.this::handleBlockEntity));
handler(blockRewriter.chunkDataHandler1_19(ChunkType1_18::new, (user, blockEntity) -> handleBlockEntity(blockEntity)));
create(Type.BOOLEAN, true); // Trust edges
}
});
@ -106,7 +107,7 @@ public final class BlockItemPackets1_20 extends BackwardsItemRewriter<Clientboun
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Icon
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
@ -147,12 +148,12 @@ public final class BlockItemPackets1_20 extends BackwardsItemRewriter<Clientboun
}
@Override
public @Nullable Item handleItemToClient(@Nullable final Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
// Remove new trim tags
final CompoundTag trimTag;
@ -171,12 +172,12 @@ public final class BlockItemPackets1_20 extends BackwardsItemRewriter<Clientboun
}
@Override
public @Nullable Item handleItemToServer(@Nullable final Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
// Add back original trim tag
final Tag trimTag;

View File

@ -172,14 +172,14 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol<ClientboundPac
return;
}
translatableRewriter.processText(decoratedMessage);
translatableRewriter.processText(wrapper.user(), decoratedMessage);
wrapper.write(Type.COMPONENT, decoratedMessage);
wrapper.write(Type.VAR_INT, SYSTEM_CHAT_ID);
});
registerClientbound(ClientboundPackets1_19_1.SYSTEM_CHAT, wrapper -> {
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);

View File

@ -148,7 +148,7 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
if (wrapper.passthrough(Type.BOOLEAN)) {
convertComponent(wrapper); // Title
convertComponent(wrapper); // Description
itemRewriter.handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Icon
itemRewriter.handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_20_2)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT);
if ((flags & 1) != 0) {
@ -366,13 +366,13 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
private void convertComponent(final PacketWrapper wrapper) throws Exception {
final Tag tag = wrapper.read(Type.TAG);
translatableRewriter.processTag(tag);
translatableRewriter.processTag(wrapper.user(), tag);
wrapper.write(Type.COMPONENT, ComponentUtil.tagToJson(tag));
}
private void convertOptionalComponent(final PacketWrapper wrapper) throws Exception {
final Tag tag = wrapper.read(Type.OPTIONAL_TAG);
translatableRewriter.processTag(tag);
translatableRewriter.processTag(wrapper.user(), tag);
wrapper.write(Type.OPTIONAL_COMPONENT, ComponentUtil.tagToJson(tag));
}

View File

@ -107,7 +107,7 @@ public final class BlockItemPacketRewriter1_20_3 extends BackwardsItemRewriter<C
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
rewrite(wrapper.passthrough(itemType())); // Result
rewrite(wrapper.user(), wrapper.passthrough(itemType())); // Result
wrapper.passthrough(Type.BOOLEAN); // Show notification
}
}.register(ClientboundPackets1_20_3.DECLARE_RECIPES);

View File

@ -107,7 +107,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
} else if (type == Types1_20_3.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.getId() == particleMappings.id("vibration")) {
if (particle.id() == particleMappings.id("vibration")) {
// Change the type of the position source type argument
final int positionSourceType = particle.<Integer>removeArgument(0).getValue();
if (positionSourceType == 0) {
@ -117,7 +117,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
}
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_20_3.META_TYPES.poseType) {
final int pose = meta.value();
if (pose >= 15) {

View File

@ -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;
@ -86,7 +87,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);
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
// Remove color argument
final int color = particle.<Integer>removeArgument(0).getValue();
@ -139,11 +140,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_COST));
final Item input = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM_COST));
wrapper.write(Type.ITEM1_20_2, input);
final Item result = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
final Item result = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, result);
final Item secondInput = handleItemToClient(wrapper.read(Types1_20_5.OPTIONAL_ITEM_COST));
final Item secondInput = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.OPTIONAL_ITEM_COST));
wrapper.write(Type.ITEM1_20_2, secondInput);
wrapper.passthrough(Type.BOOLEAN); // Out of stock
@ -172,19 +173,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, DATA_CONVERTER);
}
@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);
final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(connection, item);
return super.handleItemToServer(connection, structuredItem);
}
}

View File

@ -77,7 +77,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
wrapper.write(Type.BYTE, slot);
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.read(Types1_20_5.ITEM));
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, item);
} while (slot < 0);
});

View File

@ -19,6 +19,7 @@ package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -149,11 +150,11 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handler(wrapper -> {
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 BackwardsItemRewriter<C
map(Type.UNSIGNED_BYTE); // Window id
map(Type.VAR_INT); // State id
map(Type.SHORT); // Slot id
handler(wrapper -> 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 -> {
@ -177,7 +178,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Icon
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
@ -205,7 +206,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
byte slot;
do {
slot = wrapper.passthrough(Type.BYTE);
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2)));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
} while ((slot & 0xFFFFFF80) != 0);
});
}
@ -224,11 +225,11 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
final int length = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < length; i++) {
wrapper.passthrough(Type.SHORT); // Slot
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)));
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
}
// Carried item
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)));
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
});
}
});
@ -236,9 +237,9 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
wrapper.passthrough(Type.VAR_INT); // Container id
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Input
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Output
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Second Item
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Input
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Output
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
@ -253,7 +254,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
@Override
public void register() {
map(Type.SHORT); // 0 - Slot
handler(wrapper -> 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() {
@ -276,7 +277,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
final int data = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2)));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
}
});
}
@ -290,7 +291,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handleIngredients(wrapper);
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@ -301,7 +302,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
wrapper.passthrough(Type.FLOAT); // EXP
@ -318,7 +319,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
}
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
wrapper.passthrough(Type.BOOLEAN); // Show notification
@ -330,7 +331,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@ -340,7 +341,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handleIngredient(wrapper); // Addition
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@ -351,7 +352,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
handleIngredient(wrapper); // Additions
final Item result = wrapper.read(itemType());
rewrite(result);
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@ -360,14 +361,14 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(Type.ITEM1_13_2_ARRAY, items);
for (final Item item : items) {
rewrite(item);
rewrite(wrapper.user(), item);
}
}
}.register(ClientboundPackets1_20_2.DECLARE_RECIPES);
}
@Override
public @Nullable Item handleItemToClient(@Nullable final Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
@ -375,11 +376,11 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_1Effects(item);
}
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
@Override
public @Nullable Item handleItemToServer(@Nullable final Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
@ -387,7 +388,7 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_2Effects(item);
}
return super.handleItemToServer(item);
return super.handleItemToServer(connection, item);
}
private @Nullable CompoundTag handleBlockEntity(@Nullable final CompoundTag tag) {

View File

@ -57,12 +57,12 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -89,7 +89,7 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite metadata items
protocol.getEntityRewriter().filter().handler((event, meta) -> {
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