Skip to content

Commit fd4d6b1

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 0273625 + 9387b86 commit fd4d6b1

File tree

9 files changed

+106
-49
lines changed

9 files changed

+106
-49
lines changed

api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class ProtocolVersion {
8585
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
8686
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
8787
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
88-
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3");
88+
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new VersionRange("1.20", 3, 4));
8989
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
9090

9191
public static ProtocolVersion register(int version, String name) {

common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
*/
1818
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets;
1919

20-
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
21-
import com.github.steveice10.opennbt.tag.builtin.*;
20+
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
21+
import com.github.steveice10.opennbt.tag.builtin.IntTag;
22+
import com.github.steveice10.opennbt.tag.builtin.ListTag;
23+
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
24+
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
25+
import com.github.steveice10.opennbt.tag.builtin.StringTag;
26+
import com.github.steveice10.opennbt.tag.builtin.Tag;
2227
import com.google.common.base.Joiner;
2328
import com.google.common.primitives.Ints;
2429
import com.viaversion.viaversion.api.Via;
@@ -36,7 +41,6 @@
3641
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
3742
import com.viaversion.viaversion.rewriter.ItemRewriter;
3843
import com.viaversion.viaversion.util.Key;
39-
4044
import java.nio.charset.StandardCharsets;
4145
import java.util.ArrayList;
4246
import java.util.List;
@@ -357,7 +361,7 @@ public Item handleItemToClient(Item item) {
357361
if (tag.get("CanPlaceOn") instanceof ListTag) {
358362
ListTag old = tag.get("CanPlaceOn");
359363
ListTag newCanPlaceOn = new ListTag(StringTag.class);
360-
tag.put(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
364+
tag.put(NBT_TAG_NAME + "|CanPlaceOn", old.clone());
361365
for (Tag oldTag : old) {
362366
Object value = oldTag.getValue();
363367
String oldId = Key.stripMinecraftNamespace(value.toString());
@@ -379,7 +383,7 @@ public Item handleItemToClient(Item item) {
379383
if (tag.get("CanDestroy") instanceof ListTag) {
380384
ListTag old = tag.get("CanDestroy");
381385
ListTag newCanDestroy = new ListTag(StringTag.class);
382-
tag.put(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
386+
tag.put(NBT_TAG_NAME + "|CanDestroy", old.clone());
383387
for (Tag oldTag : old) {
384388
Object value = oldTag.getValue();
385389
String oldId = Key.stripMinecraftNamespace(value.toString());
@@ -617,8 +621,7 @@ public Item handleItemToServer(Item item) {
617621
tag.put("StoredEnchantments", newStoredEnch);
618622
}
619623
if (tag.get(NBT_TAG_NAME + "|CanPlaceOn") instanceof ListTag) {
620-
tag.put("CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanPlaceOn"))));
621-
tag.remove(NBT_TAG_NAME + "|CanPlaceOn");
624+
tag.put("CanPlaceOn", tag.remove(NBT_TAG_NAME + "|CanPlaceOn"));
622625
} else if (tag.get("CanPlaceOn") instanceof ListTag) {
623626
ListTag old = tag.get("CanPlaceOn");
624627
ListTag newCanPlaceOn = new ListTag(StringTag.class);
@@ -638,10 +641,7 @@ public Item handleItemToServer(Item item) {
638641
tag.put("CanPlaceOn", newCanPlaceOn);
639642
}
640643
if (tag.get(NBT_TAG_NAME + "|CanDestroy") instanceof ListTag) {
641-
tag.put("CanDestroy", ConverterRegistry.convertToTag(
642-
ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanDestroy"))
643-
));
644-
tag.remove(NBT_TAG_NAME + "|CanDestroy");
644+
tag.put("CanDestroy", tag.remove(NBT_TAG_NAME + "|CanDestroy"));
645645
} else if (tag.get("CanDestroy") instanceof ListTag) {
646646
ListTag old = tag.get("CanDestroy");
647647
ListTag newCanDestroy = new ListTag(StringTag.class);

common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.viaversion.viaversion.api.protocol.packet.Direction;
3030
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
3131
import com.viaversion.viaversion.api.protocol.packet.State;
32+
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
3233
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
3334
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
3435
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
@@ -150,12 +151,11 @@ protected void registerPackets() {
150151
configurationState.setClientInformation(clientInformation);
151152
wrapper.cancel();
152153
});
153-
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.getId(), -1, wrapper -> {
154-
wrapper.setPacketType(ServerboundPackets1_19_4.PLUGIN_MESSAGE);
155-
sanitizeCustomPayload(wrapper);
156-
});
157-
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.KEEP_ALIVE.getId(), -1, wrapper -> wrapper.setPacketType(ServerboundPackets1_19_4.KEEP_ALIVE));
158-
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.PONG.getId(), -1, wrapper -> wrapper.setPacketType(ServerboundPackets1_19_4.PONG));
154+
155+
// If these are not queued, they may be received before the server switched its listener state to play
156+
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.getId(), -1, queueServerboundPacket(ServerboundPackets1_20_2.PLUGIN_MESSAGE));
157+
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.KEEP_ALIVE.getId(), -1, queueServerboundPacket(ServerboundPackets1_20_2.KEEP_ALIVE));
158+
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.PONG.getId(), -1, queueServerboundPacket(ServerboundPackets1_20_2.PONG));
159159

160160
// Cancel this, as it will always just be the response to a re-sent pack from us
161161
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), -1, PacketWrapper::cancel);
@@ -273,12 +273,8 @@ public static void sendConfigurationPackets(final UserConnection connection, fin
273273
registryDataPacket.write(Type.COMPOUND_TAG, dimensionRegistry);
274274
registryDataPacket.send(Protocol1_20_2To1_20.class);
275275

276-
// Enabling features is only possible during the configuration phase
277-
// TODO Sad emoji
278-
final PacketWrapper enableFeaturesPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES, connection);
279-
enableFeaturesPacket.write(Type.VAR_INT, 1);
280-
enableFeaturesPacket.write(Type.STRING, "minecraft:vanilla");
281-
enableFeaturesPacket.send(Protocol1_20_2To1_20.class);
276+
// If we tracked enables features, they'd be sent here
277+
// The client includes vanilla as the default feature when initially leaving the login phase
282278

283279
final LastTags lastTags = connection.get(LastTags.class);
284280
if (lastTags != null) {
@@ -302,6 +298,14 @@ public static void sendConfigurationPackets(final UserConnection connection, fin
302298
protocolInfo.setServerState(State.PLAY);
303299
}
304300

301+
private PacketHandler queueServerboundPacket(final ServerboundPackets1_20_2 packetType) {
302+
return wrapper -> {
303+
wrapper.setPacketType(packetType);
304+
wrapper.user().get(ConfigurationState.class).addPacketToQueue(wrapper, false);
305+
wrapper.cancel();
306+
};
307+
}
308+
305309
private void sanitizeCustomPayload(final PacketWrapper wrapper) throws Exception {
306310
final String channel = Key.namespaced(wrapper.passthrough(Type.STRING));
307311
if (channel.equals("minecraft:brand")) {

common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.gson.JsonElement;
3636
import com.google.gson.JsonObject;
3737
import com.google.gson.JsonPrimitive;
38+
import com.google.gson.internal.LazilyParsedNumber;
3839
import com.viaversion.viaversion.api.Via;
3940
import com.viaversion.viaversion.api.connection.UserConnection;
4041
import com.viaversion.viaversion.api.data.MappingData;
@@ -65,6 +66,7 @@
6566
import com.viaversion.viaversion.rewriter.SoundRewriter;
6667
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
6768
import com.viaversion.viaversion.rewriter.TagRewriter;
69+
import java.nio.charset.StandardCharsets;
6870
import java.util.Arrays;
6971
import java.util.BitSet;
7072
import java.util.HashSet;
@@ -264,7 +266,12 @@ protected void registerPackets() {
264266
registerClientbound(ClientboundPackets1_20_2.ACTIONBAR, this::convertComponent);
265267
registerClientbound(ClientboundPackets1_20_2.TITLE_TEXT, this::convertComponent);
266268
registerClientbound(ClientboundPackets1_20_2.TITLE_SUBTITLE, this::convertComponent);
267-
registerClientbound(ClientboundPackets1_20_2.DISGUISED_CHAT, this::convertComponent);
269+
registerClientbound(ClientboundPackets1_20_2.DISGUISED_CHAT, wrapper -> {
270+
convertComponent(wrapper);
271+
wrapper.passthrough(Type.VAR_INT); // Chat type
272+
convertComponent(wrapper); // Name
273+
convertOptionalComponent(wrapper); // Target name
274+
});
268275
registerClientbound(ClientboundPackets1_20_2.SYSTEM_CHAT, this::convertComponent);
269276
registerClientbound(ClientboundPackets1_20_2.OPEN_WINDOW, wrapper -> {
270277
wrapper.passthrough(Type.VAR_INT); // Container id
@@ -326,7 +333,7 @@ public void register() {
326333
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_PUSH.getId(), resourcePackHandler(ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_POP));
327334
// TODO Auto map via packet types provider
328335
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES.getId(), ClientboundConfigurationPackets1_20_3.UPDATE_ENABLED_FEATURES.getId());
329-
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_3.UPDATE_TAGS.getId());
336+
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_3.UPDATE_TAGS.getId(), tagRewriter.getGenericHandler());
330337
}
331338

332339
private PacketHandler resourcePackStatusHandler() {
@@ -346,16 +353,19 @@ private PacketHandler resourcePackStatusHandler() {
346353

347354
private PacketHandler resourcePackHandler(final ClientboundPacketType popType) {
348355
return wrapper -> {
349-
wrapper.write(Type.UUID, UUID.randomUUID());
350-
wrapper.passthrough(Type.STRING); // Url
351-
wrapper.passthrough(Type.STRING); // Hash
352-
wrapper.passthrough(Type.BOOLEAN); // Required
353-
convertOptionalComponent(wrapper);
354-
355356
// Drop old resource packs first
356357
final PacketWrapper dropPacksPacket = wrapper.create(popType);
357358
dropPacksPacket.write(Type.OPTIONAL_UUID, null);
358359
dropPacksPacket.send(Protocol1_20_3To1_20_2.class);
360+
361+
// Use the hash to write a pack uuid
362+
final String url = wrapper.read(Type.STRING);
363+
final String hash = wrapper.read(Type.STRING);
364+
wrapper.write(Type.UUID, UUID.nameUUIDFromBytes(hash.getBytes(StandardCharsets.UTF_8)));
365+
wrapper.write(Type.STRING, url);
366+
wrapper.write(Type.STRING, hash);
367+
wrapper.passthrough(Type.BOOLEAN); // Required
368+
convertOptionalComponent(wrapper);
359369
};
360370
}
361371

@@ -390,10 +400,12 @@ private void convertOptionalComponent(final PacketWrapper wrapper) throws Except
390400
return null;
391401
} else if (element.isJsonObject()) {
392402
final CompoundTag tag = new CompoundTag();
393-
for (final Map.Entry<String, JsonElement> entry : element.getAsJsonObject().entrySet()) {
394-
// Not strictly needed, but might as well make it more compact
403+
final JsonObject jsonObject = element.getAsJsonObject();
404+
for (final Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
395405
convertObjectEntry(entry.getKey(), entry.getValue(), tag);
396406
}
407+
408+
addComponentType(jsonObject, tag);
397409
return tag;
398410
} else if (element.isJsonArray()) {
399411
return convertJsonArray(element);
@@ -418,12 +430,37 @@ private void convertOptionalComponent(final PacketWrapper wrapper) throws Except
418430
return new DoubleTag(number.doubleValue());
419431
} else if (number instanceof Float) {
420432
return new FloatTag(number.floatValue());
433+
} else if (number instanceof LazilyParsedNumber) {
434+
// TODO: This might need better handling
435+
return new IntTag(number.intValue());
421436
}
422-
return new StringTag(primitive.getAsString()); // ???
437+
return new IntTag(number.intValue()); // ???
423438
}
424439
throw new IllegalArgumentException("Unhandled json type " + element.getClass().getSimpleName() + " with value " + element.getAsString());
425440
}
426441

442+
private static void addComponentType(final JsonObject object, final CompoundTag tag) {
443+
if (object.has("type")) {
444+
return;
445+
}
446+
447+
// Add the type to speed up deserialization and make DFU errors slightly more useful
448+
// Order is important
449+
if (object.has("text")) {
450+
tag.put("type", new StringTag("text"));
451+
} else if (object.has("translate")) {
452+
tag.put("type", new StringTag("translatable"));
453+
} else if (object.has("score")) {
454+
tag.put("type", new StringTag("score"));
455+
} else if (object.has("selector")) {
456+
tag.put("type", new StringTag("selector"));
457+
} else if (object.has("keybind")) {
458+
tag.put("type", new StringTag("keybind"));
459+
} else if (object.has("nbt")) {
460+
tag.put("type", new StringTag("nbt"));
461+
}
462+
}
463+
427464
private static ListTag convertJsonArray(final JsonElement element) {
428465
// TODO Number arrays?
429466
final ListTag listTag = new ListTag();
@@ -454,29 +491,38 @@ private static ListTag convertJsonArray(final JsonElement element) {
454491

455492
// Wrap all entries in compound tags as lists can only consist of one type of tag
456493
final CompoundTag compoundTag = new CompoundTag();
494+
compoundTag.put("type", new StringTag("text"));
457495
compoundTag.put("text", new StringTag());
458496
compoundTag.put("extra", convertedTag);
459497
}
460498
return processedListTag;
461499
}
462500

463-
private static void convertObjectEntry(final String key, final JsonElement element, final CompoundTag tag) {
464-
if ((key.equals("contents")) && element.isJsonObject()) {
501+
/**
502+
* Converts a json object entry to a tag entry.
503+
*
504+
* @param key key of the entry
505+
* @param value value of the entry
506+
* @param tag the resulting compound tag
507+
*/
508+
private static void convertObjectEntry(final String key, final JsonElement value, final CompoundTag tag) {
509+
if ((key.equals("contents")) && value.isJsonObject()) {
465510
// Store show_entity id as int array instead of uuid string
466-
final JsonObject hoverEvent = element.getAsJsonObject();
511+
// Not really required, but we might as well make it more compact
512+
final JsonObject hoverEvent = value.getAsJsonObject();
467513
final JsonElement id = hoverEvent.get("id");
468514
final UUID uuid;
469515
if (id != null && id.isJsonPrimitive() && (uuid = parseUUID(id.getAsString())) != null) {
470516
hoverEvent.remove("id");
471517

472-
final CompoundTag convertedTag = (CompoundTag) convertToTag(element);
518+
final CompoundTag convertedTag = (CompoundTag) convertToTag(value);
473519
convertedTag.put("id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(uuid)));
474520
tag.put(key, convertedTag);
475521
return;
476522
}
477523
}
478524

479-
tag.put(key, convertToTag(element));
525+
tag.put(key, convertToTag(value));
480526
}
481527

482528
private static @Nullable UUID parseUUID(final String uuidString) {

common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.viaversion.viaversion.api.protocol.Protocol;
2525
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
2626
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
27+
import com.viaversion.viaversion.api.protocol.packet.State;
2728
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
2829
import com.viaversion.viaversion.api.type.Type;
2930
import com.viaversion.viaversion.util.Key;
@@ -149,6 +150,10 @@ public void registerGeneric(C packetType) {
149150
protocol.registerClientbound(packetType, getGenericHandler());
150151
}
151152

153+
public void registerGeneric(State state, ClientboundPacketType packetType) {
154+
protocol.registerClientbound(state, packetType, getGenericHandler());
155+
}
156+
152157
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
153158
return wrapper -> {
154159
for (RegistryType type : RegistryType.getValues()) {

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
2-
projectVersion=4.9.2-SNAPSHOT
2+
projectVersion=4.9.3-SNAPSHOT
33

44
# Smile emoji
5-
mcVersions=1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
6-
mcVersionRange=1.8-1.20.3
5+
mcVersions=1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
6+
mcVersionRange=1.8-1.20.4
77
waterfallVersion=1.20
88
velocityVersion=3.2
99

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ adventure = "4.14.0"
66
gson = "2.10.1"
77
fastutil = "8.5.12"
88
flare = "2.0.1"
9-
vianbt = "3.2.0"
9+
vianbt = "3.2.1"
1010

1111
# Common provided
1212
netty = "4.0.20.Final"

0 commit comments

Comments
 (0)