remove biome commands

This commit is contained in:
dfsek 2021-12-19 19:53:21 -07:00
parent a8f12ae847
commit 03e8d0f381
6 changed files with 0 additions and 357 deletions

View File

@ -1,124 +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.biome.command.biome;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
/**
* Runnable that locates a biome asynchronously
*/
public class AsyncBiomeFinder implements Runnable {
protected final BiomeProvider provider;
protected final Biome 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 AsyncBiomeFinder(BiomeProvider provider, Biome target, @NotNull Vector3 origin, ServerWorld world, int startRadius,
int maxRadius,
Consumer<Vector3> callback, Platform platform) {
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.multiply(platform.getTerraConfig().getBiomeSearchResolution());
}
@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);
}
/**
* Helper method to get biome at location
*
* @param x X coordinate
* @param z Z coordinate
*
* @return TerraBiome at coordinates
*/
public boolean isValid(int x, int z, Biome target) {
int res = platform.getTerraConfig().getBiomeSearchResolution();
return getProvider().getBiome(x * res, z * res, world.getSeed()).equals(target);
}
public Biome 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,44 +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.biome.command.biome;
import com.dfsek.terra.addons.biome.UserDefinedBiome;
import com.dfsek.terra.api.Platform;
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.PlayerCommand;
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
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.world.biome.generation.BiomeProvider;
@Command(
subcommands = {
@Subcommand(value = "info", aliases = "i", clazz = BiomeInfoCommand.class),
@Subcommand(value = "locate", aliases = "l", clazz = BiomeLocateCommand.class)
},
usage = "/terra biome"
)
@WorldCommand
@PlayerCommand
public class BiomeCommand implements CommandTemplate {
@Inject
private Platform platform;
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
BiomeProvider provider = player.world().getBiomeProvider();
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.position(), player.world().getSeed());
sender.sendMessage("You are standing in " + biome.getID());
}
}

View File

@ -1,47 +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.biome.command.biome;
import com.dfsek.terra.addons.biome.BiomeTemplate;
import com.dfsek.terra.addons.biome.UserDefinedBiome;
import com.dfsek.terra.addons.biome.command.biome.arg.BiomeArgumentParser;
import com.dfsek.terra.addons.biome.command.biome.tab.BiomeTabCompleter;
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.entity.CommandSender;
import com.dfsek.terra.api.world.biome.Biome;
@Command(arguments = @Argument(
value = "biome",
tabCompleter = BiomeTabCompleter.class,
argumentParser = BiomeArgumentParser.class
))
public class BiomeInfoCommand implements CommandTemplate {
@ArgumentTarget("biome")
private Biome biome;
@Override
public void execute(CommandSender sender) {
sender.sendMessage("Biome info for \"" + biome.getID() + "\".");
sender.sendMessage("Vanilla biome: " + biome.getPlatformBiome());
if(biome instanceof UserDefinedBiome) {
BiomeTemplate bio = ((UserDefinedBiome) biome).getConfig();
if(bio.getExtended().size() == 0) {
sender.sendMessage("No Parent Biomes");
} else {
sender.sendMessage("------Parent Biomes-----");
bio.getExtended().forEach(id -> sender.sendMessage(" - " + id));
}
}
}
}

View File

@ -1,84 +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.biome.command.biome;
import java.util.Locale;
import com.dfsek.terra.addons.biome.command.biome.arg.BiomeArgumentParser;
import com.dfsek.terra.addons.biome.command.biome.tab.BiomeTabCompleter;
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.util.vector.Vector3;
import com.dfsek.terra.api.world.biome.Biome;
@PlayerCommand
@WorldCommand
@Command(arguments = {
@Argument(
value = "biome",
tabCompleter = BiomeTabCompleter.class,
argumentParser = BiomeArgumentParser.class
),
@Argument(
value = "radius",
required = false,
defaultValue = "1000",
argumentParser = IntegerArgumentParser.class
)
}, switches = @Switch(
value = "teleport",
aliases = { "t", "tp" }
))
public class BiomeLocateCommand implements CommandTemplate {
@ArgumentTarget("radius")
private Integer radius;
@ArgumentTarget("biome")
private Biome biome;
@SwitchTarget("teleport")
private boolean teleport;
@Inject
private Platform platform;
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome,
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)", biome.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 sender.sendMessage("Unable to locate biome \"" + biome.getID() + "\"");
}, platform), "Biome Location Thread").start();
}
}

View File

@ -1,27 +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.biome.command.biome.arg;
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.world.biome.Biome;
public class BiomeArgumentParser implements ArgumentParser<Biome> {
@Inject
private Platform platform;
@Override
public Biome parse(CommandSender sender, String arg) {
Player player = (Player) sender;
return player.world().getPack().getRegistry(Biome.class).get(arg).orElse(null);
}
}

View File

@ -1,31 +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.biome.command.biome.tab;
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.world.biome.Biome;
public class BiomeTabCompleter implements TabCompleter {
@Inject
private Platform platform;
@Override
public List<String> complete(CommandSender sender) {
Player player = (Player) sender;
return player.world().getPack().getRegistry(Biome.class).entries().stream().map(Biome::getID).collect(
Collectors.toList());
}
}