mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 01:15:08 +01:00
Enable commands in all environments
- Many command-related fixes and improvements - Added test environment for easier development
This commit is contained in:
@@ -9,6 +9,8 @@ import net.neoforged.fml.loading.FMLPaths;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static eu.midnightdust.neoforge.MidnightLibNeoForge.commands;
|
||||
|
||||
public class PlatformFunctionsImpl {
|
||||
public static String getPlatformName() {
|
||||
return "neoforge";
|
||||
@@ -26,6 +28,6 @@ public class PlatformFunctionsImpl {
|
||||
return ModList.get().isLoaded(modid);
|
||||
}
|
||||
public static void registerCommand(LiteralArgumentBuilder<ServerCommandSource> command) {
|
||||
// Ignored here, see MidnightLibNeoForge#registerCommands
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,16 @@ import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mod("midnightlib")
|
||||
public class MidnightLibNeoForge {
|
||||
public static List<LiteralArgumentBuilder<ServerCommandSource>> commands = new ArrayList<>();
|
||||
|
||||
public MidnightLibNeoForge() {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) MidnightLib.onInitializeClient();
|
||||
else MidnightLib.onInitializeServer();
|
||||
MidnightLib.onInitialize();
|
||||
}
|
||||
|
||||
@EventBusSubscriber(modid = "midnightlib", bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
@@ -38,9 +43,7 @@ public class MidnightLibNeoForge {
|
||||
public static class MidnightLibServerEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
for (LiteralArgumentBuilder<ServerCommandSource> command : AutoCommand.commands) {
|
||||
event.getDispatcher().register(command);
|
||||
}
|
||||
commands.forEach(command -> event.getDispatcher().register(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user