From 85467ee7fea733c680b842c6c3f9b813302b9f50 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 4 Sep 2023 23:42:19 +0100 Subject: [PATCH] Added a command for changing and resetting the sky angle --- .../unicopia/command/SkyAngleCommand.java | 33 +++++++++++++++++++ .../unicopia/command/UnicopiaCommand.java | 1 + .../resources/assets/unicopia/lang/en_us.json | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 src/main/java/com/minelittlepony/unicopia/command/SkyAngleCommand.java diff --git a/src/main/java/com/minelittlepony/unicopia/command/SkyAngleCommand.java b/src/main/java/com/minelittlepony/unicopia/command/SkyAngleCommand.java new file mode 100644 index 00000000..5beb54c6 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/SkyAngleCommand.java @@ -0,0 +1,33 @@ +package com.minelittlepony.unicopia.command; + +import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties; +import com.mojang.brigadier.arguments.FloatArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; + +class SkyAngleCommand { + static LiteralArgumentBuilder create() { + return CommandManager.literal("skyangle").requires(s -> s.hasPermissionLevel(2)) + .executes(context -> get(context.getSource())) + .then(CommandManager.literal("set") + .executes(context -> set(context.getSource(), 0)) + .then(CommandManager.argument("angle", FloatArgumentType.floatArg(0, 360)) + .executes(context -> set(context.getSource(), FloatArgumentType.getFloat(context, "angle"))))); + } + + static int get(ServerCommandSource source) throws CommandSyntaxException { + source.sendFeedback(() -> Text.translatable("commands.skyangle.get", UnicopiaWorldProperties.forWorld(source.getWorld()).getTangentalSkyAngle()), true); + return 0; + } + + static int set(ServerCommandSource source, float newAngle) { + UnicopiaWorldProperties.forWorld(source.getWorld()).setTangentalSkyAngle(newAngle); + source.sendFeedback(() -> Text.translatable("commands.skyangle.set", newAngle), true); + return 0; + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/command/UnicopiaCommand.java b/src/main/java/com/minelittlepony/unicopia/command/UnicopiaCommand.java index c2678484..508d912b 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/UnicopiaCommand.java +++ b/src/main/java/com/minelittlepony/unicopia/command/UnicopiaCommand.java @@ -14,6 +14,7 @@ class UnicopiaCommand { .then(SpeciesCommand.create(environment)) .then(RacelistCommand.create()) .then(WorldTribeCommand.create()) + .then(SkyAngleCommand.create()) .then(GravityCommand.create()) .then(DisguiseCommand.create(registries)) .then(CastCommand.create(registries)) diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index f777cda7..783a0bb6 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -628,6 +628,9 @@ "commands.race.permission": "Selected Race is not permitted by your current server", "commands.race.fail": "\"%s\" is not a recognised Race", + "commands.skyangle.get": "The current angle of the sun is %sdeg", + "commands.skyangle.set": "Changed sky angle to %sdeg", + "commands.race.tell.self": "You are a ", "commands.race.tell.self.alt": "You are an ", "commands.race.tell.other": "%s is a ",