diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java index 55d2c91..f4422f3 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java @@ -93,7 +93,8 @@ public class TerraCommand { } public static void register(CommandDispatcher dispatcher) { - dispatcher.register(command()); + registerSimple(dispatcher); + registerLocate(dispatcher); PermissionAPI.registerNode(Permissions.QUERY, DefaultPermissionLevel.OP, "Allows use of the query command"); PermissionAPI.registerNode(Permissions.DATA, DefaultPermissionLevel.OP, "Allows use of the data command"); PermissionAPI.registerNode(Permissions.DEFAULTS, DefaultPermissionLevel.OP, "Allows use of the defaults command"); @@ -101,8 +102,8 @@ public class TerraCommand { PermissionAPI.registerNode(Permissions.LOCATE, DefaultPermissionLevel.OP, "Allows use of the locate command"); } - private static LiteralArgumentBuilder command() { - return Commands.literal("terra") + private static void registerSimple(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal("terra") .then(Commands.literal("query") .requires(perm(Permissions.QUERY)) .executes(TerraCommand::query)) @@ -116,17 +117,35 @@ public class TerraCommand { .executes(TerraCommand::setDefaults))) .then(Commands.literal("debug") .requires(perm(Permissions.DEBUG)) - .executes(TerraCommand::debugBiome)) + .executes(TerraCommand::debugBiome))); + } + + private static void registerLocate(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal("terra") .then(Commands.literal("locate") .requires(perm(Permissions.LOCATE)) .then(Commands.argument("biome", BiomeArgType.biome()) - .executes(TerraCommand::findBiome) - .then(Commands.argument("terrain", TerrainArgType.terrain()) - .executes(TerraCommand::findTerrainAndBiome))) + .executes(TerraCommand::findBiome)))); + + dispatcher.register(Commands.literal("terra") + .then(Commands.literal("locate") + .requires(perm(Permissions.LOCATE)) + .then(Commands.argument("terrain", TerrainArgType.terrain()) + .executes(TerraCommand::findTerrain)))); + + dispatcher.register(Commands.literal("terra") + .then(Commands.literal("locate") + .requires(perm(Permissions.LOCATE)) + .then(Commands.argument("biome", BiomeArgType.biome()) + .then(Commands.argument("terrain", TerrainArgType.terrain()) + .executes(TerraCommand::findTerrainAndBiome))))); + + dispatcher.register(Commands.literal("terra") + .then(Commands.literal("locate") + .requires(perm(Permissions.LOCATE)) .then(Commands.argument("terrain", TerrainArgType.terrain()) - .executes(TerraCommand::findTerrain) .then(Commands.argument("biome", BiomeArgType.biome()) - .executes(TerraCommand::findTerrainAndBiome)))); + .executes(TerraCommand::findTerrainAndBiome))))); } private static int query(CommandContext context) throws CommandSyntaxException { @@ -205,7 +224,7 @@ public class TerraCommand { WorldGenerator worldGenerator = terraContext.factory.get(); Search search = new TerrainSearchTask(pos, worldGenerator, target); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); + context.getSource().sendFeedback(new StringTextComponent("Locating terrain..."), false); return Command.SINGLE_SUCCESS; } @@ -224,7 +243,7 @@ public class TerraCommand { IWorldReader reader = context.getSource().asPlayer().getServerWorld(); Search search = new BiomeSearchTask(pos, reader, biome); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); + context.getSource().sendFeedback(new StringTextComponent("Locating biome..."), false); return Command.SINGLE_SUCCESS; } @@ -248,7 +267,7 @@ public class TerraCommand { Search terrainSearch = new TerrainSearchTask(pos, worldGenerator, target); Search search = new BothSearchTask(pos, biomeSearch, terrainSearch); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); + context.getSource().sendFeedback(new StringTextComponent("Locating biome & terrain..."), false); return Command.SINGLE_SUCCESS; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java index ab2a4b3..0053536 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java @@ -37,7 +37,6 @@ import net.minecraft.command.ISuggestionProvider; import net.minecraft.command.arguments.IArgumentSerializer; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.Registry; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.biome.Biome; import net.minecraftforge.registries.ForgeRegistries; @@ -48,9 +47,28 @@ public class BiomeArgType implements ArgumentType { @Override public Biome parse(StringReader reader) throws CommandSyntaxException { - ResourceLocation resourcelocation = ResourceLocation.read(reader); - return Registry.BIOME.getValue(resourcelocation) - .orElseThrow(() -> createException("Invalid biome", "%s is not a valid biome", resourcelocation)); + int cursor = reader.getCursor(); + String raw = reader.getString().substring(cursor); + + if (raw.indexOf(':') == -1) { + reader.setCursor(cursor); + throw createException("Invalid biome", "%s is not a valid biome", raw); + } + + ResourceLocation resourcelocation = ResourceLocation.tryCreate(raw); + if (resourcelocation == null) { + reader.setCursor(cursor); + throw createException("Invalid biome", "%s is not a valid biome", raw); + } + + if (!ForgeRegistries.BIOMES.containsKey(resourcelocation)) { + reader.setCursor(cursor); + throw createException("Invalid biome", "%s is not a valid biome", resourcelocation); + } + + reader.setCursor(reader.getString().length()); + + return ForgeRegistries.BIOMES.getValue(resourcelocation); } @Override