ServerboundMovePlayerPacket.java

net.minecraft.network.protocol.game.ServerboundMovePlayerPacket

信息

  • 全限定名:net.minecraft.network.protocol.game.ServerboundMovePlayerPacket
  • 类型:public abstract class
  • 包:net.minecraft.network.protocol.game
  • 源码路径:src/main/java/net/minecraft/network/protocol/game/ServerboundMovePlayerPacket.java
  • 起始行号:L9
  • 实现:Packet
  • 职责:

    TODO

字段/常量

  • FLAG_ON_GROUND

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L10
    • 说明:

      TODO

  • FLAG_HORIZONTAL_COLLISION

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L11
    • 说明:

      TODO

  • x

    • 类型: double
    • 修饰符: protected final
    • 源码定位: L12
    • 说明:

      TODO

  • y

    • 类型: double
    • 修饰符: protected final
    • 源码定位: L13
    • 说明:

      TODO

  • z

    • 类型: double
    • 修饰符: protected final
    • 源码定位: L14
    • 说明:

      TODO

  • yRot

    • 类型: float
    • 修饰符: protected final
    • 源码定位: L15
    • 说明:

      TODO

  • xRot

    • 类型: float
    • 修饰符: protected final
    • 源码定位: L16
    • 说明:

      TODO

  • onGround

    • 类型: boolean
    • 修饰符: protected final
    • 源码定位: L17
    • 说明:

      TODO

  • horizontalCollision

    • 类型: boolean
    • 修饰符: protected final
    • 源码定位: L18
    • 说明:

      TODO

  • hasPos

    • 类型: boolean
    • 修饰符: protected final
    • 源码定位: L19
    • 说明:

      TODO

  • hasRot

    • 类型: boolean
    • 修饰符: protected final
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.Pos

    • 类型: class
    • 修饰符: public static
    • 源码定位: L100
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.PosRot

    • 类型: class
    • 修饰符: public static
    • 源码定位: L136
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.Rot

    • 类型: class
    • 修饰符: public static
    • 源码定位: L176
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.StatusOnly

    • 类型: class
    • 修饰符: public static
    • 源码定位: L206
    • 说明:

      TODO

构造器

protected ServerboundMovePlayerPacket(double x, double y, double z, float yRot, float xRot, boolean onGround, boolean horizontalCollision, boolean hasPos, boolean hasRot) @ L43

  • 构造器名:ServerboundMovePlayerPacket
  • 源码定位:L43
  • 修饰符:protected

参数:

  • x: double
  • y: double
  • z: double
  • yRot: float
  • xRot: float
  • onGround: boolean
  • horizontalCollision: boolean
  • hasPos: boolean
  • hasRot: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

private static int packFlags(boolean onGround, boolean horizontalCollision) @ L22

  • 方法名:packFlags
  • 源码定位:L22
  • 返回类型:int
  • 修饰符:private static

参数:

  • onGround: boolean
  • horizontalCollision: boolean

说明:

TODO

private static boolean unpackOnGround(int flags) @ L35

  • 方法名:unpackOnGround
  • 源码定位:L35
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • flags: int

说明:

TODO

private static boolean unpackHorizontalCollision(int flags) @ L39

  • 方法名:unpackHorizontalCollision
  • 源码定位:L39
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • flags: int

说明:

TODO

public abstract PacketType<?extends ServerboundMovePlayerPacket> type() @ L57

  • 方法名:type
  • 源码定位:L57
  • 返回类型:PacketType<?extends ServerboundMovePlayerPacket>
  • 修饰符:public abstract

参数:

说明:

TODO

public void handle(ServerGamePacketListener listener) @ L60

  • 方法名:handle
  • 源码定位:L60
  • 返回类型:void
  • 修饰符:public

参数:

  • listener: ServerGamePacketListener

说明:

TODO

public double getX(double fallback) @ L64

  • 方法名:getX
  • 源码定位:L64
  • 返回类型:double
  • 修饰符:public

参数:

  • fallback: double

说明:

TODO

public double getY(double fallback) @ L68

  • 方法名:getY
  • 源码定位:L68
  • 返回类型:double
  • 修饰符:public

参数:

  • fallback: double

说明:

TODO

public double getZ(double fallback) @ L72

  • 方法名:getZ
  • 源码定位:L72
  • 返回类型:double
  • 修饰符:public

参数:

  • fallback: double

说明:

TODO

public float getYRot(float fallback) @ L76

  • 方法名:getYRot
  • 源码定位:L76
  • 返回类型:float
  • 修饰符:public

参数:

  • fallback: float

说明:

TODO

public float getXRot(float fallback) @ L80

  • 方法名:getXRot
  • 源码定位:L80
  • 返回类型:float
  • 修饰符:public

参数:

  • fallback: float

说明:

TODO

public boolean isOnGround() @ L84

  • 方法名:isOnGround
  • 源码定位:L84
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean horizontalCollision() @ L88

  • 方法名:horizontalCollision
  • 源码定位:L88
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean hasPosition() @ L92

  • 方法名:hasPosition
  • 源码定位:L92
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean hasRotation() @ L96

  • 方法名:hasRotation
  • 源码定位:L96
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

代码

public abstract class ServerboundMovePlayerPacket implements Packet<ServerGamePacketListener> {
    private static final int FLAG_ON_GROUND = 1;
    private static final int FLAG_HORIZONTAL_COLLISION = 2;
    protected final double x;
    protected final double y;
    protected final double z;
    protected final float yRot;
    protected final float xRot;
    protected final boolean onGround;
    protected final boolean horizontalCollision;
    protected final boolean hasPos;
    protected final boolean hasRot;
 
    private static int packFlags(boolean onGround, boolean horizontalCollision) {
        int flags = 0;
        if (onGround) {
            flags |= 1;
        }
 
        if (horizontalCollision) {
            flags |= 2;
        }
 
        return flags;
    }
 
    private static boolean unpackOnGround(int flags) {
        return (flags & 1) != 0;
    }
 
    private static boolean unpackHorizontalCollision(int flags) {
        return (flags & 2) != 0;
    }
 
    protected ServerboundMovePlayerPacket(
        double x, double y, double z, float yRot, float xRot, boolean onGround, boolean horizontalCollision, boolean hasPos, boolean hasRot
    ) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.yRot = yRot;
        this.xRot = xRot;
        this.onGround = onGround;
        this.horizontalCollision = horizontalCollision;
        this.hasPos = hasPos;
        this.hasRot = hasRot;
    }
 
    @Override
    public abstract PacketType<? extends ServerboundMovePlayerPacket> type();
 
    public void handle(ServerGamePacketListener listener) {
        listener.handleMovePlayer(this);
    }
 
    public double getX(double fallback) {
        return this.hasPos ? this.x : fallback;
    }
 
    public double getY(double fallback) {
        return this.hasPos ? this.y : fallback;
    }
 
    public double getZ(double fallback) {
        return this.hasPos ? this.z : fallback;
    }
 
    public float getYRot(float fallback) {
        return this.hasRot ? this.yRot : fallback;
    }
 
    public float getXRot(float fallback) {
        return this.hasRot ? this.xRot : fallback;
    }
 
    public boolean isOnGround() {
        return this.onGround;
    }
 
    public boolean horizontalCollision() {
        return this.horizontalCollision;
    }
 
    public boolean hasPosition() {
        return this.hasPos;
    }
 
    public boolean hasRotation() {
        return this.hasRot;
    }
 
    public static class Pos extends ServerboundMovePlayerPacket {
        public static final StreamCodec<FriendlyByteBuf, ServerboundMovePlayerPacket.Pos> STREAM_CODEC = Packet.codec(
            ServerboundMovePlayerPacket.Pos::write, ServerboundMovePlayerPacket.Pos::read
        );
 
        public Pos(Vec3 pos, boolean onGround, boolean horizontalCollision) {
            super(pos.x, pos.y, pos.z, 0.0F, 0.0F, onGround, horizontalCollision, true, false);
        }
 
        public Pos(double x, double y, double z, boolean onGround, boolean horizontalCollision) {
            super(x, y, z, 0.0F, 0.0F, onGround, horizontalCollision, true, false);
        }
 
        private static ServerboundMovePlayerPacket.Pos read(FriendlyByteBuf input) {
            double x = input.readDouble();
            double y = input.readDouble();
            double z = input.readDouble();
            short flags = input.readUnsignedByte();
            boolean onGround = ServerboundMovePlayerPacket.unpackOnGround(flags);
            boolean horizontalCollision = ServerboundMovePlayerPacket.unpackHorizontalCollision(flags);
            return new ServerboundMovePlayerPacket.Pos(x, y, z, onGround, horizontalCollision);
        }
 
        private void write(FriendlyByteBuf output) {
            output.writeDouble(this.x);
            output.writeDouble(this.y);
            output.writeDouble(this.z);
            output.writeByte(ServerboundMovePlayerPacket.packFlags(this.onGround, this.horizontalCollision));
        }
 
        @Override
        public PacketType<ServerboundMovePlayerPacket.Pos> type() {
            return GamePacketTypes.SERVERBOUND_MOVE_PLAYER_POS;
        }
    }
 
    public static class PosRot extends ServerboundMovePlayerPacket {
        public static final StreamCodec<FriendlyByteBuf, ServerboundMovePlayerPacket.PosRot> STREAM_CODEC = Packet.codec(
            ServerboundMovePlayerPacket.PosRot::write, ServerboundMovePlayerPacket.PosRot::read
        );
 
        public PosRot(Vec3 pos, float yRot, float xRot, boolean onGround, boolean horizontalCollision) {
            super(pos.x, pos.y, pos.z, yRot, xRot, onGround, horizontalCollision, true, true);
        }
 
        public PosRot(double x, double y, double z, float yRot, float xRot, boolean onGround, boolean horizontalCollision) {
            super(x, y, z, yRot, xRot, onGround, horizontalCollision, true, true);
        }
 
        private static ServerboundMovePlayerPacket.PosRot read(FriendlyByteBuf input) {
            double x = input.readDouble();
            double y = input.readDouble();
            double z = input.readDouble();
            float yRot = input.readFloat();
            float xRot = input.readFloat();
            short flags = input.readUnsignedByte();
            boolean onGround = ServerboundMovePlayerPacket.unpackOnGround(flags);
            boolean horizontalCollision = ServerboundMovePlayerPacket.unpackHorizontalCollision(flags);
            return new ServerboundMovePlayerPacket.PosRot(x, y, z, yRot, xRot, onGround, horizontalCollision);
        }
 
        private void write(FriendlyByteBuf output) {
            output.writeDouble(this.x);
            output.writeDouble(this.y);
            output.writeDouble(this.z);
            output.writeFloat(this.yRot);
            output.writeFloat(this.xRot);
            output.writeByte(ServerboundMovePlayerPacket.packFlags(this.onGround, this.horizontalCollision));
        }
 
        @Override
        public PacketType<ServerboundMovePlayerPacket.PosRot> type() {
            return GamePacketTypes.SERVERBOUND_MOVE_PLAYER_POS_ROT;
        }
    }
 
    public static class Rot extends ServerboundMovePlayerPacket {
        public static final StreamCodec<FriendlyByteBuf, ServerboundMovePlayerPacket.Rot> STREAM_CODEC = Packet.codec(
            ServerboundMovePlayerPacket.Rot::write, ServerboundMovePlayerPacket.Rot::read
        );
 
        public Rot(float yRot, float xRot, boolean onGround, boolean horizontalCollision) {
            super(0.0, 0.0, 0.0, yRot, xRot, onGround, horizontalCollision, false, true);
        }
 
        private static ServerboundMovePlayerPacket.Rot read(FriendlyByteBuf input) {
            float yRot = input.readFloat();
            float xRot = input.readFloat();
            short flags = input.readUnsignedByte();
            boolean onGround = ServerboundMovePlayerPacket.unpackOnGround(flags);
            boolean horizontalCollision = ServerboundMovePlayerPacket.unpackHorizontalCollision(flags);
            return new ServerboundMovePlayerPacket.Rot(yRot, xRot, onGround, horizontalCollision);
        }
 
        private void write(FriendlyByteBuf output) {
            output.writeFloat(this.yRot);
            output.writeFloat(this.xRot);
            output.writeByte(ServerboundMovePlayerPacket.packFlags(this.onGround, this.horizontalCollision));
        }
 
        @Override
        public PacketType<ServerboundMovePlayerPacket.Rot> type() {
            return GamePacketTypes.SERVERBOUND_MOVE_PLAYER_ROT;
        }
    }
 
    public static class StatusOnly extends ServerboundMovePlayerPacket {
        public static final StreamCodec<FriendlyByteBuf, ServerboundMovePlayerPacket.StatusOnly> STREAM_CODEC = Packet.codec(
            ServerboundMovePlayerPacket.StatusOnly::write, ServerboundMovePlayerPacket.StatusOnly::read
        );
 
        public StatusOnly(boolean onGround, boolean horizontalCollision) {
            super(0.0, 0.0, 0.0, 0.0F, 0.0F, onGround, horizontalCollision, false, false);
        }
 
        private static ServerboundMovePlayerPacket.StatusOnly read(FriendlyByteBuf input) {
            short flags = input.readUnsignedByte();
            boolean onGround = ServerboundMovePlayerPacket.unpackOnGround(flags);
            boolean horizontalCollision = ServerboundMovePlayerPacket.unpackHorizontalCollision(flags);
            return new ServerboundMovePlayerPacket.StatusOnly(onGround, horizontalCollision);
        }
 
        private void write(FriendlyByteBuf output) {
            output.writeByte(ServerboundMovePlayerPacket.packFlags(this.onGround, this.horizontalCollision));
        }
 
        @Override
        public PacketType<ServerboundMovePlayerPacket.StatusOnly> type() {
            return GamePacketTypes.SERVERBOUND_MOVE_PLAYER_STATUS_ONLY;
        }
    }
}

引用的其他类