From 5777f4a117626a864e73d574a3cd379320288801 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 14 Sep 2021 18:16:12 +0200 Subject: [PATCH] Start working on 1.18 --- build.gradle.kts | 2 +- .../api/ViaBackwardsPlatform.java | 2 + .../packets/EntityPackets1_17.java | 4 +- .../Protocol1_17_1To1_18.java | 78 +++++++++++++++ .../packets/EntityPackets1_17.java | 95 +++++++++++++++++++ gradle/libs.versions.toml | 2 +- 6 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/Protocol1_17_1To1_18.java create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_17.java diff --git a/build.gradle.kts b/build.gradle.kts index 4cd69267..07bbfbaa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.0.2-SNAPSHOT" + version = "4.1.0-SNAPSHOT" description = "Allow older clients to join newer server versions." } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index 63f936a6..7b10d532 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -43,6 +43,7 @@ import com.viaversion.viabackwards.protocol.protocol1_16_2to1_16_3.Protocol1_16_ import com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.Protocol1_16_3To1_16_4; import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17; import com.viaversion.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1; +import com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18; import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.Protocol1_17To1_17_1; import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import com.viaversion.viaversion.api.Via; @@ -106,6 +107,7 @@ public interface ViaBackwardsPlatform { protocolManager.registerProtocol(new Protocol1_16_4To1_17(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_17); protocolManager.registerProtocol(new Protocol1_17To1_17_1(), ProtocolVersion.v1_17, ProtocolVersion.v1_17_1); + protocolManager.registerProtocol(new Protocol1_17_1To1_18(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_18); } /** diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index 9e2c8835..e979ae3e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -88,8 +88,8 @@ public final class EntityPackets1_17 extends EntityRewriter { CompoundTag registry = wrapper.get(Type.NBT, 0); - CompoundTag biomeRegsitry = registry.get("minecraft:worldgen/biome"); - ListTag biomes = biomeRegsitry.get("value"); + CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome"); + ListTag biomes = biomeRegistry.get("value"); for (Tag biome : biomes) { CompoundTag biomeCompound = ((CompoundTag) biome).get("element"); StringTag category = biomeCompound.get("category"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/Protocol1_17_1To1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/Protocol1_17_1To1_18.java new file mode 100644 index 00000000..333c83e9 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/Protocol1_17_1To1_18.java @@ -0,0 +1,78 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.protocol1_17_1to1_18; + +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viaversion.api.data.entity.EntityTracker; +import com.viaversion.viaversion.api.minecraft.chunks.Chunk; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1; +import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; +import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type; + +public final class Protocol1_17_1To1_18 extends BackwardsProtocol { + + public Protocol1_17_1To1_18() { + super(ClientboundPackets1_17_1.class, ClientboundPackets1_17_1.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class); + } + + @Override + protected void registerPackets() { + registerClientbound(ClientboundPackets1_17_1.CHUNK_DATA, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + final EntityTracker tracker = getEntityRewriter().tracker(wrapper.user()); + final Chunk chunk = wrapper.passthrough(new Chunk1_17Type(tracker.currentWorldSectionHeight())); + /*for (int s = 0; s < chunk.getSections().length; s++) { + ChunkSection section = chunk.getSections()[s]; + if (section == null) continue; + for (int i = 0; i < section.getPaletteSize(); i++) { + int old = section.getPaletteEntry(i); + section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old)); + } + }*/ + + // Create and send light packet first + final PacketWrapper lightPacket = wrapper.create(ClientboundPackets1_17_1.UPDATE_LIGHT); + lightPacket.write(Type.BOOLEAN, wrapper.read(Type.BOOLEAN)); // Trust edges + lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE)); // Sky light mask + lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE)); // Block light mask + lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE)); // Empty sky light mask + lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE)); // Empty block light mask + + final int skyLightLength = wrapper.read(Type.VAR_INT); + lightPacket.write(Type.VAR_INT, skyLightLength); + for (int i = 0; i < skyLightLength; i++) { + lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE)); + } + + final int blockLightLength = wrapper.read(Type.VAR_INT); + lightPacket.write(Type.VAR_INT, blockLightLength); + for (int i = 0; i < blockLightLength; i++) { + lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE)); + } + + lightPacket.send(Protocol1_17_1To1_18.class); + }); + } + }); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_17.java new file mode 100644 index 00000000..af4925c8 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_17.java @@ -0,0 +1,95 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.packets; + +import com.viaversion.viabackwards.api.rewriters.EntityRewriter; +import com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18; +import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.FloatTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; +import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1; + +public final class EntityPackets1_17 extends EntityRewriter { + + public EntityPackets1_17(Protocol1_17_1To1_18 protocol) { + super(protocol); + } + + @Override + protected void registerPackets() { + /*registerTrackerWithData(ClientboundPackets1_17_1.SPAWN_ENTITY, Entity1_18Types.FALLING_BLOCK); + registerSpawnTracker(ClientboundPackets1_17_1.SPAWN_MOB); + registerTracker(ClientboundPackets1_17_1.SPAWN_EXPERIENCE_ORB, Entity1_18Types.EXPERIENCE_ORB); + registerTracker(ClientboundPackets1_17_1.SPAWN_PAINTING, Entity1_18Types.PAINTING); + registerTracker(ClientboundPackets1_17_1.SPAWN_PLAYER, Entity1_18Types.PLAYER); + registerMetadataRewriter(ClientboundPackets1_17_1.ENTITY_METADATA, Types1_17.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_17_1.REMOVE_ENTITIES);*/ + + protocol.registerClientbound(ClientboundPackets1_17_1.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); // Worlds + map(Type.NBT); // Dimension registry + map(Type.NBT); // Current dimension data + map(Type.STRING); // World + handler(getTrackerHandler(Entity1_17Types.PLAYER, Type.INT)); + handler(worldDataTrackerHandler(1)); + handler(wrapper -> { + CompoundTag registry = wrapper.get(Type.NBT, 0); + CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome"); + ListTag biomes = biomeRegistry.get("value"); + for (Tag biome : biomes) { + CompoundTag biomeCompound = ((CompoundTag) biome).get("element"); + // The client just needs something + biomeCompound.put("depth", new FloatTag(0.125F)); + biomeCompound.put("scale", new FloatTag(0.05F)); + } + }); + } + }); + + protocol.registerClientbound(ClientboundPackets1_17_1.RESPAWN, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.NBT); // Dimension data + map(Type.STRING); // World + handler(worldDataTrackerHandler(0)); + } + }); + } + + @Override + protected void registerRewrites() { + // Particles have already been handled + //registerMetaTypeHandler(MetaType1_17.ITEM, MetaType1_17.BLOCK_STATE, null, MetaType1_17.OPT_COMPONENT); //TODO correct types + } + + @Override + public EntityType typeFromId(int typeId) { + return Entity1_17Types.getTypeFromId(typeId); //TODO + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a45f4452..11aeb8c7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "4.0.1" +viaver = "4.1.0-SNAPSHOT" # Common provided netty = "4.0.20.Final"