Skip to content

Commit

Permalink
feat: Add /balm dev command to quickly change game rules to not be an…
Browse files Browse the repository at this point in the history
…noying during dev
  • Loading branch information
BlayTheNinth committed Jul 4, 2024
1 parent 595cded commit 9cebad9
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,42 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.GameRules;

import java.io.File;
import java.util.Objects;

public class BalmCommand {

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("balm")
.then(Commands.literal("dev").requires(BalmCommand::mayEnableDevMode).executes(context -> {
final var source = context.getSource();
final var server = source.getServer();
final var gameRules = server.getGameRules();
gameRules.getRule(GameRules.RULE_DAYLIGHT).set(false, server);
source.sendSuccess(() -> Component.literal("Daylight cycle disabled"), true);
gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).set(false, server);
source.sendSuccess(() -> Component.literal("Weather cycle disabled"), true);
gameRules.getRule(GameRules.RULE_KEEPINVENTORY).set(true, server);
source.sendSuccess(() -> Component.literal("Keep Inventory enabled"), true);
gameRules.getRule(GameRules.RULE_DOINSOMNIA).set(false, server);
source.sendSuccess(() -> Component.literal("Insomnia disabled"), true);
gameRules.getRule(GameRules.RULE_MOBGRIEFING).set(false, server);
source.sendSuccess(() -> Component.literal("Mob Griefing disabled"), true);
gameRules.getRule(GameRules.RULE_DO_TRADER_SPAWNING).set(false, server);
source.sendSuccess(() -> Component.literal("Trader Spawning disabled"), true);
server.setDifficulty(Difficulty.PEACEFUL, true);
source.sendSuccess(() -> Component.literal("Difficulty set to Peaceful"), true);
server.overworld().setWeatherParameters(99999, 0, false, false);
source.sendSuccess(() -> Component.literal("Weather cleared"), true);
for (final var level : server.getAllLevels()) {
level.setDayTime(1000);
}
source.sendSuccess(() -> Component.literal("Set the time to Daytime"), true);
return 0;
}))
.then(Commands.literal("export")
.then(Commands.literal("config").then(Commands.argument("class", StringArgumentType.greedyString()).executes(context -> {
final var className = context.getArgument("class", String.class);
Expand Down Expand Up @@ -48,4 +77,19 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
})))));
}

private static boolean mayEnableDevMode(CommandSourceStack it) {
if (it.hasPermission(2)) {
return true;
}

final var server = it.getServer();
if (server.isSingleplayer()) {
final var player = it.getPlayer();
if (player != null) {
return Objects.equals(player.getGameProfile(), server.getSingleplayerProfile());
}
}

return false;
}
}

0 comments on commit 9cebad9

Please sign in to comment.