EntityActionPacket
This commit is contained in:
@@ -50,7 +50,8 @@ public enum State {
|
|||||||
0x0B, PingPacket.class,
|
0x0B, PingPacket.class,
|
||||||
0x0D, PlayerPositionPacket.class,
|
0x0D, PlayerPositionPacket.class,
|
||||||
0x0E, CPlayerPositionAndLookPacket.class,
|
0x0E, CPlayerPositionAndLookPacket.class,
|
||||||
0x0F, PlayerLookPacket.class
|
0x0F, PlayerLookPacket.class,
|
||||||
|
0x15, EntityActionPacket.class
|
||||||
),
|
),
|
||||||
// client bound
|
// client bound
|
||||||
Map.of(
|
Map.of(
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package mc.protocol.packets.client;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import mc.protocol.io.NetByteBuf;
|
||||||
|
import mc.protocol.packets.ClientSidePacket;
|
||||||
|
import mc.protocol.utils.EntityActionAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity Action packet.
|
||||||
|
*
|
||||||
|
* <p>Структура пакета</p>
|
||||||
|
* <pre>
|
||||||
|
* | FIELD | TYPE | NOTES |
|
||||||
|
* |------------|--------|-------------------------------------------|
|
||||||
|
* | Entity ID | VarInt | ID игрока |
|
||||||
|
* | Action ID | VarInt | ID действия |
|
||||||
|
* | Jump Boost | VarInt | Используется только при "Action ID" = 5. |
|
||||||
|
* | | | В этом случае значение будет от 0 до 100. |
|
||||||
|
* | | | В остальных случаях значение 0. |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Entity_Action" target="_top">Entity Action</a>
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
public class EntityActionPacket implements ClientSidePacket {
|
||||||
|
|
||||||
|
private Integer entityId;
|
||||||
|
private EntityActionAction action;
|
||||||
|
private Integer jumpBoost;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSelf(NetByteBuf netByteBuf) {
|
||||||
|
this.entityId = netByteBuf.readVarInt();
|
||||||
|
int actionId = netByteBuf.readVarInt();
|
||||||
|
this.jumpBoost = netByteBuf.readVarInt();
|
||||||
|
|
||||||
|
this.action = EntityActionAction.valueOfCode(actionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void passivate() {
|
||||||
|
this.entityId = null;
|
||||||
|
this.action = null;
|
||||||
|
this.jumpBoost = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package mc.protocol.utils;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum EntityActionAction {
|
||||||
|
START_SNEAKING(0),
|
||||||
|
STOP_SNEAKING(1),
|
||||||
|
LEAVE_BED(2),
|
||||||
|
START_SPRINTING(3),
|
||||||
|
STOP_SPRINTING(4),
|
||||||
|
START_JUMP_WITH_HORSE(5),
|
||||||
|
STOP_JUMP_WITH_HORSE(6),
|
||||||
|
OPEN_HORSE_INVENTORY(7),
|
||||||
|
START_FLYING_WITH_ELYTRA(8);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static EntityActionAction valueOfCode(int code) {
|
||||||
|
for (EntityActionAction action : EntityActionAction.values()) {
|
||||||
|
if (action.code == code) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int code;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user