From 8850d5c8ff81b1905742926d6996ce8271e6272d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 20 Apr 2022 21:00:45 +0200 Subject: [PATCH] 22w16b (probably, also ignoring a possible race condition) --- build.gradle.kts | 2 +- .../Protocol1_18_2To1_19.java | 3 +- .../packets/EntityPackets1_19.java | 34 ++++++++- .../storage/StoredPainting.java | 71 +++++++++++++++++++ .../viabackwards/data/mapping-1.18to1.19.json | 23 +++++- gradle/libs.versions.toml | 2 +- 6 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/storage/StoredPainting.java diff --git a/build.gradle.kts b/build.gradle.kts index 3878f615..ae2f722c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.3.0-22w15a-SNAPSHOT" + version = "4.3.0-22w16b-SNAPSHOT" description = "Allow older clients to join newer server versions." } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java index c7c13fdf..1c0113d2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java @@ -118,6 +118,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol { + event.cancel(); + + final StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId()); + final StoredPainting storedPainting = entityData.remove(StoredPainting.class); + if (storedPainting != null) { + final PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_18.SPAWN_PAINTING, event.user()); + packet.write(Type.VAR_INT, storedPainting.entityId()); + packet.write(Type.UUID, storedPainting.uuid()); + packet.write(Type.VAR_INT, meta.value()); + packet.write(Type.POSITION1_14, storedPainting.position()); + packet.write(Type.BYTE, storedPainting.direction()); + try { + // TODO Race condition + packet.send(Protocol1_18_2To1_19.class); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + filter().type(Entity1_19Types.PLAYER).removeIndex(19); // Last death location; filter().type(Entity1_19Types.CAT).index(19).handler((event, meta) -> meta.setMetaType(Types1_18.META_TYPES.varIntType)); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/storage/StoredPainting.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/storage/StoredPainting.java new file mode 100644 index 00000000..49b8de47 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/storage/StoredPainting.java @@ -0,0 +1,71 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2022 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_18_2to1_19.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.api.minecraft.Position; + +import java.util.UUID; + +public final class StoredPainting implements StorableObject { + + private final int entityId; + private final UUID uuid; + private final Position position; + private final byte direction; + + public StoredPainting(final int entityId, final UUID uuid, final Position position, final int direction3d) { + this.entityId = entityId; + this.uuid = uuid; + this.position = position; + this.direction = to2dDirection(direction3d); + } + + public int entityId() { + return entityId; + } + + public UUID uuid() { + return uuid; + } + + public Position position() { + return position; + } + + public byte direction() { + return direction; + } + + private byte to2dDirection(int direction) { + switch (direction) { + case 0: + case 1: + return -1; // No worky + case 2: + return 2; + case 3: + return 0; + case 4: + return 1; + case 5: + return 3; + } + throw new IllegalArgumentException("Invalid direction: " + direction); + } +} diff --git a/common/src/main/resources/assets/viabackwards/data/mapping-1.18to1.19.json b/common/src/main/resources/assets/viabackwards/data/mapping-1.18to1.19.json index 84d16ff3..0214ff00 100644 --- a/common/src/main/resources/assets/viabackwards/data/mapping-1.18to1.19.json +++ b/common/src/main/resources/assets/viabackwards/data/mapping-1.18to1.19.json @@ -398,8 +398,13 @@ "entity.allay.item_given": "", "entity.allay.item_taken": "", "entity.parrot.imitate.warden": "", - "entity.warden.sonic_boom": "", - "entity.warden.sonic_charge": "" + "entity.warden.sonic_boom": "", + "entity.warden.sonic_charge": "", + "entity.allay.item_thrown": "", + "music_disc.5": "", + "music.overworld.swamp": "", + "music.overworld.jungle_and_forest": "", + "music.overworld.old_growth_taiga": "" }, "items": { "minecraft:warden_spawn_egg": { @@ -593,6 +598,14 @@ "minecraft:recovery_compass": { "id": "minecraft:compass", "name": "1.19 Recovery Compass" + }, + "minecraft:music_disc_5": { + "id": "minecraft:music_disc_13", + "name": "1.19 Music Disc 5" + }, + "minecraft:disc_fragment_5": { + "id": "minecraft:music_disc_13", + "name": "1.19 Disc Fragment" } }, "particles": { @@ -610,6 +623,12 @@ "enchantments": { "minecraft:swift_sneak": "minecraft:soul_speed" }, + "paintings": { + "minecraft:earth": "minecraft:void", + "minecraft:fire": "minecraft:void", + "minecraft:water": "minecraft:void", + "minecraft:wind": "minecraft:void" + }, "entitynames": { "warden": "Warden", "frog": "Frog", diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a484fa44..284b3872 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "4.3.0-22w14a-SNAPSHOT" +viaver = "4.3.0-22w16b-SNAPSHOT" # Common provided netty = "4.0.20.Final"