Skip to content

Commit

Permalink
Move command registers
Browse files Browse the repository at this point in the history
  • Loading branch information
yuesha-yc committed Dec 12, 2024
1 parent 9509dc5 commit 2122485
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 40 deletions.
12 changes: 0 additions & 12 deletions src/main/java/com/teammoeg/frostedheart/events/FHCommonEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,6 @@ public static void onPotionRemove(MobEffectEvent.Remove event) {

}

@SubscribeEvent
public static void onRegisterCommands(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
LiteralArgumentBuilder<CommandSourceStack> 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,
Expand Down Expand Up @@ -270,7 +276,9 @@ public static void register(CommandDispatcher<CommandSourceStack> 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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
// Define nutrients
String[] nutrients = {"fat", "carbohydrate", "protein", "vegetable"};

Expand Down Expand Up @@ -81,7 +87,9 @@ public static void register(CommandDispatcher<CommandSourceStack> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
LiteralArgumentBuilder<CommandSourceStack> add = Commands.literal("research")
// add insight
.then(Commands.literal("insight").then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(0)).executes(ct -> {
Expand Down Expand Up @@ -203,6 +209,8 @@ public static void register(CommandDispatcher<CommandSourceStack> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
LiteralArgumentBuilder<CommandSourceStack> run=Commands.literal("scenario").then(

Commands.literal("jump").then(
Expand Down Expand Up @@ -81,7 +87,9 @@ public static void register(CommandDispatcher<CommandSourceStack> 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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,11 @@ public static void register(RegisterCommandsEvent event) {
)
);
}

dispatcher.register(Commands.literal("temperature")
.requires(s -> s.hasPermission(2))
.then(get)
.then(set)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
LiteralArgumentBuilder<CommandSourceStack> run = Commands.literal("tips").then(
Commands.literal("add").then(
Commands.argument("targets", EntityArgument.players()).then(
Expand Down Expand Up @@ -73,6 +79,8 @@ public static void register(CommandDispatcher<CommandSourceStack> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();

LiteralArgumentBuilder<CommandSourceStack> name =
Commands.literal("name")
Expand Down Expand Up @@ -105,21 +111,40 @@ public static void register(CommandDispatcher<CommandSourceStack> 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)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack> dispatcher) {
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
// Get waterlevel from WaterLevelCapability
LiteralArgumentBuilder<CommandSourceStack> water = Commands.literal("water")
.then(Commands.literal("level")
Expand Down Expand Up @@ -74,6 +80,21 @@ public static void register(CommandDispatcher<CommandSourceStack> 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;
})
);

}
}

0 comments on commit 2122485

Please sign in to comment.