Skip to content

Commit 8d51d50

Browse files
committed
Replace inRound boolean with Phase enum
Provides more information to the client, to be used in banner rendering.
1 parent 388cceb commit 8d51d50

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

src/main/java/net/kyrptonaught/lemclienthelper/ServerInfo/ServerInfoData.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package net.kyrptonaught.lemclienthelper.ServerInfo;
22

33
public class ServerInfoData {
4-
private static boolean IN_ROUND = false;
5-
private static byte[] PLAYER_STATUS = new byte[]{1,0,1,1,1,0,-1,-1};
6-
74
private static GAME_MODES GAME_MODE = GAME_MODES.CASUAL;
85
private static MINIGAME_TYPES MINIGAME = MINIGAME_TYPES.BATTLE;
6+
private static MINIGAME_PHASES PHASE = MINIGAME_PHASES.NONE;
7+
8+
private static byte[] PLAYER_STATUS = new byte[]{1,0,1,1,1,0,-1,-1};
99

1010
/**
1111
* Minigame types
@@ -58,6 +58,24 @@ public enum GAME_MODES {
5858
SCORE_ATTACK
5959
}
6060

61+
/**
62+
* Minigame phase
63+
* <ul>
64+
* <li> NONE
65+
* <li> LOADING
66+
* <li> COUNTDOWN
67+
* <li> RUNNING
68+
* <li> END
69+
* </ul>
70+
*/
71+
public enum MINIGAME_PHASES {
72+
NONE,
73+
LOADING,
74+
COUNTDOWN,
75+
RUNNING,
76+
END
77+
}
78+
6179
public static void setMinigame(MINIGAME_TYPES minigame) {
6280
MINIGAME = minigame;
6381
}
@@ -74,12 +92,12 @@ public static GAME_MODES getGamemode() {
7492
return GAME_MODE;
7593
}
7694

77-
public static void setInRound(boolean inRound) {
78-
IN_ROUND = inRound;
95+
public static void setPhase(MINIGAME_PHASES phase) {
96+
PHASE = phase;
7997
}
8098

81-
public static boolean getInRound() {
82-
return IN_ROUND;
99+
public static MINIGAME_PHASES getPhase() {
100+
return PHASE;
83101
}
84102

85103
public static void setPlayerStatus(byte[] playerStatus) {

src/main/java/net/kyrptonaught/lemclienthelper/ServerInfo/ServerInfoNetworking.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void onInitialize() {
1010
ClientPlayNetworking.registerGlobalReceiver(serverInfoPackets.serverInfoPacket.PACKET_ID, ((payload, context) -> {
1111
ServerInfoData.setMinigame(payload.minigame());
1212
ServerInfoData.setGamemode(payload.gamemode());
13-
ServerInfoData.setInRound(payload.inRound());
13+
ServerInfoData.setPhase(payload.phase());
1414
ServerInfoData.setPlayerStatus(payload.playerStatus());
1515
}));
1616

@@ -20,8 +20,8 @@ public static void onInitialize() {
2020
PayloadTypeRegistry.playS2C().register(serverInfoPackets.gamemodePacket.PACKET_ID, serverInfoPackets.gamemodePacket.codec);
2121
ClientPlayNetworking.registerGlobalReceiver(serverInfoPackets.gamemodePacket.PACKET_ID, ((payload, context) -> ServerInfoData.setGamemode(payload.gamemode())));
2222

23-
PayloadTypeRegistry.playS2C().register(serverInfoPackets.inRoundPacket.PACKET_ID, serverInfoPackets.inRoundPacket.codec);
24-
ClientPlayNetworking.registerGlobalReceiver(serverInfoPackets.inRoundPacket.PACKET_ID, ((payload, context) -> ServerInfoData.setInRound(payload.inRound())));
23+
PayloadTypeRegistry.playS2C().register(serverInfoPackets.phasePacket.PACKET_ID, serverInfoPackets.phasePacket.codec);
24+
ClientPlayNetworking.registerGlobalReceiver(serverInfoPackets.phasePacket.PACKET_ID, ((payload, context) -> ServerInfoData.setPhase(payload.phase())));
2525

2626
PayloadTypeRegistry.playS2C().register(serverInfoPackets.playerStatusPacket.PACKET_ID, serverInfoPackets.playerStatusPacket.codec);
2727
ClientPlayNetworking.registerGlobalReceiver(serverInfoPackets.serverInfoPacket.PACKET_ID, ((payload, context) -> ServerInfoData.setPlayerStatus(payload.playerStatus())));

src/main/java/net/kyrptonaught/lemclienthelper/ServerInfo/packets/serverInfoPackets.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,29 @@ public class serverInfoPackets {
1818
* new serverInfoPacket(
1919
* ServerInfoData.MINIGAME_TYPES.BATTLE,
2020
* ServerInfoData.GAME_MODES.CASUAL,
21-
* false,
21+
* ServerInfoData.MINIGAME_PHASES.NONE,
2222
* new byte[]{0,0,1,1}
2323
* );</code>
2424
* </pre>
2525
*
2626
* @param minigame {@link ServerInfoData.MINIGAME_TYPES}. Minigame the client is in.
2727
*
28-
* @param gamemode {@link ServerInfoData.GAME_MODES}. Gamemode the client is in.
28+
* @param gamemode {@link ServerInfoData.GAME_MODES}. Gamemode the game is in.
2929
*
30-
* @param inRound boolean, Is the client in a round?
30+
* @param phase {@link ServerInfoData.MINIGAME_PHASES}, Phase the game is in.
3131
*
32-
* @param playerStatus byte[]. In Round: 0 - Dead; 1 - Alive; -1 - Spectating;<br>
33-
* In Lobby: 0 - Not Ready; 1 - Ready
32+
* @param playerStatus byte[], -1 — Spectating; 0 — Dead/Not Ready; 1 — Alive/Ready;
3433
*
3534
* @see gamemodePacket gamemodePacket
3635
* @see playerStatusPacket playerStatusPacket
37-
* @see inRoundPacket inRoundPacket
36+
* @see phasePacket phasePacket
3837
*/
39-
public record serverInfoPacket(ServerInfoData.MINIGAME_TYPES minigame, ServerInfoData.GAME_MODES gamemode, boolean inRound, byte[] playerStatus) implements CustomPayload {
38+
public record serverInfoPacket(ServerInfoData.MINIGAME_TYPES minigame, ServerInfoData.GAME_MODES gamemode, ServerInfoData.MINIGAME_PHASES phase, byte[] playerStatus) implements CustomPayload {
4039
public static final Id<serverInfoPacket> PACKET_ID = new Id<>(Identifier.of("serverinfo", "serverinfo_set"));
4140
public static final PacketCodec<RegistryByteBuf, serverInfoPacket> codec = PacketCodec.tuple(
4241
PacketCodecs.indexed(i -> ServerInfoData.MINIGAME_TYPES.values()[i], ServerInfoData.MINIGAME_TYPES::ordinal), serverInfoPacket::minigame,
4342
PacketCodecs.indexed(i -> ServerInfoData.GAME_MODES.values()[i], ServerInfoData.GAME_MODES::ordinal), serverInfoPacket::gamemode,
44-
PacketCodecs.BOOL, serverInfoPacket::inRound,
43+
PacketCodecs.indexed(i -> ServerInfoData.MINIGAME_PHASES.values()[i], ServerInfoData.MINIGAME_PHASES::ordinal), serverInfoPacket::phase,
4544
PacketCodecs.BYTE_ARRAY, serverInfoPacket::playerStatus,
4645
serverInfoPacket::new
4746
);
@@ -96,16 +95,16 @@ public Id<? extends CustomPayload> getId() {
9695
}
9796

9897
/**
99-
* <pre>inRoundPacket, sends the current inRound status to client.
100-
* Intended for use at begining & end of round.</pre>
98+
* phasePacket, sends phase to client
99+
*
100+
* @param phase {@link ServerInfoData.MINIGAME_PHASES}. Phase the game is in.
101101
*
102-
* @param inRound boolean, Is the client in a round?
103102
*/
104-
public record inRoundPacket(boolean inRound) implements CustomPayload {
105-
public static final Id<inRoundPacket> PACKET_ID = new Id<>(Identifier.of("serverinfo", "inround_set"));
106-
public static final PacketCodec<RegistryByteBuf, inRoundPacket> codec = PacketCodec.tuple(
107-
PacketCodecs.BOOL, inRoundPacket::inRound,
108-
inRoundPacket::new
103+
public record phasePacket(ServerInfoData.MINIGAME_PHASES phase) implements CustomPayload {
104+
public static final Id<phasePacket> PACKET_ID = new Id<>(Identifier.of("serverinfo", "phase_set"));
105+
public static final PacketCodec<RegistryByteBuf, phasePacket> codec = PacketCodec.tuple(
106+
PacketCodecs.indexed(i -> ServerInfoData.MINIGAME_PHASES.values()[i], ServerInfoData.MINIGAME_PHASES::ordinal), phasePacket::phase,
107+
phasePacket::new
109108
);
110109

111110
@Override
@@ -120,8 +119,7 @@ public Id<? extends CustomPayload> getId() {
120119
* <code>new byte[]{0,1,0,-1}</code> 4 players, players 1 & 3 are either not ready or dead, player 4 is spectating.
121120
* </pre>
122121
*
123-
* @param playerStatus byte[]. In Round: 0 - Dead; 1 - Alive; -1 - Spectating;<br>
124-
* In Lobby: 0 - Not Ready; 1 - Ready
122+
* @param playerStatus byte[], -1 — Spectating; 0 — Dead/Not Ready; 1 — Alive/Ready;
125123
*/
126124
public record playerStatusPacket(byte[] playerStatus) implements CustomPayload {
127125
public static final Id<playerStatusPacket> PACKET_ID = new Id<>(Identifier.of("serverinfo", "playerstatus_set"));

src/main/java/net/kyrptonaught/lemclienthelper/hud/genericHud/GenericHudMod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void onInitialize() {
4646
.then(CommandManager.argument("target", EntityArgumentType.players())
4747
.executes(context -> {
4848
ServerPlayNetworking.send(EntityArgumentType.getPlayer(context, "target"),
49-
new serverInfoPackets.inRoundPacket(BoolArgumentType.getBool(context,"inRound")));
49+
new serverInfoPackets.phasePacket((BoolArgumentType.getBool(context,"inRound") ? ServerInfoData.MINIGAME_PHASES.RUNNING : ServerInfoData.MINIGAME_PHASES.NONE)));
5050
ServerPlayNetworking.send(EntityArgumentType.getPlayer(context, "target"),
5151
new PlayerBarPacket(true));
5252
return 0;

src/main/java/net/kyrptonaught/lemclienthelper/hud/genericHud/PlayerBarRenderer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import net.minecraft.client.render.RenderTickCounter;
88
import net.minecraft.util.Identifier;
99

10-
public class PlayerBarRenderer {
10+
import static net.kyrptonaught.lemclienthelper.ServerInfo.ServerInfoData.MINIGAME_PHASES.*;
1111

12+
public class PlayerBarRenderer {
1213
private static final Identifier BIG_PLAYER_ICON_DEAD = Identifier.of("lem.base", "textures/playerbar/big/dead.png");
1314
private static final Identifier SMALL_PLAYER_ICON_DEAD = Identifier.of("lem.base", "textures/playerbar/small/dead.png");
1415

@@ -40,11 +41,12 @@ public static void renderPlayerBar(DrawContext context, RenderTickCounter v) {
4041
int e; // Width of texture
4142
float u; // Width of texture + spacing.
4243

44+
ServerInfoData.MINIGAME_PHASES Phase = ServerInfoData.getPhase();
4345
// Horrible awful, no good, very bad, spacing/centring code.
4446
if (p < 11) {
4547
e = 17;
4648
u = p > 8 ? 18f : 23f;
47-
if (ServerInfoData.getInRound()) {
49+
if (Phase != NONE) {
4850
// If you're wondering about this calculation,
4951
// This is the amount of pixels the matrix is shifted by
5052
// after every icon, in order to evenly space all icons, when there are >8.
@@ -59,7 +61,7 @@ public static void renderPlayerBar(DrawContext context, RenderTickCounter v) {
5961
} else {
6062
e = 10;
6163
u = 11f;
62-
if (ServerInfoData.getInRound()) {
64+
if (Phase != NONE) {
6365
u = ((182f - (e * p))/(p - 1))+ e;
6466

6567
context.getMatrices().translate(91f,0f,0f);
@@ -71,13 +73,13 @@ public static void renderPlayerBar(DrawContext context, RenderTickCounter v) {
7173
for (int i = 0; i < p; i++) {
7274
if (i > 0) {context.getMatrices().translate(u, 0f, 0f);}
7375
float[] c = RenderSystem.getShaderColor(); // Get the current shader colour to prevent breaking with hud transparency mods.
74-
if ((!ServerInfoData.getInRound() && s[i] == 0) || s[i] == -1) {RenderSystem.setShaderColor(c[0],c[1],c[2], c[3]*(128F/255F));}
76+
if ((Phase == NONE && s[i] == 0) || s[i] == -1) {RenderSystem.setShaderColor(c[0],c[1],c[2], c[3]*(128F/255F));}
7577
if (p < 11) {
76-
context.drawTexture(((s[i] == 0 || s[i] == -1) && ServerInfoData.getInRound()) ? BIG_PLAYER_ICON_DEAD : BIG_PLAYER_ICONS(i), x, l, e, 5, e, 5, e, 5);
78+
context.drawTexture(((s[i] == 0 || s[i] == -1) && (Phase != NONE)) ? BIG_PLAYER_ICON_DEAD : BIG_PLAYER_ICONS(i), x, l, e, 5, e, 5, e, 5);
7779
} else {
78-
context.drawTexture(((s[i] == 0 || s[i] == -1) && ServerInfoData.getInRound()) ? SMALL_PLAYER_ICON_DEAD : SMALL_PLAYER_ICONS(i),x, l, e, 5, e, 5, e, 5);
80+
context.drawTexture(((s[i] == 0 || s[i] == -1) && (Phase != NONE)) ? SMALL_PLAYER_ICON_DEAD : SMALL_PLAYER_ICONS(i),x, l, e, 5, e, 5, e, 5);
7981
}
80-
if ((!ServerInfoData.getInRound() && s[i] == 0) || s[i] == -1) {RenderSystem.setShaderColor(c[0],c[1],c[2],c[3]*(255F/128F));}
82+
if ((Phase == NONE && s[i] == 0) || s[i] == -1) {RenderSystem.setShaderColor(c[0],c[1],c[2],c[3]*(255F/128F));}
8183
}
8284
RenderSystem.disableBlend();
8385
context.getMatrices().pop();

0 commit comments

Comments
 (0)