From fcefba29acf1ad4ad7293288c866a34a73984723 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sat, 18 Aug 2018 22:22:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82:=20EntityActionPacket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/core/network/proto_1_12_2/State.java | 1 + .../packets/EntityActionPacket.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/EntityActionPacket.java diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/State.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/State.java index 8d52cf5..9ff4d79 100644 --- a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/State.java +++ b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/State.java @@ -80,6 +80,7 @@ public enum State { .put(0x0D, PlayerPositionPacket.class) .put(0x0E, PlayerPositionAndLookPacket.class) .put(0x0F, PlayerLookPacket.class) + .put(0x15, EntityActionPacket.class) .put(0x1A, HeldItemChangePacket.class) .put(0x1D, AnimationPacket.class) .build(), diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/EntityActionPacket.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/EntityActionPacket.java new file mode 100644 index 0000000..0e02a01 --- /dev/null +++ b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/EntityActionPacket.java @@ -0,0 +1,45 @@ +package mc.core.network.proto_1_12_2.packets; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import mc.core.network.CSPacket; +import mc.core.network.NetInputStream; + +import java.util.Arrays; + +@Getter +public class EntityActionPacket implements CSPacket { + @RequiredArgsConstructor + public enum Action { + START_SNEAKING(0), + STOP_SNEAKING(1), + LEAVE_BED(2), // Leave bed is only sent when the “Leave Bed” button is clicked on the sleep GUI, not when waking up due today time. + START_SPRINTING(3), + STOP_SPRINTING(4), + START_JUMP_WITH_HORSE(5), + STOP_JUMP_WITH_HORSE(6), + OPEN_HORSE_INVENTORY(7), // Open horse inventory is only sent when pressing the inventory key (default: E) while on a horse — all other methods of opening a horse's inventory (involving right-clicking or shift-right-clicking it) do not use this packet. + START_FLYING_WITH_ELYTRA(8); + + public static Action getById(final int id) { + return Arrays.stream(Action.values()) + .filter(action -> action.id == id) + .findFirst() + .orElse(null); + } + + @Getter + private final int id; + } + + private int entityId; + private Action action; + private int jumpBoost; // Only used by the “start jump with horse” action, in which case it ranges from 0 to 100. In all other cases it is 0. + + @Override + public void readSelf(NetInputStream netStream) { + entityId = netStream.readVarInt(); + action = Action.getById(netStream.readVarInt()); + jumpBoost = netStream.readVarInt(); + } +}