3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Fix 1.18.2->1.19.0 transforming, warn on 1.19.0 server

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-06-30 20:00:55 +02:00
Ursprung f4aa96a5f8
Commit 6388021c6d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 112 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -142,7 +142,10 @@ public class ViaManagerImpl implements ViaManager {
platform.getLogger().warning("This version of Minecraft is extremely outdated and support for it has reached its end of life. "
+ "You will still be able to run Via on this Minecraft version, but we are unlikely to provide any further fixes or help with problems specific to legacy Minecraft versions. "
+ "Please consider updating to give your players a better experience and to avoid issues that have long been fixed.");
} else if (protocolVersion.highestSupportedVersion() == ProtocolVersion.v1_19.getVersion()) {
platform.getLogger().warning("Due to technical limitations, ViaVersion does not support 1.19.1+ clients on 1.19.0 servers. Please update your server to a newer version.");
}
}
checkJavaVersion();

Datei anzeigen

@ -17,7 +17,11 @@
*/
package com.viaversion.viaversion.protocols.protocol1_19_1to1_19;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.minecraft.nbt.BinaryTagIO;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
@ -25,18 +29,84 @@ import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
import java.io.IOException;
public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPackets1_19, ClientboundPackets1_19, ServerboundPackets1_19, ServerboundPackets1_19> {
private static final String CHAT_REGISTRY_SNBT = "{\n" +
" \"minecraft:chat_type\": {\n" +
" \"type\": \"minecraft:chat_type\",\n" +
" \"value\": [\n" +
" {\n" +
" \"name\":\"minecraft:chat\",\n" +
" \"id\":1,\n" +
" \"element\":{\n" +
" \"chat\":{\n" +
" \"translation_key\":\"chat.type.text\",\n" +
" \"parameters\":[\n" +
" \"sender\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"narration\":{\n" +
" \"translation_key\":\"chat.type.text.narrate\",\n" +
" \"parameters\":[\n" +
" \"sender\",\n" +
" \"content\"\n" +
" ]\n" +
" }\n" +
" }\n" +
" }" +
" ]\n" +
" }\n" +
"}";
private static final CompoundTag CHAT_REGISTRY;
static {
try {
CHAT_REGISTRY = BinaryTagIO.readString(CHAT_REGISTRY_SNBT).get("minecraft:chat_type");
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected void registerPackets() {
// Skip 1.19 and assume 1.18.2->1.19.1 translation
registerClientbound(ClientboundPackets1_19.SYSTEM_CHAT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT);
map(Type.COMPONENT); // Content
handler(wrapper -> {
wrapper.read(Type.VAR_INT); // Chat type
wrapper.write(Type.BOOLEAN, false); // Overlay
final int type = wrapper.read(Type.VAR_INT);
final boolean overlay = type == 2;
wrapper.write(Type.BOOLEAN, overlay);
});
}
});
registerClientbound(ClientboundPackets1_19.PLAYER_CHAT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT); // Signed content
map(Type.OPTIONAL_COMPONENT); // Unsigned content
handler(wrapper -> {
// Can only be 1 (chat) or 2 (game info) as per 1.18.2->1.19.0 transformer
final int type = wrapper.read(Type.VAR_INT);
if (type == 1) {
return;
}
// Send as system message to allow overlay
wrapper.cancel();
final PacketWrapper systemChatPacket = wrapper.create(ClientboundPackets1_19.SYSTEM_CHAT);
JsonElement content = wrapper.get(Type.OPTIONAL_COMPONENT, 0);
if (content == null) {
content = wrapper.get(Type.COMPONENT, 0);
}
systemChatPacket.write(Type.COMPONENT, content);
systemChatPacket.write(Type.BOOLEAN, true); // Overlay
systemChatPacket.send(Protocol1_19_1To1_19.class);
});
}
});
@ -49,5 +119,22 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
read(Type.OPTIONAL_UUID); // Profile uuid
}
});
registerClientbound(ClientboundPackets1_19.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // Entity ID
map(Type.BOOLEAN); // Hardcore
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Registry
handler(wrapper -> {
// Replace chat types
final CompoundTag tag = wrapper.get(Type.NBT, 0);
tag.put("minecraft:chat_type", CHAT_REGISTRY.clone());
});
}
});
}
}

Datei anzeigen

@ -200,9 +200,8 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
public void registerMap() {
map(Type.COMPONENT); // Message
handler(wrapper -> {
//TODO handle game info
wrapper.read(Type.BYTE);
wrapper.write(Type.VAR_INT, 1);
final int type = wrapper.read(Type.BYTE);
wrapper.write(Type.VAR_INT, type == 0 ? 1 : type);
});
read(Type.UUID); // Sender
}

Datei anzeigen

@ -51,31 +51,27 @@ import java.util.Map;
public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
//TODO move to compressed nbt file
private static final String CHAT_REGISTRY_SNBT = "{\n" +
" \"minecraft:chat_type\": {\n" +
" \"type\": \"minecraft:chat_type\",\n" +
" \"value\": [\n" +
" {\n" +
" \"name\":\"minecraft:chat\",\n" +
" \"id\":1,\n" +
" \"element\":{\n" +
" \"chat\":{\n" +
" \"translation_key\":\"chat.type.text\",\n" +
" \"parameters\":[\n" +
" \"sender\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"narration\":{\n" +
" \"translation_key\":\"chat.type.text.narrate\",\n" +
" \"parameters\":[\n" +
" \"sender\",\n" +
" \"content\"\n" +
" ]\n" +
" }\n" +
" }\n" +
" }" +
" {\n" +
" \"name\": \"minecraft:system\",\n" +
" \"id\": 1,\n" +
" \"element\": {\n" +
" \"chat\": {},\n" +
" \"narration\": {\n" +
" \"priority\": \"system\"\n" +
" }\n" +
" }\n" +
" },\n" +
" {\n" +
" \"name\": \"minecraft:game_info\",\n" +
" \"id\": 2,\n" +
" \"element\": {\n" +
" \"overlay\": {}\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";