diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 42da33d6..d3da087b 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -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 diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java b/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java index b3fdc55d..b5cc2df5 100644 --- a/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java @@ -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; @@ -35,7 +37,9 @@ public class NoxesiumPackets { private static final Map serverboundPackets = new HashMap<>(); private static final Set 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 CLIENT_CHANGE_SERVER_RULES = client("change_server_rules", ClientboundChangeServerRulesPacket::new); @@ -43,6 +47,9 @@ public class NoxesiumPackets { public static final PacketType CLIENT_RESET = client("reset", ClientboundResetPacket::new); public static final PacketType CLIENT_SERVER_INFO = client("server_info", ClientboundServerInformationPacket::new); + public static final PacketType CLIENT_MCC_SERVER = client("mcc_server", ClientboundMccServerPacket::new); + public static final PacketType CLIENT_MCC_GAME_STATE = client("mcc_game_state", ClientboundMccGameStatePacket::new); + public static final PacketType SERVER_CLIENT_INFO = server("client_info"); public static final PacketType SERVER_CLIENT_SETTINGS = server("client_settings"); @@ -78,8 +85,8 @@ public static PacketType client(String /** * Registers a new serverbound Noxesium packet. * - * @param id The identifier of this packet. - * @param The type of packet. + * @param id The identifier of this packet. + * @param The type of packet. * @return The PacketType instance. */ public static PacketType server(String id) { @@ -89,9 +96,9 @@ public static PacketType 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 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 The type of packet. * @return The PacketType instance. */ public static PacketType server(String id, String group) { diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccGameStatePacket.java b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccGameStatePacket.java new file mode 100644 index 00000000..353c25c1 --- /dev/null +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccGameStatePacket.java @@ -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 + *

+ * 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; + } +} diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccServerPacket.java b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccServerPacket.java new file mode 100644 index 00000000..39cc68ac --- /dev/null +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundMccServerPacket.java @@ -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; + } +}