-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup initializations for Steamworks4J, changed a few settings around…
…, and started on the FriendsList for the join game UI
- Loading branch information
Showing
6 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 42 additions & 1 deletion
43
src/client/java/permdog99/steam_integration/SteamIntegrationClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/client/java/permdog99/steam_integration/gui/screen/friends/FriendsList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/main/java/permdog99/steam_integration/SteamIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters