minecraft-src/net/minecraft/network/protocol/game/ServerboundMoveVehiclePacket.java
2025-07-04 01:41:11 +03:00

77 lines
1.9 KiB
Java

package net.minecraft.network.protocol.game;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketType;
import net.minecraft.world.entity.Entity;
public class ServerboundMoveVehiclePacket implements Packet<ServerGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ServerboundMoveVehiclePacket> STREAM_CODEC = Packet.codec(
ServerboundMoveVehiclePacket::write, ServerboundMoveVehiclePacket::new
);
private final double x;
private final double y;
private final double z;
private final float yRot;
private final float xRot;
public ServerboundMoveVehiclePacket(Entity vehicle) {
this.x = vehicle.getX();
this.y = vehicle.getY();
this.z = vehicle.getZ();
this.yRot = vehicle.getYRot();
this.xRot = vehicle.getXRot();
}
private ServerboundMoveVehiclePacket(FriendlyByteBuf buffer) {
this.x = buffer.readDouble();
this.y = buffer.readDouble();
this.z = buffer.readDouble();
this.yRot = buffer.readFloat();
this.xRot = buffer.readFloat();
}
/**
* Writes the raw packet data to the data stream.
*/
private void write(FriendlyByteBuf buffer) {
buffer.writeDouble(this.x);
buffer.writeDouble(this.y);
buffer.writeDouble(this.z);
buffer.writeFloat(this.yRot);
buffer.writeFloat(this.xRot);
}
@Override
public PacketType<ServerboundMoveVehiclePacket> type() {
return GamePacketTypes.SERVERBOUND_MOVE_VEHICLE;
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void handle(ServerGamePacketListener handler) {
handler.handleMoveVehicle(this);
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public double getZ() {
return this.z;
}
public float getYRot() {
return this.yRot;
}
public float getXRot() {
return this.xRot;
}
}