Enable commands in all environments

- Many command-related fixes and improvements
- Added test environment for easier development
This commit is contained in:
Martin Prokoph
2024-08-29 13:38:38 +02:00
parent 545a845add
commit db32a41e2b
14 changed files with 215 additions and 50 deletions

View File

@@ -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);
}
}

View File

@@ -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));
}
}
}