UpdateHealthPacket
This commit is contained in:
@@ -60,6 +60,7 @@ public enum State {
|
||||
JoinGamePacket.class, 0x23,
|
||||
PlayerAbilitiesPacket.class,0x2C,
|
||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||
UpdateHealthPacket.class, 0x41,
|
||||
SpawnPositionPacket.class, 0x46
|
||||
)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
|
||||
/**
|
||||
* Update Health Packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-----------------|--------|----------------------------------|
|
||||
* | Health | Float | 0 = смерть; 20 = полное здоровье |
|
||||
* | Food | VarInt | 0-20 |
|
||||
* | Food Saturation | Float | 0-5 |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Update_Health">Update Health</a>
|
||||
* @see <a href="https://minecraft.fandom.com/wiki/Food#Hunger_and_saturation">Food: Hunger and saturation</a>
|
||||
*/
|
||||
@Data
|
||||
public class UpdateHealthPacket implements ServerSidePacket {
|
||||
|
||||
private float health;
|
||||
private int food;
|
||||
private float foodSaturation;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeFloat(this.health);
|
||||
netByteBuf.writeVarInt(this.food);
|
||||
netByteBuf.writeFloat(this.foodSaturation);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@@ -67,6 +68,7 @@ public class PacketHandler {
|
||||
context.sendNow(response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S2189")
|
||||
public void onLoginStart(ConnectionContext context, LoginStartPacket loginStartPacket) {
|
||||
var loginSuccessPacket = new LoginSuccessPacket();
|
||||
loginSuccessPacket.setUuid(UUID.randomUUID());
|
||||
@@ -122,6 +124,32 @@ public class PacketHandler {
|
||||
context.send(pingPacket);
|
||||
|
||||
context.flushSending();
|
||||
|
||||
// -- Эксперименты -- //
|
||||
|
||||
var updateHealthPacket = new UpdateHealthPacket();
|
||||
updateHealthPacket.setHealth(0.1f);
|
||||
updateHealthPacket.setFood(0);
|
||||
updateHealthPacket.setFoodSaturation(5.0f);
|
||||
|
||||
context.sendNow(updateHealthPacket);
|
||||
|
||||
while (true) {
|
||||
context.sendNow(updateHealthPacket);
|
||||
|
||||
updateHealthPacket.setHealth(updateHealthPacket.getHealth() + 1.0f);
|
||||
updateHealthPacket.setFood(updateHealthPacket.getFood() + 1);
|
||||
if (updateHealthPacket.getHealth() > 20.0f) {
|
||||
updateHealthPacket.setHealth(0.1f);
|
||||
updateHealthPacket.setFood(0);
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String faviconToBase64(Path iconPath) {
|
||||
|
||||
Reference in New Issue
Block a user