Skip to content

Commit

Permalink
Resolve some NeoForge FIXMEs
Browse files Browse the repository at this point in the history
ModLoadingContext can be supplied to the Mod's constructor, so using it.
  • Loading branch information
stewi1014 committed Nov 20, 2024
1 parent cd6cbc2 commit 1ca18be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.pcal.fastback.mod.neoforge;

import net.neoforged.fml.ModContainer;
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.common.NeoForge;
Expand Down Expand Up @@ -38,9 +39,9 @@ final class ForgeClientProvider extends ForgeCommonProvider {
private long hudTextTime;
private final Minecraft client;

public ForgeClientProvider() {
final IEventBus modEventBus = ModLoadingContext.get().getActiveContainer().getEventBus();
modEventBus.addListener(this::onClientStartupEvent);
public ForgeClientProvider(ModContainer container) {
super(container);
container.getEventBus().addListener(this::onClientStartupEvent);
NeoForge.EVENT_BUS.addListener(this::onGuiOverlayEvent);
NeoForge.EVENT_BUS.addListener(this::onScreenRenderEvent);
this.client = requireNonNull(Minecraft.getInstance(), "MinecraftClient.getInstance() returned null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.storage.LevelResource;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.bus.api.IEventBus;
Expand Down Expand Up @@ -40,13 +41,15 @@ class ForgeCommonProvider implements MinecraftProvider, MixinGateway {

static final String MOD_ID = "fastback";
private MinecraftServer logicalServer;
private ModContainer container;
private LifecycleListener lifecycleListener = null;
private Runnable autoSaveListener;
private boolean isWorldSaveEnabled = true;

ForgeCommonProvider() {
final IEventBus modEventBus = ModLoadingContext.get().getActiveContainer().getEventBus();
modEventBus.addListener(this::onDedicatedServerStartupEvent);
ForgeCommonProvider(ModContainer container) {
this.container = container;

container.getEventBus().addListener(this::onDedicatedServerStartupEvent);
NeoForge.EVENT_BUS.addListener(this::onServerStartupEvent);
NeoForge.EVENT_BUS.addListener(this::onServerStoppingEvent);
NeoForge.EVENT_BUS.addListener(this::onRegisterCommandEvent);
Expand Down Expand Up @@ -89,9 +92,9 @@ void onInitialize() {
this.lifecycleListener = MinecraftProvider.register(this);
syslog().debug("registered backup command");
this.lifecycleListener.onInitialize();
syslog().info("Fastback initialized");
syslog().info("Fastback " + getModVersion() + " initialized");
syslog().warn("------------------------------------------------------------------------------------");
syslog().warn("Thanks for trying the new Forge version of Fastback. For help, go to:");
syslog().warn("Thanks for trying the new NeoForge version of Fastback. For help, go to:");
syslog().warn("https://pcal43.github.io/fastback/");
syslog().warn("Please note that this is an alpha release. A list of known issues is available here:");
syslog().warn("https://github.com/pcal43/fastback/issues?q=is%3Aissue+is%3Aopen+label%3Aforge");
Expand Down Expand Up @@ -125,7 +128,7 @@ void renderOverlayText(GuiGraphics drawContext) {

@Override
public String getModVersion() {
return "0.15.3+1.20.1-alpha"; //FIXME
return container.getModInfo().getVersion().toString();
}

@Override
Expand Down Expand Up @@ -205,14 +208,10 @@ public void addBackupProperties(Map<String, String> props) {
@Override
public Collection<Path> getModsBackupPaths() {
final List<Path> out = new ArrayList<>();
/**
final FabricLoader fl = FabricLoader.getInstance();
final Path gameDir = fl.getGameDir();
out.add(gameDir.resolve("options.txt´"));
out.add(gameDir.resolve("mods"));
out.add(gameDir.resolve("config"));
out.add(gameDir.resolve("resourcepacks"));
**/
out.add(FMLPaths.GAMEDIR.get().resolve("options.txt"));
out.add(FMLPaths.MODSDIR.get());
out.add(FMLPaths.CONFIGDIR.get());
out.add(FMLPaths.GAMEDIR.get().resolve("resourcepacks"));
return out;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.pcal.fastback.mod.neoforge;

import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLEnvironment;

Expand All @@ -12,13 +14,13 @@
@Mod("fastback")
final public class ForgeInitializer {

public ForgeInitializer() {
public ForgeInitializer(ModContainer container) {
try {
if (FMLEnvironment.dist.isDedicatedServer()) {
new ForgeCommonProvider();
new ForgeCommonProvider(container);
} else if (FMLEnvironment.dist.isClient()) {
// Forge yells at us if we touch any client classes in a server. So,
Class.forName("net.pcal.fastback.mod.neoforge.ForgeClientProvider").getConstructor().newInstance();
Class.forName("net.pcal.fastback.mod.neoforge.ForgeClientProvider").getConstructor(ModContainer.class).newInstance(container);
} else {
throw new IllegalStateException("where am i? server or client?");
}
Expand All @@ -27,4 +29,4 @@ public ForgeInitializer() {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public void warn(String message) {
}

@Override
public void warn(String message, Throwable t) {
this.slf4j.warn(message, t);
}
public void warn(String message, Throwable t) {this.slf4j.warn(message, t);}

@Override
public void info(String message) {
Expand Down

0 comments on commit 1ca18be

Please sign in to comment.