Skip to content

Commit

Permalink
Setup initializations for Steamworks4J, changed a few settings around…
Browse files Browse the repository at this point in the history
…, and started on the FriendsList for the join game UI
  • Loading branch information
Permdog99 committed Nov 23, 2024
1 parent 596aabf commit a56b4f3
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 7 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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!");
}
}
Original file line number Diff line number Diff line change
@@ -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<FriendsList.Entry> {


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<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) {

}
}
}
45 changes: 41 additions & 4 deletions src/main/java/permdog99/steam_integration/SteamIntegration.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,67 @@
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;

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
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();
}
}
5 changes: 5 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
"fabricloader": ">=0.15",
"minecraft": "${mcdep}",
"fabric-api": "*"
},
"breaks": {
"e4mc": "*",
"world_host": "*",
"essential": "*"
}
}

0 comments on commit a56b4f3

Please sign in to comment.