PlayerBlockPlacementPacket
This commit is contained in:
@@ -65,7 +65,8 @@ public enum State {
|
|||||||
Map.entry(0x13, CPlayerAbilitiesPacket.class),
|
Map.entry(0x13, CPlayerAbilitiesPacket.class),
|
||||||
Map.entry(0x14, PlayerDiggingAndMorePacket.class),
|
Map.entry(0x14, PlayerDiggingAndMorePacket.class),
|
||||||
Map.entry(0x15, EntityActionPacket.class),
|
Map.entry(0x15, EntityActionPacket.class),
|
||||||
Map.entry(0x1D, HandAnimationPacket.class)
|
Map.entry(0x1D, HandAnimationPacket.class),
|
||||||
|
Map.entry(0x1F, PlayerBlockPlacementPacket.class)
|
||||||
),
|
),
|
||||||
// server side
|
// server side
|
||||||
Map.of(
|
Map.of(
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package mc.protocol.packets.play.client;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import mc.protocol.buffer.NetByteBuf;
|
||||||
|
import mc.protocol.model.BlockLocation;
|
||||||
|
import mc.protocol.packets.ClientSidePacket;
|
||||||
|
import mc.protocol.utils.Face;
|
||||||
|
import mc.protocol.utils.Hand;
|
||||||
|
import mc.protocol.utils.SerializeUtil;
|
||||||
|
import mc.utils.vector.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Игрок размещает блок.
|
||||||
|
*
|
||||||
|
* <p>Структура пакета</p>
|
||||||
|
* <pre>
|
||||||
|
* | FIELD | TYPE | NOTES |
|
||||||
|
* |-------------------|----------|---------------------------------------------------------------------------|
|
||||||
|
* | Location | Position | Позиция блока |
|
||||||
|
* | Face | VarInt | Сторона блока, к которому ставится новый блок |
|
||||||
|
* | Hand | VarInt | Используемая рука |
|
||||||
|
* | | | - 0: основная рука |
|
||||||
|
* | | | - 1: левая рука |
|
||||||
|
* | Cursor Position X | Float | Положение перекрестия на блоке, от 0 до 1 с увеличением с West на East. |
|
||||||
|
* | Cursor Position Y | Float | Положение перекрестия на блоке, от 0 до 1 с увеличением с Bottom на Top. |
|
||||||
|
* | Cursor Position Z | Float | Положение перекрестия на блоке, от 0 до 1 с увеличением с North на South. |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>Значения Стороны блока</p>
|
||||||
|
* <pre>
|
||||||
|
* | VALUE | OFFCET | FACE |
|
||||||
|
* |-------|--------|--------|
|
||||||
|
* | 0 | -Y | Bottom |
|
||||||
|
* | 1 | +Y | Top |
|
||||||
|
* | 2 | -Z | North |
|
||||||
|
* | 3 | +Z | South |
|
||||||
|
* | 4 | -X | West |
|
||||||
|
* | 5 | +X | East |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_Block_Placement">Player Block Placement</a>
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
public class PlayerBlockPlacementPacket implements ClientSidePacket {
|
||||||
|
|
||||||
|
private BlockLocation location;
|
||||||
|
private Face face;
|
||||||
|
private Hand hand;
|
||||||
|
private Vector3f cursorPosition;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSelf(NetByteBuf netByteBuf) {
|
||||||
|
this.location = SerializeUtil.long2location(netByteBuf.readLong());
|
||||||
|
this.face = Face.valueById(netByteBuf.readVarInt());
|
||||||
|
this.hand = Hand.valueById(netByteBuf.readVarInt());
|
||||||
|
|
||||||
|
this.cursorPosition = new Vector3f();
|
||||||
|
this.cursorPosition.set(
|
||||||
|
netByteBuf.readFloat(),
|
||||||
|
netByteBuf.readFloat(),
|
||||||
|
netByteBuf.readFloat()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void passivate() {
|
||||||
|
this.location = null;
|
||||||
|
this.face = null;
|
||||||
|
this.hand = null;
|
||||||
|
this.cursorPosition = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
53
utils/src/main/java/mc/utils/vector/Vector3f.java
Normal file
53
utils/src/main/java/mc/utils/vector/Vector3f.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package mc.utils.vector;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
public class Vector3f {
|
||||||
|
|
||||||
|
private float x;
|
||||||
|
private float y;
|
||||||
|
private float z;
|
||||||
|
|
||||||
|
public Vector3f(float x, float y, float z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f(Vector3f vector3f) {
|
||||||
|
this(vector3f.getX(), vector3f.getY(), vector3f.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f() {
|
||||||
|
this(0f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(float x, float y, float z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Vector3f vector3f) {
|
||||||
|
this.set(vector3f.getX(), vector3f.getY(), vector3f.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(float x, float y, float z) {
|
||||||
|
this.x += x;
|
||||||
|
this.y += y;
|
||||||
|
this.z += z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Vector3f vector3f) {
|
||||||
|
this.add(vector3f.getX(), vector3f.getY(), vector3f.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f copy() {
|
||||||
|
return new Vector3f(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user