implement GeometryCommands

This commit is contained in:
dfsek 2021-03-10 16:02:25 -07:00
parent 51fa58b481
commit 1f16a82a8d
6 changed files with 199 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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 <RADIUS> <DEFORM> <FREQUENCY>"
)
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);
}
}
}

View File

@ -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);
}
}

View File

@ -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 <RADIUS>"
)
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);
}
}
}

View File

@ -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 <RADIUS>"
)
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<Location, Location> 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);
}
}
}