Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Handle PLAYER_ROTATION packet using PLAYER_LOOK_AT
Dieser Commit ist enthalten in:
Ursprung
1b9d53af2a
Commit
545365786f
@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewr
|
|||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage;
|
||||||
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
@ -153,6 +154,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPac
|
|||||||
user.put(new ItemTagStorage());
|
user.put(new ItemTagStorage());
|
||||||
user.put(new SneakingStorage());
|
user.put(new SneakingStorage());
|
||||||
user.put(new RecipeStorage(this));
|
user.put(new RecipeStorage(this));
|
||||||
|
user.put(new PlayerStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
|
|||||||
import com.viaversion.nbt.tag.Tag;
|
import com.viaversion.nbt.tag.Tag;
|
||||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
|
||||||
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage;
|
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2;
|
||||||
@ -140,9 +141,30 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
|||||||
updateRotation(wrapper);
|
updateRotation(wrapper);
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_POSITION, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_LOOK_AT, wrapper -> {
|
||||||
// TODO Send PLAYER_LOOK_AT via currently tracked location
|
wrapper.passthrough(Types.FLOAT); // Y rot
|
||||||
wrapper.cancel();
|
wrapper.passthrough(Types.FLOAT); // X rot
|
||||||
|
|
||||||
|
final double yaw = Math.toRadians(wrapper.get(Types.FLOAT, 0));
|
||||||
|
final double pitch = Math.toRadians(wrapper.get(Types.FLOAT, 1));
|
||||||
|
|
||||||
|
final double factor = -Math.cos(-pitch);
|
||||||
|
final double deltaX = Math.sin(-yaw - (float) Math.PI) * factor;
|
||||||
|
final double deltaY = Math.sin(-pitch);
|
||||||
|
final double deltaZ = Math.cos(-yaw - (float) Math.PI) * factor;
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
wrapper.write(Types.VAR_INT, 0); // From anchor
|
||||||
|
wrapper.write(Types.DOUBLE, storage.x() + deltaX); // X
|
||||||
|
wrapper.write(Types.DOUBLE, storage.y() + deltaY); // Y
|
||||||
|
wrapper.write(Types.DOUBLE, storage.z() + deltaZ); // Z
|
||||||
|
wrapper.write(Types.BOOLEAN, false); // At entity
|
||||||
|
|
||||||
|
final PacketWrapper entityMotionPacket = PacketWrapper.create(ServerboundPackets1_21_2.MOVE_PLAYER_ROT, wrapper.user());
|
||||||
|
entityMotionPacket.write(Types.FLOAT, wrapper.get(Types.FLOAT, 0));
|
||||||
|
entityMotionPacket.write(Types.FLOAT, wrapper.get(Types.FLOAT, 1));
|
||||||
|
entityMotionPacket.write(Types.UNSIGNED_BYTE, (short) 0); // On ground and horizontal collision
|
||||||
|
entityMotionPacket.sendToServer(Protocol1_21_2To1_21.class);
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21_2.TELEPORT_ENTITY, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21_2.TELEPORT_ENTITY, wrapper -> {
|
||||||
@ -176,6 +198,10 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
|||||||
wrapper.passthrough(Types.FLOAT); // Y rot
|
wrapper.passthrough(Types.FLOAT); // Y rot
|
||||||
wrapper.passthrough(Types.FLOAT); // X rot
|
wrapper.passthrough(Types.FLOAT); // X rot
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
storage.setCoordinates(wrapper, true);
|
||||||
|
storage.setRotation(wrapper);
|
||||||
|
|
||||||
// Just keep the new values in there
|
// Just keep the new values in there
|
||||||
final int relativeArguments = wrapper.read(Types.INT);
|
final int relativeArguments = wrapper.read(Types.INT);
|
||||||
wrapper.write(Types.BYTE, (byte) relativeArguments);
|
wrapper.write(Types.BYTE, (byte) relativeArguments);
|
||||||
@ -271,6 +297,9 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
|||||||
wrapper.passthrough(Types.DOUBLE); // Y
|
wrapper.passthrough(Types.DOUBLE); // Y
|
||||||
wrapper.passthrough(Types.DOUBLE); // Z
|
wrapper.passthrough(Types.DOUBLE); // Z
|
||||||
fixOnGround(wrapper);
|
fixOnGround(wrapper);
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
storage.setCoordinates(wrapper, false);
|
||||||
});
|
});
|
||||||
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> {
|
||||||
wrapper.passthrough(Types.DOUBLE); // X
|
wrapper.passthrough(Types.DOUBLE); // X
|
||||||
@ -279,13 +308,31 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
|||||||
wrapper.passthrough(Types.FLOAT); // Yaw
|
wrapper.passthrough(Types.FLOAT); // Yaw
|
||||||
wrapper.passthrough(Types.FLOAT); // Pitch
|
wrapper.passthrough(Types.FLOAT); // Pitch
|
||||||
fixOnGround(wrapper);
|
fixOnGround(wrapper);
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
storage.setCoordinates(wrapper, false);
|
||||||
|
storage.setRotation(wrapper);
|
||||||
});
|
});
|
||||||
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> {
|
||||||
wrapper.passthrough(Types.FLOAT); // Yaw
|
wrapper.passthrough(Types.FLOAT); // Yaw
|
||||||
wrapper.passthrough(Types.FLOAT); // Pitch
|
wrapper.passthrough(Types.FLOAT); // Pitch
|
||||||
fixOnGround(wrapper);
|
fixOnGround(wrapper);
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
storage.setRotation(wrapper);
|
||||||
});
|
});
|
||||||
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround);
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround);
|
||||||
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_VEHICLE, wrapper -> {
|
||||||
|
wrapper.passthrough(Types.DOUBLE); // X
|
||||||
|
wrapper.passthrough(Types.DOUBLE); // Y
|
||||||
|
wrapper.passthrough(Types.DOUBLE); // Z
|
||||||
|
wrapper.passthrough(Types.FLOAT); // Yaw
|
||||||
|
wrapper.passthrough(Types.FLOAT); // Pitch
|
||||||
|
|
||||||
|
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
|
||||||
|
storage.setCoordinates(wrapper, false);
|
||||||
|
storage.setRotation(wrapper);
|
||||||
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> {
|
||||||
final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM);
|
final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM);
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||||
|
* 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.viabackwards.protocol.v1_21_2to1_21.storage;
|
||||||
|
|
||||||
|
import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage;
|
||||||
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
|
|
||||||
|
public final class PlayerStorage extends PlayerPositionStorage {
|
||||||
|
|
||||||
|
private float yaw;
|
||||||
|
private float pitch;
|
||||||
|
|
||||||
|
public float yaw() {
|
||||||
|
return yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float pitch() {
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRotation(final PacketWrapper wrapper) {
|
||||||
|
this.yaw = wrapper.get(Types.FLOAT, 0);
|
||||||
|
this.pitch = wrapper.get(Types.FLOAT, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren