From a56b4f377197ad0c201c0af67d59c4de9993435e Mon Sep 17 00:00:00 2001 From: Permdog99 <34215218+Permdog99@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:16:09 -0500 Subject: [PATCH] Setup initializations for Steamworks4J, changed a few settings around, and started on the FriendsList for the join game UI --- build.gradle.kts | 3 +- gradle.properties | 3 +- .../SteamIntegrationClient.java | 43 +++++++++++++++++- .../gui/screen/friends/FriendsList.java | 35 +++++++++++++++ .../steam_integration/SteamIntegration.java | 45 +++++++++++++++++-- src/main/resources/fabric.mod.json | 5 +++ 6 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 src/client/java/permdog99/steam_integration/gui/screen/friends/FriendsList.java diff --git a/build.gradle.kts b/build.gradle.kts index 3f896a2..c43932a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,7 +54,8 @@ dependencies { mappings(loom.officialMojangMappings()) modImplementation("net.fabricmc:fabric-loader:${deps["fabric_loader"]}") - implementation("com.code-disaster.steamworks4j:${deps["steamworks4j"]}") + implementation("com.code-disaster.steamworks4j:${deps["steamworks4j.client"]}") + implementation("com.code-disaster.steamworks4j:${deps["steamworks4j.server"]}") fapi( // Add modules from https://github.com/FabricMC/fabric diff --git a/gradle.properties b/gradle.properties index a836ea5..cb051d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,8 @@ mod.mc_targets=[VERSIONED] # Global dependencies deps.fabric_loader=0.16.3 -deps.steamworks4j=steamworks4j:1.9.0 +deps.steamworks4j.client=steamworks4j:1.9.0 +deps.steamworks4j.server=steamworks4j-server:1.9.0 # Versioned dependencies deps.yarn_build=[VERSIONED] diff --git a/src/client/java/permdog99/steam_integration/SteamIntegrationClient.java b/src/client/java/permdog99/steam_integration/SteamIntegrationClient.java index 6eaee45..0959d20 100644 --- a/src/client/java/permdog99/steam_integration/SteamIntegrationClient.java +++ b/src/client/java/permdog99/steam_integration/SteamIntegrationClient.java @@ -1,10 +1,51 @@ package permdog99.steam_integration; +import com.codedisaster.steamworks.SteamAPI; +import com.codedisaster.steamworks.SteamException; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.client.Minecraft; public class SteamIntegrationClient implements ClientModInitializer { @Override public void onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. + SteamIntegration.LOGGER.info("Initializing Client-side Steam Integration..."); + + SteamIntegration.LOGGER.info("Setting up Steam API..."); + this.tryLoadSteamAPI(); + // Begins ticking the Steam API + ClientTickEvents.START_CLIENT_TICK.register(this::tickSteamAPI); + + // Stops Steam API and functions + ClientLifecycleEvents.CLIENT_STOPPING.register(client -> stopSteamAPIFunctions()); + + SteamIntegration.LOGGER.info("Client-side Steam Integration has been initialized!"); + } + + public void tryLoadSteamAPI() { + try { + SteamAPI.loadLibraries(); + if (!SteamAPI.init()) { + // Steamworks initialization error, e.g. Steam client not running + SteamIntegration.LOGGER.warn("Steam is not running!"); + } else { + SteamIntegration.LOGGER.info("Steam API is initialized!"); + } + } catch (SteamException e) { + // Error extracting or loading native libraries + SteamIntegration.LOGGER.warn("Cannot find native Steam API libraries; either failed loading or extracting!"); + } + } + + private void tickSteamAPI(Minecraft client) { + if (SteamAPI.isSteamRunning()) { + SteamAPI.runCallbacks(); + } + } + + public static void stopSteamAPIFunctions() { + SteamAPI.shutdown(); + SteamIntegration.LOGGER.info("Stutting down Steam API... Done!"); } } \ No newline at end of file diff --git a/src/client/java/permdog99/steam_integration/gui/screen/friends/FriendsList.java b/src/client/java/permdog99/steam_integration/gui/screen/friends/FriendsList.java new file mode 100644 index 0000000..aa1bd1c --- /dev/null +++ b/src/client/java/permdog99/steam_integration/gui/screen/friends/FriendsList.java @@ -0,0 +1,35 @@ +package permdog99.steam_integration.gui.screen.friends; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.ObjectSelectionList; +import net.minecraft.network.chat.Component; + +public class FriendsList extends ObjectSelectionList { + + + public FriendsList(Minecraft minecraft, int i, int j, int k, int l, int m) { + super(minecraft, i, j, k, l, m); + } + + public abstract static class Entry extends ObjectSelectionList.Entry implements AutoCloseable { + public Entry() { + } + + public void close() { + } + } + + public class JoinableFriendsEntry extends Entry { + + @Override + public Component getNarration() { + return null; + } + + @Override + public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { + + } + } +} diff --git a/src/main/java/permdog99/steam_integration/SteamIntegration.java b/src/main/java/permdog99/steam_integration/SteamIntegration.java index 1001c31..c9c5849 100644 --- a/src/main/java/permdog99/steam_integration/SteamIntegration.java +++ b/src/main/java/permdog99/steam_integration/SteamIntegration.java @@ -1,6 +1,12 @@ package permdog99.steam_integration; +import com.codedisaster.steamworks.SteamAPI; +import com.codedisaster.steamworks.SteamException; +import com.codedisaster.steamworks.SteamGameServerAPI; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.server.MinecraftServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,7 +14,7 @@ public class SteamIntegration implements ModInitializer { // This logger is used to write text to the console and the log file. // It is considered best practice to use your mod id as the logger's name. // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger("template"); + public static final Logger LOGGER = LoggerFactory.getLogger("mc-steam-integration"); public static final String VERSION = /*$ mod_version*/ "0.1.0"; @Override @@ -16,15 +22,46 @@ public void onInitialize() { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. - - LOGGER.info("Hello Fabric world!"); + LOGGER.info("Initializing Server-side Steam Integration..."); //? if !release - LOGGER.warn("I'm still a template!"); + LOGGER.warn("Not on a release build of MC! Be warned!"); //? if fapi: <0.95 { LOGGER.info("Fabric API is old on this version"); LOGGER.info("Please update!"); //?} + + LOGGER.info("Setting up Steam GameServer API..."); + this.tryLoadSteamGameServerAPI(); + ServerTickEvents.START_SERVER_TICK.register(this::tickSteamGameServerAPI); + ServerLifecycleEvents.SERVER_STARTED.register(server -> stopSteamGameServerAPIFunctions()); + LOGGER.info("Server-side Steam Integration has been initialized!"); + } + + public void tryLoadSteamGameServerAPI() { + try { + SteamGameServerAPI.loadLibraries(); + if (!SteamGameServerAPI.init((127 << 24) + 1, (short) 27016, (short) 27017, + SteamGameServerAPI.ServerMode.NoAuthentication, "0.0.1")) { + // initialization error + LOGGER.warn("Steam GameServer API has failed to initialize!"); + } else { + LOGGER.info("Steam GameServer API is initialized!"); + } + } catch (SteamException e) { + // Error extracting or loading native libraries + LOGGER.warn("Cannot find native Steam GameServer API libraries; either failed loading or extracting!"); + } + } + + public void tickSteamGameServerAPI(MinecraftServer server) { + while (server.isRunning()) { + SteamGameServerAPI.runCallbacks(); + } + } + + public void stopSteamGameServerAPIFunctions() { + SteamGameServerAPI.shutdown(); } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1adf017..1e5a840 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,5 +33,10 @@ "fabricloader": ">=0.15", "minecraft": "${mcdep}", "fabric-api": "*" + }, + "breaks": { + "e4mc": "*", + "world_host": "*", + "essential": "*" } } \ No newline at end of file