Compare commits
1 Commits
dev/experi
...
dev/title
| Author | SHA1 | Date | |
|---|---|---|---|
|
74a9066a04
|
@@ -50,18 +50,17 @@ 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(
|
||||||
PingPacket.class, 0x1F,
|
PingPacket.class, 0x1F,
|
||||||
ChunkDataPacket.class, 0x20,
|
|
||||||
JoinGamePacket.class, 0x23,
|
JoinGamePacket.class, 0x23,
|
||||||
|
SpawnPositionPacket.class, 0x46,
|
||||||
|
ChunkDataPacket.class, 0x20,
|
||||||
PlayerAbilitiesPacket.class,0x2C,
|
PlayerAbilitiesPacket.class,0x2C,
|
||||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||||
SetExperiencePacket.class, 0x40,
|
TitlePacket.class, 0x48
|
||||||
SpawnPositionPacket.class, 0x46
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package mc.protocol.packets.server;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import mc.protocol.io.NetByteBuf;
|
|
||||||
import mc.protocol.packets.ServerSidePacket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Experience packet.
|
|
||||||
*
|
|
||||||
* <p>Структура пакета</p>
|
|
||||||
* <pre>
|
|
||||||
* | FIELD | TYPE | NOTES |
|
|
||||||
* |------------------|----------|------------------------|
|
|
||||||
* | Experience bar | Float | Значение от 0.0 до 1.0 |
|
|
||||||
* | Level | VarInt | |
|
|
||||||
* | Total Experience | VarInt | |
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Set_Experience">Set Experience</a>
|
|
||||||
* @see <a href="https://minecraft.fandom.com/wiki/Experience#Leveling_up">Experience: Leveling up</a>
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class SetExperiencePacket implements ServerSidePacket {
|
|
||||||
|
|
||||||
private float experienceBar;
|
|
||||||
private int level;
|
|
||||||
private int totalExperience;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSelf(NetByteBuf netByteBuf) {
|
|
||||||
netByteBuf.writeFloat(this.experienceBar);
|
|
||||||
netByteBuf.writeVarInt(this.level);
|
|
||||||
netByteBuf.writeVarInt(this.totalExperience);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package mc.protocol.packets.server;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import mc.protocol.io.NetByteBuf;
|
||||||
|
import mc.protocol.model.text.Text;
|
||||||
|
import mc.protocol.model.text.TextColor;
|
||||||
|
import mc.protocol.model.text.TextStyle;
|
||||||
|
import mc.protocol.packets.ServerSidePacket;
|
||||||
|
import mc.protocol.serializer.TextSerializer;
|
||||||
|
import mc.protocol.utils.TitleAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title packet.
|
||||||
|
*
|
||||||
|
* <p>Структура пакета</p>
|
||||||
|
* <pre>
|
||||||
|
* | FIELD | TYPE | NOTES |
|
||||||
|
* |-------------|-------------|----------------------------------|
|
||||||
|
* | Action | VarInt | Определяет остальные поля пакета |
|
||||||
|
* | Data fields | - | зависят от "Action" |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>Варианты "Action"</p>
|
||||||
|
* <pre>
|
||||||
|
* | ACTION | FIELD | TYPE | NOTES |
|
||||||
|
* | VALUE | DESCRIPTION | | | |
|
||||||
|
* |-------|-----------------------|-----------------|---------|-------------------------------------------------|
|
||||||
|
* | 0 | set title | Title Text | Text | |
|
||||||
|
* | 1 | set subtitle | Subtitle Text | Text | |
|
||||||
|
* | 2 | set action bar | Action bar text | Text | [*] |
|
||||||
|
* | 3 | set times and display | Fade In | Integer | Время (в тиках (tick)) на эфект появления |
|
||||||
|
* | | | Stay | Integer | Время (в тиках (tick)) на отображение на экране |
|
||||||
|
* | | | Fade Out | Integer | Время (в тиках (tick)) на эфект исчезания |
|
||||||
|
* | 4 | hide | - | - | |
|
||||||
|
* | 5 | reset | - | - | |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* * - стоит обратить внимание, что {@link TextColor} и {@link TextStyle} не работают: клиент не применяет
|
||||||
|
* стилистику в таком виде. Однако метод через символ "§" (\<span>u00a7</span>) работает.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Title">Title</a>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TitlePacket implements ServerSidePacket {
|
||||||
|
|
||||||
|
private TitleAction action;
|
||||||
|
|
||||||
|
private Text title;
|
||||||
|
private Text subtitle;
|
||||||
|
private Text actionbar;
|
||||||
|
private Integer fadeIn;
|
||||||
|
private Integer stay;
|
||||||
|
private Integer fadeOut;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelf(NetByteBuf netByteBuf) {
|
||||||
|
netByteBuf.writeVarInt(this.action.getCode());
|
||||||
|
|
||||||
|
switch (this.action) {
|
||||||
|
case SET_TITLE:
|
||||||
|
netByteBuf.writeString(TextSerializer.toJsonObject(this.title).toString());
|
||||||
|
break;
|
||||||
|
case SET_SUBTITLE:
|
||||||
|
netByteBuf.writeString(TextSerializer.toJsonObject(this.subtitle).toString());
|
||||||
|
break;
|
||||||
|
case SET_ACTIONBAR:
|
||||||
|
netByteBuf.writeString(TextSerializer.toJsonObject(this.actionbar).toString());
|
||||||
|
break;
|
||||||
|
case SET_TIMES_AND_DISPLAY:
|
||||||
|
netByteBuf.writeInt(fadeIn);
|
||||||
|
netByteBuf.writeInt(stay);
|
||||||
|
netByteBuf.writeInt(fadeOut);
|
||||||
|
break;
|
||||||
|
case HIDE:
|
||||||
|
case RESET:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
17
protocol/src/main/java/mc/protocol/utils/TitleAction.java
Normal file
17
protocol/src/main/java/mc/protocol/utils/TitleAction.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package mc.protocol.utils;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum TitleAction {
|
||||||
|
SET_TITLE(0),
|
||||||
|
SET_SUBTITLE(1),
|
||||||
|
SET_ACTIONBAR(2),
|
||||||
|
SET_TIMES_AND_DISPLAY(3),
|
||||||
|
HIDE(4),
|
||||||
|
RESET(5);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int code;
|
||||||
|
}
|
||||||
@@ -2,12 +2,12 @@ package mc.server;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.protocol.ProtocolConstant;
|
import mc.protocol.*;
|
||||||
import mc.protocol.State;
|
|
||||||
import mc.protocol.api.ConnectionContext;
|
import mc.protocol.api.ConnectionContext;
|
||||||
import mc.protocol.model.Location;
|
import mc.protocol.model.Location;
|
||||||
import mc.protocol.model.Look;
|
import mc.protocol.model.Look;
|
||||||
import mc.protocol.model.ServerInfo;
|
import mc.protocol.model.ServerInfo;
|
||||||
|
import mc.protocol.model.text.Text;
|
||||||
import mc.protocol.packets.PingPacket;
|
import mc.protocol.packets.PingPacket;
|
||||||
import mc.protocol.packets.client.HandshakePacket;
|
import mc.protocol.packets.client.HandshakePacket;
|
||||||
import mc.protocol.packets.client.LoginStartPacket;
|
import mc.protocol.packets.client.LoginStartPacket;
|
||||||
@@ -17,6 +17,7 @@ import mc.protocol.serializer.TextSerializer;
|
|||||||
import mc.protocol.utils.Difficulty;
|
import mc.protocol.utils.Difficulty;
|
||||||
import mc.protocol.utils.GameMode;
|
import mc.protocol.utils.GameMode;
|
||||||
import mc.protocol.utils.LevelType;
|
import mc.protocol.utils.LevelType;
|
||||||
|
import mc.protocol.utils.TitleAction;
|
||||||
import mc.server.config.Config;
|
import mc.server.config.Config;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
@@ -27,7 +28,6 @@ import java.util.Base64;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -69,7 +69,6 @@ public class PacketHandler {
|
|||||||
context.sendNow(response);
|
context.sendNow(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("java:S2189")
|
|
||||||
public void onLoginStart(ConnectionContext context, LoginStartPacket loginStartPacket) {
|
public void onLoginStart(ConnectionContext context, LoginStartPacket loginStartPacket) {
|
||||||
var loginSuccessPacket = new LoginSuccessPacket();
|
var loginSuccessPacket = new LoginSuccessPacket();
|
||||||
loginSuccessPacket.setUuid(UUID.randomUUID());
|
loginSuccessPacket.setUuid(UUID.randomUUID());
|
||||||
@@ -128,27 +127,11 @@ public class PacketHandler {
|
|||||||
|
|
||||||
// -- Эксперименты -- //
|
// -- Эксперименты -- //
|
||||||
|
|
||||||
var setExperiencePacket = new SetExperiencePacket();
|
var titlePacket = new TitlePacket();
|
||||||
setExperiencePacket.setExperienceBar(0f);
|
titlePacket.setAction(TitleAction.SET_TITLE);
|
||||||
setExperiencePacket.setLevel(0);
|
titlePacket.setTitle(Text.of("HELLO"));
|
||||||
setExperiencePacket.setTotalExperience(100);
|
|
||||||
|
|
||||||
while (true) {
|
context.sendNow(titlePacket);
|
||||||
context.sendNow(setExperiencePacket);
|
|
||||||
|
|
||||||
setExperiencePacket.setExperienceBar(setExperiencePacket.getExperienceBar() + 0.01f);
|
|
||||||
setExperiencePacket.setLevel(setExperiencePacket.getLevel() + 1);
|
|
||||||
if (setExperiencePacket.getExperienceBar() > 1.0f) {
|
|
||||||
setExperiencePacket.setExperienceBar(0f);
|
|
||||||
setExperiencePacket.setLevel(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
TimeUnit.MILLISECONDS.sleep(10);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String faviconToBase64(Path iconPath) {
|
private static String faviconToBase64(Path iconPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user