3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Properly handle dismount in PLAYER_POSITION packet (#3272)

Dieser Commit ist enthalten in:
RK_01 2023-03-21 21:53:44 +01:00 committet von GitHub
Ursprung 23f045feee
Commit 641171a14f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 91 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPac
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data.MappingData;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage.PlayerVehicleTracker;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
@ -105,6 +106,8 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
@Override
public void init(final UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, Entity1_19_4Types.PLAYER));
user.put(new PlayerVehicleTracker(user));
}
@Override
@ -121,4 +124,4 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
}
}

Datei anzeigen

@ -24,6 +24,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
@ -31,6 +32,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage.PlayerVehicleTracker;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3, Protocol1_19_4To1_19_3> {
@ -55,6 +57,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
handler(dimensionDataHandler());
handler(biomeSizeTracker());
handler(worldDataTrackerHandlerByKey());
handler(playerTrackerHandler());
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag damageTypeRegistry = protocol.getMappingData().damageTypesRegistry();
@ -82,7 +85,49 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
map(Type.FLOAT); // Pitch
map(Type.BYTE); // Relative arguments
map(Type.VAR_INT); // Id
read(Type.BOOLEAN); // Dismount vehicle
handler(wrapper -> {
if (wrapper.read(Type.BOOLEAN)) { // Dismount vehicle
final PlayerVehicleTracker playerVehicleTracker = wrapper.user().get(PlayerVehicleTracker.class);
if (playerVehicleTracker.getVehicleId() != -1) {
final PacketWrapper bundleStart = wrapper.create(ClientboundPackets1_19_4.BUNDLE);
bundleStart.send(Protocol1_19_4To1_19_3.class);
final PacketWrapper setPassengers = wrapper.create(ClientboundPackets1_19_4.SET_PASSENGERS);
setPassengers.write(Type.VAR_INT, playerVehicleTracker.getVehicleId()); // vehicle id
setPassengers.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[0]); // passenger ids
setPassengers.send(Protocol1_19_4To1_19_3.class);
wrapper.send(Protocol1_19_4To1_19_3.class);
wrapper.cancel();
final PacketWrapper bundleEnd = wrapper.create(ClientboundPackets1_19_4.BUNDLE);
bundleEnd.send(Protocol1_19_4To1_19_3.class);
playerVehicleTracker.setVehicleId(-1);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_19_3.SET_PASSENGERS, new PacketHandlers() {
@Override
protected void register() {
map(Type.VAR_INT); // vehicle id
map(Type.VAR_INT_ARRAY_PRIMITIVE); // passenger ids
handler(wrapper -> {
final PlayerVehicleTracker playerVehicleTracker = wrapper.user().get(PlayerVehicleTracker.class);
final int clientEntityId = wrapper.user().getEntityTracker(Protocol1_19_4To1_19_3.class).clientEntityId();
final int vehicleId = wrapper.get(Type.VAR_INT, 0);
if (playerVehicleTracker.getVehicleId() == vehicleId) {
playerVehicleTracker.setVehicleId(-1);
}
final int[] passengerIds = wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0);
for (int passengerId : passengerIds) {
if (passengerId == clientEntityId) {
playerVehicleTracker.setVehicleId(vehicleId);
break;
}
}
});
}
});
@ -109,6 +154,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
map(Type.STRING); // Dimension
map(Type.STRING); // World
handler(worldDataTrackerHandlerByKey());
handler(wrapper -> wrapper.user().put(new PlayerVehicleTracker(wrapper.user())));
}
});
@ -188,4 +234,4 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
public EntityType typeFromId(final int type) {
return Entity1_19_4Types.getTypeFromId(type);
}
}
}

Datei anzeigen

@ -0,0 +1,39 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class PlayerVehicleTracker extends StoredObject {
private int vehicleId = -1;
public PlayerVehicleTracker(final UserConnection user) {
super(user);
}
public int getVehicleId() {
return this.vehicleId;
}
public void setVehicleId(final int vehicleId) {
this.vehicleId = vehicleId;
}
}