remove old structure commands

This commit is contained in:
dfsek
2021-12-19 19:54:34 -07:00
parent 03e8d0f381
commit 4c01cb4b8d
9 changed files with 0 additions and 462 deletions

View File

@@ -1,118 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
public class AsyncStructureFinder implements Runnable {
protected final BiomeProvider provider;
protected final ConfiguredStructure target;
protected final int startRadius;
protected final int maxRadius;
protected final int centerX;
protected final int centerZ;
protected final ServerWorld world;
protected final Platform platform;
private final Consumer<Vector3> callback;
protected int searchSize = 1;
public AsyncStructureFinder(BiomeProvider provider, ConfiguredStructure target, @NotNull Vector3 origin, ServerWorld world,
int startRadius,
int maxRadius, Consumer<Vector3> callback, Platform platform) {
//setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
this.provider = provider;
this.target = target;
this.platform = platform;
this.startRadius = startRadius;
this.maxRadius = maxRadius;
this.centerX = origin.getBlockX();
this.centerZ = origin.getBlockZ();
this.world = world;
this.callback = callback;
}
public Vector3 finalizeVector(Vector3 orig) {
return orig;//target.getSpawn().getChunkSpawn(orig.getBlockX(), orig.getBlockZ(), world.getSeed());
}
@Override
public void run() {
int x = centerX;
int z = centerZ;
x /= searchSize;
z /= searchSize;
int run = 1;
boolean toggle = true;
boolean found = false;
main:
for(int i = startRadius; i < maxRadius; i++) {
for(int j = 0; j < run; j++) {
if(isValid(x, z, target)) {
found = true;
break main;
}
if(toggle) x += 1;
else x -= 1;
}
for(int j = 0; j < run; j++) {
if(isValid(x, z, target)) {
found = true;
break main;
}
if(toggle) z += 1;
else z -= 1;
}
run++;
toggle = !toggle;
}
Vector3 finalSpawn = found ? finalizeVector(new Vector3(x, 0, z)) : null;
callback.accept(finalSpawn);
}
public boolean isValid(int x, int z, ConfiguredStructure target) {
//Vector3 spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed());
//if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
//Random random = new Random(PopulationUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn
// .getBlockZ(), 16), world.getSeed()));
//return target.getStructure().get(random).test(spawn.setY(target.getSpawnStart().get(random)), world, random, Rotation
// .fromDegrees(90 * random.nextInt(4)));
return false;
}
public ConfiguredStructure getTarget() {
return target;
}
public ServerWorld getWorld() {
return world;
}
public BiomeProvider getProvider() {
return provider;
}
public int getSearchSize() {
return searchSize;
}
public void setSearchSize(int searchSize) {
this.searchSize = searchSize;
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure;
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.entity.CommandSender;
@Command(
subcommands = {
@Subcommand(
clazz = StructureLoadCommand.class,
value = "load",
aliases = "ld"
),
@Subcommand(
clazz = StructureLocateCommand.class,
value = "locate",
aliases = "l"
)
},
usage = "/te structure"
)
public class StructureCommand implements CommandTemplate {
@Override
public void execute(CommandSender sender) {
//LangUtil.send("command.structure.main-menu", sender);
}
}

View File

@@ -1,92 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import com.dfsek.terra.addons.structure.command.structure.argument.ScriptArgumentParser;
import com.dfsek.terra.addons.structure.command.structure.completer.RotationCompleter;
import com.dfsek.terra.addons.structure.command.structure.completer.ScriptCompleter;
import com.dfsek.terra.api.Platform;
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.Switch;
import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
import com.dfsek.terra.api.command.annotation.inject.SwitchTarget;
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
import com.dfsek.terra.api.command.arg.IntegerArgumentParser;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
@PlayerCommand
@DebugCommand
@WorldCommand
@Command(arguments = {
@Argument(
value = "structure",
tabCompleter = ScriptCompleter.class,
argumentParser = ScriptArgumentParser.class
),
@Argument(
value = "rotation",
required = false,
tabCompleter = RotationCompleter.class,
argumentParser = IntegerArgumentParser.class,
defaultValue = "0"
)
}, switches = @Switch(value = "chunk",
aliases = "c"
), usage = "/terra structure load [ROTATION] [-c]")
public class StructureLoadCommand implements CommandTemplate {
@ArgumentTarget("rotation")
private final Integer rotation = 0;
@SwitchTarget("chunk")
private boolean chunk;
@ArgumentTarget("structure")
private Structure script;
@Inject
private Platform platform;
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
long t = System.nanoTime();
Random random = new Random(ThreadLocalRandom.current().nextLong());
Rotation r;
try {
r = Rotation.fromDegrees(rotation);
} catch(Exception e) {
sender.sendMessage("Invalid rotation: " + rotation);
return;
}
if(script == null) {
sender.sendMessage("Invalid structure.");
return;
}
if(this.chunk) {
script.generate(player.position(), player.world(), player.world().getChunkAt(player.position()), random, r);
} else {
script.generate(player.position(), player.world(), random, r);
}
long l = System.nanoTime() - t;
sender.sendMessage("Took " + ((double) l) / 1000000 + "ms");
}
}

View File

@@ -1,82 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure;
import java.util.Locale;
import com.dfsek.terra.addons.structure.command.AsyncStructureFinder;
import com.dfsek.terra.addons.structure.command.structure.argument.StructureArgumentParser;
import com.dfsek.terra.addons.structure.command.structure.completer.StructureCompleter;
import com.dfsek.terra.api.Platform;
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.Switch;
import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
import com.dfsek.terra.api.command.annotation.inject.SwitchTarget;
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
import com.dfsek.terra.api.command.arg.IntegerArgumentParser;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
import com.dfsek.terra.api.util.vector.Vector3;
@PlayerCommand
@WorldCommand
@Command(arguments = {
@Argument(
value = "structure",
tabCompleter = StructureCompleter.class,
argumentParser = StructureArgumentParser.class
),
@Argument(
value = "radius",
required = false,
defaultValue = "100",
argumentParser = IntegerArgumentParser.class
)
}, switches = @Switch(
value = "teleport",
aliases = { "t", "tp" }
))
public class StructureLocateCommand implements CommandTemplate {
@Inject
private Platform platform;
@ArgumentTarget("structure")
private ConfiguredStructure structure;
@ArgumentTarget("radius")
private Integer radius;
@SwitchTarget("teleport")
private boolean teleport;
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
new Thread(new AsyncStructureFinder(player.world().getBiomeProvider(), structure,
player.position().clone().multiply((1D / platform.getTerraConfig().getBiomeSearchResolution())),
player.world(), 0, radius, location -> {
if(location != null) {
sender.sendMessage(
String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getID().toLowerCase(Locale.ROOT),
location.getBlockX(), location.getBlockZ(),
location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) {
platform.runPossiblyUnsafeTask(
() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
}
} //else LangUtil.send("command.biome.unable-to-locate", sender);
}, platform), "Biome Location Thread").start();
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure.argument;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.command.arg.ArgumentParser;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.Structure;
public class ScriptArgumentParser implements ArgumentParser<Structure> {
@Inject
private Platform platform;
@Override
public Structure parse(CommandSender sender, String arg) {
return ((Player) sender).world().getPack().getRegistry(Structure.class).get(arg).orElse(null);
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure.argument;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.command.arg.ArgumentParser;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
public class StructureArgumentParser implements ArgumentParser<ConfiguredStructure> {
@Inject
private Platform platform;
@Override
public ConfiguredStructure parse(CommandSender sender, String arg) {
return ((Player) sender).world().getPack().getRegistry(ConfiguredStructure.class).get(arg).orElse(null);
}
}

View File

@@ -1,22 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure.completer;
import java.util.Arrays;
import java.util.List;
import com.dfsek.terra.api.command.tab.TabCompleter;
import com.dfsek.terra.api.entity.CommandSender;
public class RotationCompleter implements TabCompleter {
@Override
public List<String> complete(CommandSender sender) {
return Arrays.asList("0", "90", "180", "270");
}
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure.completer;
import java.util.List;
import java.util.stream.Collectors;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.command.tab.TabCompleter;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.Structure;
public class ScriptCompleter implements TabCompleter {
@Inject
private Platform platform;
@Override
public List<String> complete(CommandSender sender) {
return ((Player) sender).world().getPack().getRegistry(Structure.class).entries().stream().map(Structure::getID).collect(
Collectors.toList());
}
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in this module's root directory.
*/
package com.dfsek.terra.addons.structure.command.structure.completer;
import java.util.ArrayList;
import java.util.List;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.command.tab.TabCompleter;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
public class StructureCompleter implements TabCompleter {
@Inject
private Platform platform;
@Override
public List<String> complete(CommandSender sender) {
Player player = (Player) sender;
return new ArrayList<>(player.world().getPack().getRegistry(ConfiguredStructure.class).keys());
}
}