Skip to content

Commit

Permalink
Tidy up NeoForge/Forge mod init
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Nov 2, 2024
1 parent ef507b1 commit 41a1117
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected void sendStatisticsToSocket() {
viewerSocket.sendUpdatedStatistics(platform, system);
}
} catch (Exception e) {
platform.getPlugin().log(Level.WARNING, "Exception occurred while sending statistics to viewer", e);
this.platform.getPlugin().log(Level.WARNING, "Exception occurred while sending statistics to viewer", e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spark-fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
modImplementation(fabricApi.module(it, '0.106.1+1.21.3'))
}

include(modImplementation('me.lucko:fabric-permissions-api:0.3.2'))
include(modImplementation('me.lucko:fabric-permissions-api:0.3.3'))

modImplementation('eu.pb4:placeholder-api:2.5.0+1.21.2')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onInitialize() {
CommandRegistrationCallback.EVENT.register(this::onServerCommandRegister);
}

// client (called be entrypoint defined in fabric.mod.json)
// client (called by entrypoint defined in fabric.mod.json)
public static void initializeClient() {
Objects.requireNonNull(FabricSparkMod.mod, "mod");
FabricClientSparkPlugin.register(FabricSparkMod.mod, MinecraftClient.getInstance());
Expand Down
26 changes: 9 additions & 17 deletions spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;

Expand All @@ -39,26 +37,23 @@
@Mod("spark")
public class ForgeSparkMod {

private ModContainer container;
private Path configDirectory;
private final ModContainer container;
private final Path configDirectory;

public ForgeSparkMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientInit);
MinecraftForge.EVENT_BUS.register(this);
public ForgeSparkMod(FMLJavaModLoadingContext ctx) {
this.container = ctx.getContainer();
this.configDirectory = FMLPaths.CONFIGDIR.get().resolve(this.container.getModId());

ModLoadingContext.get().registerDisplayTest(IExtensionPoint.DisplayTest.IGNORE_ALL_VERSION);
ctx.getModEventBus().addListener(this::clientInit);
ctx.registerDisplayTest(IExtensionPoint.DisplayTest.IGNORE_ALL_VERSION);

MinecraftForge.EVENT_BUS.register(this);
}

public String getVersion() {
return this.container.getModInfo().getVersion().toString();
}

public void setup(FMLCommonSetupEvent e) {
this.container = ModLoadingContext.get().getActiveContainer();
this.configDirectory = FMLPaths.CONFIGDIR.get().resolve(this.container.getModId());
}

public void clientInit(FMLClientSetupEvent e) {
ForgeClientSparkPlugin.register(this, e);
}
Expand All @@ -69,9 +64,6 @@ public void serverInit(ServerAboutToStartEvent e) {
}

public Path getConfigDirectory() {
if (this.configDirectory == null) {
throw new IllegalStateException("Config directory not set");
}
return this.configDirectory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerAboutToStartEvent;
Expand All @@ -38,27 +36,22 @@
@Mod("spark")
public class NeoForgeSparkMod {

private ModContainer container;
private Path configDirectory;
private final ModContainer container;
private final Path configDirectory;

private IEventBus eventBus;
public NeoForgeSparkMod(ModContainer container, IEventBus eventBus) {
this.container = container;
this.configDirectory = FMLPaths.CONFIGDIR.get().resolve(this.container.getModId());

public NeoForgeSparkMod(IEventBus eventBus) {
this.eventBus = eventBus;
eventBus.addListener(this::setup);
eventBus.addListener(this::clientInit);

NeoForge.EVENT_BUS.register(this);
}

public String getVersion() {
return this.container.getModInfo().getVersion().toString();
}

public void setup(FMLCommonSetupEvent e) {
this.container = ModLoadingContext.get().getActiveContainer();
this.configDirectory = FMLPaths.CONFIGDIR.get().resolve(this.container.getModId());
}

public void clientInit(FMLClientSetupEvent e) {
NeoForgeClientSparkPlugin.register(this, e);
}
Expand All @@ -69,9 +62,6 @@ public void serverInit(ServerAboutToStartEvent e) {
}

public Path getConfigDirectory() {
if (this.configDirectory == null) {
throw new IllegalStateException("Config directory not set");
}
return this.configDirectory;
}
}

0 comments on commit 41a1117

Please sign in to comment.