Archived
0
This commit is contained in:
2018-07-12 12:38:17 +03:00
parent 99febc56df
commit 5b38d1a032
3 changed files with 100 additions and 2 deletions

View File

@@ -82,6 +82,7 @@ public enum State {
.put(0x1D, AnimationPacket.class)
.build(),
ImmutableMap.<Class<? extends SCPacket>, Integer>builder()
.put(BossBarPacket.class, 0x0C)
.put(ChatMessageServerPacket.class, 0x0F)
.put(PluginMessagePacket.class, 0x18)
.put(KeepAlivePacket.class, 0x1F)

View File

@@ -4,5 +4,88 @@
*/
package mc.core.network.proto_1_12_2.packets;
public class BossBarPacket {
import lombok.Data;
import lombok.Setter;
import lombok.ToString;
import mc.core.network.NetStream;
import mc.core.network.SCPacket;
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
import mc.core.text.Text;
import java.util.UUID;
@Setter
@ToString
public class BossBarPacket implements SCPacket {
public static final int ACTION_ADD = 0,
ACTION_REMOVE = 1,
ACTION_UPDATE_HEALTH = 2,
ACTION_UPDATE_TITLE = 3,
ACTION_UPDATE_STYLE = 4,
ACTION_UPDATE_FLAGS = 5;
public static final int COLOR_PINK = 0,
COLOR_BLUE = 1,
COLOR_RED = 2,
COLOR_GREEN = 3,
COLOR_YELLOW = 4,
COLOR_PURPLE = 5,
COLOR_WHITE = 6;
public static final int DIVISION_NO = 0,
DIVISION_0 = DIVISION_NO,
DIVISION_6 = 1,
DIVISION_10 = 2,
DIVISION_12 = 3,
DIVISION_20 = 4;
public static final byte FLAG_NO = 0x00,
FLAG_DAKR_SKY = 0x01,
FLAG_DRAGON_BAR = 0x02;
@Data
public static class BarData {
private Text title;
/*
* From 0 to 1.
* Values greater than 1 do not crash a Notchian client,
* and start rendering part of a second health bar at around 1.5.
* (https://i.johni0702.de/nA.png)
*/
private float health;
private int color;
private int division;
private byte flags;
}
private UUID uuid; // Unique ID for this bar
private int action;
private BarData barData;
@Override
public void writeSelf(NetStream netStream) {
netStream.writeUUID(uuid);
netStream.writeVarInt(action);
if (action == ACTION_REMOVE) {
return;
}
if (action == ACTION_ADD || action == ACTION_UPDATE_TITLE) {
netStream.writeString(TextSerializer.serialize(barData.title).toString());
}
if (action == ACTION_ADD || action == ACTION_UPDATE_HEALTH) {
netStream.writeFloat(barData.health);
}
if (action == ACTION_ADD || action == ACTION_UPDATE_STYLE) {
netStream.writeVarInt(barData.color);
netStream.writeVarInt(barData.division);
}
if (action == ACTION_ADD || action == ACTION_UPDATE_FLAGS) {
netStream.writeUnsignedByte(barData.flags);
}
}
}