tweaks to terrain arg type

This commit is contained in:
dags- 2020-04-30 14:31:56 +01:00
parent 19e4990073
commit 52f6fec48c
2 changed files with 15 additions and 10 deletions

View File

@ -27,7 +27,6 @@ package com.terraforged.mod.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
@ -305,11 +304,18 @@ public class TerraCommand {
// the terrain parsed from the command will not be the same instance as used in the
// world generator, so find the matching instance by name
private static Terrain getTerrainInstance(Terrain find, Terrains terrains) {
// search for exact match first
for (Terrain t : terrains.index) {
if (t.getName().equals(find.getName())) {
return t;
}
}
// find a mixed terrain as a fallback
for (Terrain t : terrains.index) {
if (t.getName().contains("-") && t.getName().contains(find.getName())) {
return t;
}
}
return find;
}

View File

@ -33,27 +33,22 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.terraforged.core.settings.Settings;
import com.terraforged.core.world.terrain.Terrain;
import com.terraforged.core.world.terrain.Terrains;
import net.minecraft.command.ISuggestionProvider;
import net.minecraft.command.arguments.IArgumentSerializer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.StringTextComponent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class TerrainArgType implements ArgumentType<Terrain> {
private final List<Terrain> terrains;
public TerrainArgType() {
this(Terrain.getRegistered());
}
public TerrainArgType(List<Terrain> terrains) {
this.terrains = terrains;
}
private final List<Terrain> terrains = createTerrainList();
@Override
public Terrain parse(StringReader reader) throws CommandSyntaxException {
@ -88,6 +83,10 @@ public class TerrainArgType implements ArgumentType<Terrain> {
);
}
private static List<Terrain> createTerrainList() {
return Terrains.create(new Settings()).index;
}
public static class Serializer implements IArgumentSerializer<TerrainArgType> {
@Override