Skip to content

Commit

Permalink
Introduce the first two plugin messages sent by MCCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Aug 6, 2023
1 parent 7b028fd commit a7003f7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
5 changes: 4 additions & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}")

// Compatibility with other mods
// Add the API module
include(project(":api"))
api(project(":api"))

// Compatibility with other mods
modImplementation("maven.modrinth:sodium:${property("sodium")}")
modImplementation("maven.modrinth:iris:${property("iris")}") {
isTransitive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.mojang.datafixers.util.Pair;
import com.noxcrew.noxesium.NoxesiumMod;
import com.noxcrew.noxesium.network.clientbound.ClientboundChangeServerRulesPacket;
import com.noxcrew.noxesium.network.clientbound.ClientboundMccGameStatePacket;
import com.noxcrew.noxesium.network.clientbound.ClientboundMccServerPacket;
import com.noxcrew.noxesium.network.clientbound.ClientboundNoxesiumPacket;
import com.noxcrew.noxesium.network.clientbound.ClientboundResetPacket;
import com.noxcrew.noxesium.network.clientbound.ClientboundResetServerRulesPacket;
Expand Down Expand Up @@ -35,14 +37,19 @@ public class NoxesiumPackets {
private static final Map<String, String> serverboundPackets = new HashMap<>();
private static final Set<String> registeredGroups = new HashSet<>();

/** The namespace under which all packets are registered. Appended by a global API version equal to the major version of Noxesium. */
/**
* The namespace under which all packets are registered. Appended by a global API version equal to the major version of Noxesium.
*/
public static final String PACKET_NAMESPACE = NoxesiumMod.NAMESPACE + "-v1";

public static final PacketType<ClientboundChangeServerRulesPacket> CLIENT_CHANGE_SERVER_RULES = client("change_server_rules", ClientboundChangeServerRulesPacket::new);
public static final PacketType<ClientboundResetServerRulesPacket> CLIENT_RESET_SERVER_RULES = client("reset_server_rules", ClientboundResetServerRulesPacket::new);
public static final PacketType<ClientboundResetPacket> CLIENT_RESET = client("reset", ClientboundResetPacket::new);
public static final PacketType<ClientboundServerInformationPacket> CLIENT_SERVER_INFO = client("server_info", ClientboundServerInformationPacket::new);

public static final PacketType<ClientboundMccServerPacket> CLIENT_MCC_SERVER = client("mcc_server", ClientboundMccServerPacket::new);
public static final PacketType<ClientboundMccGameStatePacket> CLIENT_MCC_GAME_STATE = client("mcc_game_state", ClientboundMccGameStatePacket::new);

public static final PacketType<ServerboundClientInformationPacket> SERVER_CLIENT_INFO = server("client_info");
public static final PacketType<ServerboundClientSettingsPacket> SERVER_CLIENT_SETTINGS = server("client_settings");

Expand Down Expand Up @@ -78,8 +85,8 @@ public static <T extends ClientboundNoxesiumPacket> PacketType<T> client(String
/**
* Registers a new serverbound Noxesium packet.
*
* @param id The identifier of this packet.
* @param <T> The type of packet.
* @param id The identifier of this packet.
* @param <T> The type of packet.
* @return The PacketType instance.
*/
public static <T extends ServerboundNoxesiumPacket> PacketType<T> server(String id) {
Expand All @@ -89,9 +96,9 @@ public static <T extends ServerboundNoxesiumPacket> PacketType<T> server(String
/**
* Registers a new serverbound Noxesium packet.
*
* @param id The identifier of this packet.
* @param group The group this packet belongs to, this can be used to selectively register packets based on the server being used.
* @param <T> The type of packet.
* @param id The identifier of this packet.
* @param group The group this packet belongs to, this can be used to selectively register packets based on the server being used.
* @param <T> The type of packet.
* @return The PacketType instance.
*/
public static <T extends ServerboundNoxesiumPacket> PacketType<T> server(String id, String group) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.noxcrew.noxesium.network.clientbound;

import com.noxcrew.noxesium.network.NoxesiumPackets;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;

/**
* Sent by MCC Island whenever the game state changes.
* Possible values for the phase type:
* - LOADING
* - WAITING_FOR_PLAYERS
* - PRE_GAME
* - PLAY
* - INTERMISSION
* - POST_GAME
* <p>
* Values for the stage key differ based on the game.
*/
public class ClientboundMccGameStatePacket extends ClientboundNoxesiumPacket {

public final String phaseType;
public final String stage;

public ClientboundMccGameStatePacket(FriendlyByteBuf buf) {
super(buf.readVarInt());
this.phaseType = buf.readUtf();
this.stage = buf.readUtf();
}

@Override
public void receive(LocalPlayer player, PacketSender responseSender) {
// This packet is sent to be handled by any other users of the MCC Island API.
// TODO Set up a public packet handler API here?
}

@Override
public PacketType<?> getType() {
return NoxesiumPackets.CLIENT_MCC_GAME_STATE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.noxcrew.noxesium.network.clientbound;

import com.noxcrew.noxesium.network.NoxesiumPackets;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;

/**
* Sent by MCC Island whenever you switch servers. All values are dynamic and may change over time.
*/
public class ClientboundMccServerPacket extends ClientboundNoxesiumPacket {

public final String type;
public final String subType;
public final String associatedGame;

public ClientboundMccServerPacket(FriendlyByteBuf buf) {
super(buf.readVarInt());
this.type = buf.readUtf();
this.subType = buf.readUtf();
this.associatedGame = buf.readUtf();
}

@Override
public void receive(LocalPlayer player, PacketSender responseSender) {
// This packet is sent to be handled by any other users of the MCC Island API.
// TODO Set up a public packet handler API here?
}

@Override
public PacketType<?> getType() {
return NoxesiumPackets.CLIENT_MCC_SERVER;
}
}

0 comments on commit a7003f7

Please sign in to comment.