From 52f6fec48c564370be6b5a9624dae1bbafd59e6a Mon Sep 17 00:00:00 2001 From: dags- Date: Thu, 30 Apr 2020 14:31:56 +0100 Subject: [PATCH] tweaks to terrain arg type --- .../terraforged/mod/command/TerraCommand.java | 8 +++++++- .../mod/command/arg/TerrainArgType.java | 17 ++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) 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 f4422f3..00b8a27 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java @@ -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; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java index 0fd01d1..9414ccb 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java @@ -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 { - private final List terrains; - - public TerrainArgType() { - this(Terrain.getRegistered()); - } - - public TerrainArgType(List terrains) { - this.terrains = terrains; - } + private final List terrains = createTerrainList(); @Override public Terrain parse(StringReader reader) throws CommandSyntaxException { @@ -88,6 +83,10 @@ public class TerrainArgType implements ArgumentType { ); } + private static List createTerrainList() { + return Terrains.create(new Settings()).index; + } + public static class Serializer implements IArgumentSerializer { @Override