From 1f16a82a8d9f16ba8cc5e6ec977bb763b7a6963e Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:02:25 -0700 Subject: [PATCH] implement GeometryCommands --- .../com/dfsek/terra/commands/CommandUtil.java | 2 + .../dfsek/terra/commands/GeometryCommand.java | 12 ---- .../geometry/DeformedSphereCommand.java | 65 +++++++++++++++++++ .../commands/geometry/GeometryCommand.java | 39 +++++++++++ .../commands/geometry/SphereCommand.java | 44 +++++++++++++ .../terra/commands/geometry/TubeCommand.java | 49 ++++++++++++++ 6 files changed, 199 insertions(+), 12 deletions(-) delete mode 100644 common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index 3d2e3423a..a9e327d08 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -3,6 +3,7 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.commands.biome.BiomeCommand; +import com.dfsek.terra.commands.geometry.GeometryCommand; import com.dfsek.terra.commands.profiler.ProfileCommand; import com.dfsek.terra.commands.structure.StructureCommand; @@ -16,5 +17,6 @@ public final class CommandUtil { manager.register("getblock", GetBlockCommand.class); manager.register("packs", PacksCommand.class); manager.register("biome", BiomeCommand.class); + manager.register("geometry", GeometryCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java b/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java deleted file mode 100644 index 574c1d2b7..000000000 --- a/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.commands; - -import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.platform.CommandSender; -import com.dfsek.terra.config.lang.LangUtil; - -public class GeometryCommand implements CommandTemplate { - @Override - public void execute(CommandSender sender) { - LangUtil.send("command.geometry.main-menu", sender); - } -} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java new file mode 100644 index 000000000..46ce84559 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java @@ -0,0 +1,65 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.DoubleArgumentParser; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.DeformedSphere; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +import java.util.concurrent.ThreadLocalRandom; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ), + @Argument( + value = "deform", + argumentParser = DoubleArgumentParser.class + ), + @Argument( + value = "frequency", + argumentParser = DoubleArgumentParser.class + ) + }, + usage = "/terra geometry deformedsphere " +) +public class DeformedSphereCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @ArgumentTarget("deform") + private Double deform; + + @ArgumentTarget("frequency") + private Double frequency; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + OpenSimplex2Sampler noise = new OpenSimplex2Sampler(ThreadLocalRandom.current().nextInt()); + noise.setFrequency(frequency); + + DeformedSphere sphere = new DeformedSphere(player.getLocation().toVector(), radius, deform, noise); + for(Vector3 v : sphere.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java new file mode 100644 index 000000000..d41bc8506 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java @@ -0,0 +1,39 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; + + +@DebugCommand +@PlayerCommand +@Command( + subcommands = { + @Subcommand( + value = "sphere", + clazz = SphereCommand.class, + aliases = {"s"} + ), + @Subcommand( + value = "deformedsphere", + clazz = DeformedSphereCommand.class, + aliases = {"df"} + ), + @Subcommand( + value = "tube", + clazz = TubeCommand.class, + aliases = {"t"} + ) + }, + usage = "/terra geometry" +) +public class GeometryCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + LangUtil.send("command.geometry.main-menu", sender); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java new file mode 100644 index 000000000..7d8586e6a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java @@ -0,0 +1,44 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.Sphere; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ) + }, + usage = "/terra geometry sphere " +) +public class SphereCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + Sphere sphere = new Sphere(player.getLocation().toVector(), radius); + for(Vector3 v : sphere.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java new file mode 100644 index 000000000..b24694762 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java @@ -0,0 +1,49 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.Tube; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.util.generic.pair.Pair; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ) + }, + usage = "/terra geometry tube " +) +public class TubeCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + Pair locations = main.getWorldHandle().getSelectedLocation(player); + + Tube tube = new Tube(locations.getLeft().toVector(), locations.getRight().toVector(), radius); + + for(Vector3 v : tube.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +}