Boss bar colors now work in Bedrock 1.18!!

This commit is contained in:
Camotoy 2021-11-30 21:28:32 -05:00
parent 75d1a6364c
commit 3f296e32a1
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 18 additions and 2 deletions

View file

@ -42,7 +42,7 @@ public class BossBar {
private final long entityId;
private Component title;
private float health;
private final int color;
private int color;
private final int overlay;
private final int darkenSky;
@ -86,6 +86,16 @@ public class BossBar {
session.sendUpstreamPacket(bossEventPacket);
}
public void updateColor(int color) {
this.color = color;
BossEventPacket bossEventPacket = new BossEventPacket();
bossEventPacket.setBossUniqueEntityId(entityId);
bossEventPacket.setAction(BossEventPacket.Action.UPDATE_STYLE);
bossEventPacket.setColor(color);
session.sendUpstreamPacket(bossEventPacket);
}
public void removeBossBar() {
BossEventPacket bossEventPacket = new BossEventPacket();
bossEventPacket.setBossUniqueEntityId(entityId);

View file

@ -46,6 +46,10 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslat
}
// else we were able to log the user in
}
if (session.isLoggedIn()) {
// Sigh
session.getEntityCache().updateBossBars();
}
}
}
}

View file

@ -41,7 +41,7 @@ public class JavaBossEventTranslator extends PacketTranslator<ClientboundBossEve
switch (packet.getAction()) {
case ADD:
long entityId = session.getEntityCache().getNextEntityId().incrementAndGet();
bossBar = new BossBar(session, entityId, packet.getTitle(), packet.getHealth(), 0, 1, 0);
bossBar = new BossBar(session, entityId, packet.getTitle(), packet.getHealth(), packet.getColor().ordinal(), 1, 0);
session.getEntityCache().addBossBar(packet.getUuid(), bossBar);
break;
case UPDATE_TITLE:
@ -54,6 +54,8 @@ public class JavaBossEventTranslator extends PacketTranslator<ClientboundBossEve
session.getEntityCache().removeBossBar(packet.getUuid());
break;
case UPDATE_STYLE:
if (bossBar != null) bossBar.updateColor(packet.getColor().ordinal());
break;
case UPDATE_FLAGS:
//todo
}