- fixed terrain types being parsed as biomes in the locate command

- tell the user the type of search being carried out by the locate command
This commit is contained in:
dags- 2020-04-30 13:18:11 +01:00
parent 971814f3dc
commit 0ea18b62ad
2 changed files with 53 additions and 16 deletions

View File

@ -93,7 +93,8 @@ public class TerraCommand {
} }
public static void register(CommandDispatcher<CommandSource> dispatcher) { public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(command()); registerSimple(dispatcher);
registerLocate(dispatcher);
PermissionAPI.registerNode(Permissions.QUERY, DefaultPermissionLevel.OP, "Allows use of the query command"); 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.DATA, DefaultPermissionLevel.OP, "Allows use of the data command");
PermissionAPI.registerNode(Permissions.DEFAULTS, DefaultPermissionLevel.OP, "Allows use of the defaults 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"); PermissionAPI.registerNode(Permissions.LOCATE, DefaultPermissionLevel.OP, "Allows use of the locate command");
} }
private static LiteralArgumentBuilder<CommandSource> command() { private static void registerSimple(CommandDispatcher<CommandSource> dispatcher) {
return Commands.literal("terra") dispatcher.register(Commands.literal("terra")
.then(Commands.literal("query") .then(Commands.literal("query")
.requires(perm(Permissions.QUERY)) .requires(perm(Permissions.QUERY))
.executes(TerraCommand::query)) .executes(TerraCommand::query))
@ -116,17 +117,35 @@ public class TerraCommand {
.executes(TerraCommand::setDefaults))) .executes(TerraCommand::setDefaults)))
.then(Commands.literal("debug") .then(Commands.literal("debug")
.requires(perm(Permissions.DEBUG)) .requires(perm(Permissions.DEBUG))
.executes(TerraCommand::debugBiome)) .executes(TerraCommand::debugBiome)));
}
private static void registerLocate(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(Commands.literal("terra")
.then(Commands.literal("locate") .then(Commands.literal("locate")
.requires(perm(Permissions.LOCATE)) .requires(perm(Permissions.LOCATE))
.then(Commands.argument("biome", BiomeArgType.biome()) .then(Commands.argument("biome", BiomeArgType.biome())
.executes(TerraCommand::findBiome) .executes(TerraCommand::findBiome))));
.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))));
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()) .then(Commands.argument("terrain", TerrainArgType.terrain())
.executes(TerraCommand::findTerrain)
.then(Commands.argument("biome", BiomeArgType.biome()) .then(Commands.argument("biome", BiomeArgType.biome())
.executes(TerraCommand::findTerrainAndBiome)))); .executes(TerraCommand::findTerrainAndBiome)))));
} }
private static int query(CommandContext<CommandSource> context) throws CommandSyntaxException { private static int query(CommandContext<CommandSource> context) throws CommandSyntaxException {
@ -205,7 +224,7 @@ public class TerraCommand {
WorldGenerator worldGenerator = terraContext.factory.get(); WorldGenerator worldGenerator = terraContext.factory.get();
Search search = new TerrainSearchTask(pos, worldGenerator, target); Search search = new TerrainSearchTask(pos, worldGenerator, target);
doSearch(server, playerID, search); doSearch(server, playerID, search);
context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); context.getSource().sendFeedback(new StringTextComponent("Locating terrain..."), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@ -224,7 +243,7 @@ public class TerraCommand {
IWorldReader reader = context.getSource().asPlayer().getServerWorld(); IWorldReader reader = context.getSource().asPlayer().getServerWorld();
Search search = new BiomeSearchTask(pos, reader, biome); Search search = new BiomeSearchTask(pos, reader, biome);
doSearch(server, playerID, search); doSearch(server, playerID, search);
context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); context.getSource().sendFeedback(new StringTextComponent("Locating biome..."), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@ -248,7 +267,7 @@ public class TerraCommand {
Search terrainSearch = new TerrainSearchTask(pos, worldGenerator, target); Search terrainSearch = new TerrainSearchTask(pos, worldGenerator, target);
Search search = new BothSearchTask(pos, biomeSearch, terrainSearch); Search search = new BothSearchTask(pos, biomeSearch, terrainSearch);
doSearch(server, playerID, search); doSearch(server, playerID, search);
context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); context.getSource().sendFeedback(new StringTextComponent("Locating biome & terrain..."), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }

View File

@ -37,7 +37,6 @@ import net.minecraft.command.ISuggestionProvider;
import net.minecraft.command.arguments.IArgumentSerializer; import net.minecraft.command.arguments.IArgumentSerializer;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@ -48,9 +47,28 @@ public class BiomeArgType implements ArgumentType<Biome> {
@Override @Override
public Biome parse(StringReader reader) throws CommandSyntaxException { public Biome parse(StringReader reader) throws CommandSyntaxException {
ResourceLocation resourcelocation = ResourceLocation.read(reader); int cursor = reader.getCursor();
return Registry.BIOME.getValue(resourcelocation) String raw = reader.getString().substring(cursor);
.orElseThrow(() -> createException("Invalid biome", "%s is not a valid biome", resourcelocation));
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 @Override