diff --git a/src/main/java/com/teammoeg/frostedheart/events/FHCommonEvents.java b/src/main/java/com/teammoeg/frostedheart/events/FHCommonEvents.java index 3ac7d440f..726f58017 100644 --- a/src/main/java/com/teammoeg/frostedheart/events/FHCommonEvents.java +++ b/src/main/java/com/teammoeg/frostedheart/events/FHCommonEvents.java @@ -330,18 +330,6 @@ public static void onPotionRemove(MobEffectEvent.Remove event) { } - @SubscribeEvent - public static void onRegisterCommands(RegisterCommandsEvent event) { - CommandDispatcher dispatcher = event.getDispatcher(); - ResearchCommand.register(dispatcher); - DebugCommand.register(dispatcher); - ScenarioCommand.register(dispatcher); - TownCommand.register(dispatcher); - TipCommand.register(dispatcher); - WaterCommand.register(dispatcher); - NutritionCommand.register(dispatcher); - } - @SubscribeEvent public static void tickPlayer(PlayerTickEvent event) { if (event.side == LogicalSide.SERVER && event.phase == Phase.END diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ClimateCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ClimateCommand.java index 7091d6f83..ccc2dbd56 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ClimateCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ClimateCommand.java @@ -100,6 +100,11 @@ public static void register(RegisterCommandsEvent event) { return Command.SINGLE_SUCCESS; }); - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(Commands.literal("climate").then(get).then(init).then(rebuild).then(reset).then(app))); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(Commands.literal("climate").then(get).then(init).then(rebuild).then(reset).then(app))); + } + + // register a simple /climate comand to skip /fh climate + dispatcher.register(Commands.literal("climate").requires(s -> s.hasPermission(2)).then(get).then(init).then(rebuild).then(reset).then(app)); } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/DebugCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/DebugCommand.java index b4cc0c703..95d9ca68b 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/DebugCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/DebugCommand.java @@ -54,10 +54,16 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.loading.FMLPaths; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class DebugCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); LiteralArgumentBuilder add = Commands.literal("debug") .then(Commands.literal("generate_airship").executes(ct -> { FHFeatures.SPACECRAFT.get().place(NoneFeatureConfiguration.INSTANCE, ((ServerLevel) ct.getSource().getPlayerOrException().level()), ((ServerLevel) ct.getSource().getPlayerOrException().level()).getChunkSource().getGenerator(), ct.getSource().getPlayerOrException().level().random, @@ -270,7 +276,9 @@ public static void register(CommandDispatcher dispatcher) { return Command.SINGLE_SUCCESS; }))*/; - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(add)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(add)); + } } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/HeatAdjustCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/HeatAdjustCommand.java index 7d98ecbef..64854bccd 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/HeatAdjustCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/HeatAdjustCommand.java @@ -96,5 +96,8 @@ public static void register(RegisterCommandsEvent event) { for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(Commands.literal("heat_adjust").then(add).then(get).then(remove))); } + + // simple alias to skip modid + dispatcher.register(Commands.literal("heat_adjust").requires(s -> s.hasPermission(2)).then(add).then(get).then(remove)); } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/NutritionCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/NutritionCommand.java index 5e5edb672..f65221608 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/NutritionCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/NutritionCommand.java @@ -29,9 +29,15 @@ import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class NutritionCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); // Define nutrients String[] nutrients = {"fat", "carbohydrate", "protein", "vegetable"}; @@ -81,7 +87,9 @@ public static void register(CommandDispatcher dispatcher) { nutrition.then(nutrientCommand); } - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(nutrition)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(nutrition)); + } } private static float getNutrientValue(NutritionCapability data, String nutrient) { diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ResearchCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ResearchCommand.java index 29ab4f22d..66269bed1 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ResearchCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ResearchCommand.java @@ -44,9 +44,15 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.ChatFormatting; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ResearchCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); LiteralArgumentBuilder add = Commands.literal("research") // add insight .then(Commands.literal("insight").then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(0)).executes(ct -> { @@ -203,6 +209,8 @@ public static void register(CommandDispatcher dispatcher) { }catch(Throwable t) {t.printStackTrace();} return Command.SINGLE_SUCCESS; }))); - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(add)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(add)); + } } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ScenarioCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ScenarioCommand.java index 1127736aa..4756c89aa 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ScenarioCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/ScenarioCommand.java @@ -31,9 +31,15 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ScenarioCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); LiteralArgumentBuilder run=Commands.literal("scenario").then( Commands.literal("jump").then( @@ -81,7 +87,9 @@ public static void register(CommandDispatcher dispatcher) { return Command.SINGLE_SUCCESS; }))) ); - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(run)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(run)); + } } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TemperatureCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TemperatureCommand.java index 8a6d44bac..47fa0a7bd 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TemperatureCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TemperatureCommand.java @@ -96,5 +96,11 @@ public static void register(RegisterCommandsEvent event) { ) ); } + + dispatcher.register(Commands.literal("temperature") + .requires(s -> s.hasPermission(2)) + .then(get) + .then(set) + ); } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java index ecaf18486..d1a043fd2 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TipCommand.java @@ -32,10 +32,16 @@ import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.PacketDistributor; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class TipCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); LiteralArgumentBuilder run = Commands.literal("tips").then( Commands.literal("add").then( Commands.argument("targets", EntityArgument.players()).then( @@ -73,6 +79,8 @@ public static void register(CommandDispatcher dispatcher) { return i; } )))))))); - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(run)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(run)); + } } } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TownCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TownCommand.java index c5184823d..83b8e9be1 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TownCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/TownCommand.java @@ -34,9 +34,15 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class TownCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); LiteralArgumentBuilder name = Commands.literal("name") @@ -105,21 +111,40 @@ public static void register(CommandDispatcher dispatcher) { return Command.SINGLE_SUCCESS; }); - dispatcher.register(Commands.literal(FHMain.MODID) + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string) + .requires(s -> s.hasPermission(2)) + .then(Commands.literal("town") + .then(name) + .then(Commands.literal("resources") + .then(listResources) + .then(addResources) + ) + .then(Commands.literal("residents") + .then(listResidents) + .then(addResident) + ) + .then(Commands.literal("blocks") + .then(listBlocks) + ) + ) + ); + } + + // alias without modid + dispatcher.register(Commands.literal("town") .requires(s -> s.hasPermission(2)) - .then(Commands.literal("town") - .then(name) - .then(Commands.literal("resources") - .then(listResources) - .then(addResources) - ) - .then(Commands.literal("residents") - .then(listResidents) - .then(addResident) - ) - .then(Commands.literal("blocks") - .then(listBlocks) - ) + .then(name) + .then(Commands.literal("resources") + .then(listResources) + .then(addResources) + ) + .then(Commands.literal("residents") + .then(listResidents) + .then(addResident) + ) + .then(Commands.literal("blocks") + .then(listBlocks) ) ); } diff --git a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/WaterCommand.java b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/WaterCommand.java index dafcf8b3b..0c3722461 100644 --- a/src/main/java/com/teammoeg/frostedheart/infrastructure/command/WaterCommand.java +++ b/src/main/java/com/teammoeg/frostedheart/infrastructure/command/WaterCommand.java @@ -29,9 +29,15 @@ import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = FHMain.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class WaterCommand { - public static void register(CommandDispatcher dispatcher) { + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); // Get waterlevel from WaterLevelCapability LiteralArgumentBuilder water = Commands.literal("water") .then(Commands.literal("level") @@ -74,6 +80,21 @@ public static void register(CommandDispatcher dispatcher) { ) ); - dispatcher.register(Commands.literal(FHMain.MODID).requires(s -> s.hasPermission(2)).then(water)); + for (String string : new String[]{FHMain.MODID, FHMain.ALIAS, FHMain.TWRID}) { + dispatcher.register(Commands.literal(string).requires(s -> s.hasPermission(2)).then(water)); + } + + // create a simple alias command /drink for /fh water level fill + dispatcher.register(Commands.literal("drink") + .requires(s -> s.hasPermission(2)) + .executes(ct -> { + WaterLevelCapability.getCapability(ct.getSource().getPlayer()).ifPresent(data -> { + data.setWaterLevel(20); + ct.getSource().sendSuccess(()-> Lang.str("Water Level Filled").withStyle(ChatFormatting.BLUE), false); + }); + return Command.SINGLE_SUCCESS; + }) + ); + } }