Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Cancel player input if not in a vehicle, fix shift/sprint input
Dieser Commit ist enthalten in:
Ursprung
a88e2f3fb5
Commit
75537d3f85
@ -44,6 +44,7 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.ComponentRewriter1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage;
|
||||
import com.viaversion.viaversion.rewriter.AttributeRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
@ -134,6 +135,7 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
|
||||
@Override
|
||||
public void init(final UserConnection connection) {
|
||||
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
|
||||
connection.put(new ClientVehicleStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,6 +34,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
|
||||
import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
@ -120,6 +121,8 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
|
||||
wrapper.write(Types.VAR_INT, 64); // Sea level
|
||||
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world);
|
||||
|
||||
wrapper.user().get(ClientVehicleStorage.class).clear();
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.PLAYER_POSITION, wrapper -> {
|
||||
@ -150,22 +153,53 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
wrapper.set(Types.VAR_INT, 0, teleportId);
|
||||
});
|
||||
|
||||
// Previously only used while in a vehicle, now always sent.
|
||||
// The server will ignore it if not in a vehicle, so we can always pass it through
|
||||
protocol.registerClientbound(ClientboundPackets1_21.SET_PASSENGERS, wrapper -> {
|
||||
final int vehicleId = wrapper.passthrough(Types.VAR_INT);
|
||||
final int[] passengerIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
|
||||
final ClientVehicleStorage storage = wrapper.user().get(ClientVehicleStorage.class);
|
||||
if (vehicleId == storage.vehicleId()) {
|
||||
storage.clear();
|
||||
}
|
||||
|
||||
final int clientEntityId = tracker(wrapper.user()).clientEntityId();
|
||||
for (final int passenger : passengerIds) {
|
||||
if (passenger == clientEntityId) {
|
||||
storage.setVehicleId(vehicleId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
protocol.appendClientbound(ClientboundPackets1_21.REMOVE_ENTITIES, wrapper -> {
|
||||
final ClientVehicleStorage vehicleStorage = wrapper.user().get(ClientVehicleStorage.class);
|
||||
final int[] entityIds = wrapper.get(Types.VAR_INT_ARRAY_PRIMITIVE, 0);
|
||||
for (final int entityId : entityIds) {
|
||||
if (entityId == vehicleStorage.vehicleId()) {
|
||||
vehicleStorage.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_21_2.PLAYER_INPUT, wrapper -> {
|
||||
// Previously only used while in a vehicle, now always sent
|
||||
// Filter them appropriately
|
||||
if (wrapper.user().get(ClientVehicleStorage.class).vehicleId() == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
final byte flags = wrapper.read(Types.BYTE);
|
||||
final boolean left = (flags & 4) != 0;
|
||||
final boolean right = (flags & 8) != 0;
|
||||
final boolean left = (flags & 1 << 2) != 0;
|
||||
final boolean right = (flags & 1 << 3) != 0;
|
||||
wrapper.write(Types.FLOAT, left ? IMPULSE : (right ? -IMPULSE : 0F));
|
||||
|
||||
final boolean forward = (flags & 1) != 0;
|
||||
final boolean backward = (flags & 2) != 0;
|
||||
final boolean forward = (flags & 1 << 0) != 0;
|
||||
final boolean backward = (flags & 1 << 1) != 0;
|
||||
wrapper.write(Types.FLOAT, forward ? IMPULSE : (backward ? -IMPULSE : 0F));
|
||||
|
||||
byte updatedFlags = 0;
|
||||
if ((flags & 1) != 0) {
|
||||
if ((flags & 1 << 4) != 0) {
|
||||
updatedFlags |= 1;
|
||||
} else if ((flags & 2) != 0) {
|
||||
}
|
||||
if ((flags & 1 << 5) != 0) {
|
||||
updatedFlags |= 2;
|
||||
}
|
||||
wrapper.write(Types.BYTE, updatedFlags);
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 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.v1_21to1_21_2.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class ClientVehicleStorage implements StorableObject {
|
||||
|
||||
private int vehicleId = -1;
|
||||
|
||||
public int vehicleId() {
|
||||
return this.vehicleId;
|
||||
}
|
||||
|
||||
public void setVehicleId(final int vehicleId) {
|
||||
this.vehicleId = vehicleId;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.vehicleId = -1;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren