Skip to content

Commit

Permalink
Migrate InitBoardPacket to a record
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 29, 2024
1 parent dd916f5 commit 7162f10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void addPlayer(ServerPlayer player) {
final BingoBoard.Teams team = getTeam(player);
new SyncTeamPacket(team).sendTo(player);

new InitBoardPacket(this, obfuscateTeam(team, player)).sendTo(player);
InitBoardPacket.create(this, obfuscateTeam(team, player)).sendTo(player);
player.connection.send(new ClientboundUpdateAdvancementsPacket(
false,
VanillaNetworking.generateAdvancements(board.getSize(), board.getGoals()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

import java.util.Arrays;

public final class InitBoardPacket implements AbstractCustomPayload {
public record InitBoardPacket(
int size,
ClientGoal[] goals,
BingoBoard.Teams[] states,
String[] teams,
BingoGameMode.RenderMode renderMode
) implements AbstractCustomPayload {
public static final Type<InitBoardPacket> TYPE = AbstractCustomPayload.type("init_board");
public static final StreamCodec<RegistryFriendlyByteBuf, InitBoardPacket> CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_INT, p -> p.size,
Expand All @@ -31,33 +37,20 @@ public final class InitBoardPacket implements AbstractCustomPayload {
InitBoardPacket::new
);

private final int size;
private final ClientGoal[] goals;
private final BingoBoard.Teams[] states;
private final String[] teams;
private final BingoGameMode.RenderMode renderMode;

public InitBoardPacket(BingoGame game, BingoBoard.Teams[] states) {
public static InitBoardPacket create(BingoGame game, BingoBoard.Teams[] states) {
final BingoBoard board = game.getBoard();

this.size = board.getSize();
this.goals = new ClientGoal[board.getGoals().length];
this.states = states; // Obfuscated states
final int size = board.getSize();
final ClientGoal[] goals = new ClientGoal[board.getGoals().length];

for (int i = 0; i < goals.length; i++) {
this.goals[i] = new ClientGoal(board.getGoals()[i]);
goals[i] = new ClientGoal(board.getGoals()[i]);
}

this.teams = Arrays.stream(game.getTeams()).map(PlayerTeam::getName).toArray(String[]::new);
this.renderMode = game.getGameMode().getRenderMode();
}
final String[] teams = Arrays.stream(game.getTeams()).map(PlayerTeam::getName).toArray(String[]::new);
final var renderMode = game.getGameMode().getRenderMode();

private InitBoardPacket(int size, ClientGoal[] goals, BingoBoard.Teams[] states, String[] teams, BingoGameMode.RenderMode renderMode) {
this.size = size;
this.goals = goals;
this.states = states;
this.teams = teams;
this.renderMode = renderMode;
return new InitBoardPacket(size, goals, states, teams, renderMode);
}

@NotNull
Expand Down

0 comments on commit 7162f10

Please sign in to comment.