Archived
0

новый пакет PlayerDiggingPacket

This commit is contained in:
2018-08-18 23:11:08 +03:00
parent b6120736f3
commit 02e348d8ce
2 changed files with 76 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ public enum State {
.put(0x0E, PlayerPositionAndLookPacket.class) .put(0x0E, PlayerPositionAndLookPacket.class)
.put(0x0F, PlayerLookPacket.class) .put(0x0F, PlayerLookPacket.class)
.put(0x13, PlayerAbilitiesPacket.class) .put(0x13, PlayerAbilitiesPacket.class)
.put(0x14, PlayerDiggingPacket.class)
.put(0x15, EntityActionPacket.class) .put(0x15, EntityActionPacket.class)
.put(0x1A, HeldItemChangePacket.class) .put(0x1A, HeldItemChangePacket.class)
.put(0x1D, AnimationPacket.class) .put(0x1D, AnimationPacket.class)

View File

@@ -0,0 +1,75 @@
package mc.core.network.proto_1_12_2.packets;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import mc.core.Location;
import mc.core.network.CSPacket;
import mc.core.network.NetInputStream;
import mc.core.utils.CompactedCoords;
import java.util.Arrays;
@Getter
@ToString
public class PlayerDiggingPacket implements CSPacket {
@RequiredArgsConstructor
public enum Status {
STARTED_DIGGING(0),
CANCELLED_DIGGING(1),
FINISHED_DIGGING(2),
DROP_ITEM_STACK(3),
DROP_ITEM(4),
/* Indicates that the currently held item should have its
* state updated such as eating food, pulling back bows,
* using buckets, etc. Location is always set to 0/0/0,
* Face is always set to -Y.
*/
SHOOT_ARROW(5),
FINISH_EATING(5),
SWAP_ITEM_IN_HAND(6);
public static Status getById(final int id) {
return Arrays.stream(Status.values())
.filter(status -> status.id == id)
.findFirst()
.orElse(null);
}
@Getter
private final int id;
}
@RequiredArgsConstructor
public enum Face {
BOTTOM(0), // -Y
TOP(1), // +Y
NORTH(2), // -Z
SOUTH(3), // +Z
WEST(4), // -X
EAST(5); // +X
public static Face getById(final int id) {
return Arrays.stream(Face.values())
.filter(status -> status.id == id)
.findFirst()
.orElse(null);
}
@Getter
private final int id;
}
private Status status;
private Location location;
private Face face;
@Override
public void readSelf(NetInputStream netStream) {
status = Status.getById(netStream.readVarInt());
long compactCoord = netStream.readLong();
double[] xyz = CompactedCoords.uncompressXYZ(compactCoord);
location = new Location(xyz[0], xyz[1], xyz[2], null);
face = Face.getById(netStream.readByte());
}
}