diff --git a/src/main/java/org/dimdev/dimdoors/command/ModCommands.java b/src/main/java/org/dimdev/dimdoors/command/ModCommands.java index 86c5d30e..c4f41bf2 100644 --- a/src/main/java/org/dimdev/dimdoors/command/ModCommands.java +++ b/src/main/java/org/dimdev/dimdoors/command/ModCommands.java @@ -9,6 +9,7 @@ public final class ModCommands { SchematicCommand.register(dispatcher); PocketCommand.register(dispatcher); SaveSchemCommand.register(dispatcher); + SchematicV2Command.register(dispatcher); }); } } diff --git a/src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java b/src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java index 5f997543..2b4932f6 100644 --- a/src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java +++ b/src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java @@ -3,57 +3,44 @@ package org.dimdev.dimdoors.command; import java.io.IOException; import java.io.InputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.dimdev.dimcore.schematic.v2.Schematic; import org.dimdev.dimcore.schematic.v2.SchematicPlacer; +import org.dimdev.dimdoors.command.arguments.SchematicNamespaceArgumentType; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.nbt.NbtIo; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.TranslatableText; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class SchematicV2Command { + private static final Logger LOGGER = LogManager.getLogger(); + public static void register(CommandDispatcher dispatcher) { dispatcher.register(literal("schematicv2") - // TODO: Create an argument type for this - .then(literal("ruins") + .then(argument("namespace", new SchematicNamespaceArgumentType()) .then(argument("schematic_name", StringArgumentType.string()) - .executes((ctx) -> place(ctx, "ruins")) - ) - ) - .then(literal("blank") - .then(argument("schematic_name", StringArgumentType.string()) - .executes((ctx) -> place(ctx, "blank")) - ) - ) - .then(literal("nether") - .then(argument("schematic_name", StringArgumentType.string()) - .executes((ctx) -> place(ctx, "nether")) - ) - ) - .then(literal("private") - .then(argument("schematic_name", StringArgumentType.string()) - .executes((ctx) -> place(ctx, "private")) - ) - ) - .then(literal("public") - .then(argument("schematic_name", StringArgumentType.string()) - .executes((ctx) -> place(ctx, "public")) + .executes(SchematicV2Command::place) ) ) ); } - private static int place(CommandContext ctx, String namespace) throws CommandSyntaxException { + private static int place(CommandContext ctx) throws CommandSyntaxException { ServerPlayerEntity player = ctx.getSource().getPlayer(); String id = StringArgumentType.getString(ctx, "schematic_name"); + String ns = SchematicNamespaceArgumentType.getValue(ctx, "namespace"); - try (InputStream in = SchematicCommand.class.getResourceAsStream("/data/dimdoors/pockets/schematic/v2/" + namespace + "/" + id + ".schem")) { + try (InputStream in = SchematicCommand.class.getResourceAsStream("/data/dimdoors/pockets/schematic/v2/" + ns + "/" + id + ".schem")) { SchematicPlacer.place( Schematic.fromTag(NbtIo.readCompressed(in)), ctx.getSource().getWorld(), @@ -61,9 +48,10 @@ public class SchematicV2Command { ); } catch (IOException e) { e.printStackTrace(); + throw new SimpleCommandExceptionType(new TranslatableText("command.dimdoors.schematicv2.unknownSchematic", id, ns)).create(); } - System.out.println(id + " placed"); + LOGGER.info(String.format("Placed schematic %s from namespace %s at %s in world %s", id, ns, player.getBlockPos(), player.getServerWorld().getRegistryKey().getValue())); return 1; } } diff --git a/src/main/java/org/dimdev/dimdoors/command/arguments/SchematicNamespaceArgumentType.java b/src/main/java/org/dimdev/dimdoors/command/arguments/SchematicNamespaceArgumentType.java new file mode 100644 index 00000000..bddfe00e --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/command/arguments/SchematicNamespaceArgumentType.java @@ -0,0 +1,35 @@ +package org.dimdev.dimdoors.command.arguments; + +import java.util.Collection; +import java.util.Objects; + +import com.google.common.collect.ImmutableList; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; + +import net.minecraft.text.TranslatableText; + +public class SchematicNamespaceArgumentType implements ArgumentType { + private static final Collection EXAMPLES = ImmutableList.of("ruins", "blank", "nether", "private", "public"); + + @Override + public String parse(StringReader reader) throws CommandSyntaxException { + String value = Objects.requireNonNull(reader.readString()); + if (!EXAMPLES.contains(value)) { + throw new SimpleCommandExceptionType(new TranslatableText("argument.dimdoors.schematic.invalidNamespace", String.join(", ", EXAMPLES), value)).create(); + } + return value; + } + + @Override + public Collection getExamples() { + return EXAMPLES; + } + + public static String getValue(CommandContext context, final String name) { + return context.getArgument(name, String.class); + } +} diff --git a/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java b/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java index 285cf608..e309285a 100644 --- a/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java +++ b/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java @@ -22,37 +22,21 @@ import net.minecraft.world.gen.feature.Feature; import net.fabricmc.loader.api.FabricLoader; public final class ModFeatures { - public static final Feature GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway"), new SchematicGatewayFeature(SchematicGatewayFeatureConfig.CODEC)); public static final Feature GATEWAY_FEATURE_V2 = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway_v2"), new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC)); - public static final SchematicGateway SANDSTONE_PILLARS_GATEWAY; - public static final SchematicGateway TWO_PILLARS_GATEWAY; public static final SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY_V2; public static final ConfiguredFeature SANDSTONE_PILLARS_FEATURE_V2; - public static final ConfiguredFeature SANDSTONE_PILLARS_FEATURE; - public static final ConfiguredFeature TWO_PILLARS_FEATURE; public static void init() { Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars_v2"), SANDSTONE_PILLARS_FEATURE_V2); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "two_pillars"), TWO_PILLARS_FEATURE); } static { ModBlocks.init(); - - SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsGateway(); - TWO_PILLARS_GATEWAY = new TwoPillarsGateway(); SANDSTONE_PILLARS_GATEWAY_V2 = new SandstonePillarsV2Gateway(); - int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 50 : ModConfig.WORLD.gatewayGenChance; + int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : ModConfig.WORLD.gatewayGenChance; SANDSTONE_PILLARS_FEATURE_V2 = GATEWAY_FEATURE_V2.configure(new SchematicV2GatewayFeatureConfig(SchematicV2Gateway.SCHEMATIC_ID_MAP.get(SANDSTONE_PILLARS_GATEWAY_V2))) .decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP .applyChance(gatewayChance)); - SANDSTONE_PILLARS_FEATURE = GATEWAY_FEATURE.configure(new SchematicGatewayFeatureConfig(SchematicGateway.SCHEMATIC_ID_MAP.get(SANDSTONE_PILLARS_GATEWAY))) - .decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP - .applyChance(gatewayChance)); - TWO_PILLARS_FEATURE = GATEWAY_FEATURE.configure(new SchematicGatewayFeatureConfig(SchematicGateway.SCHEMATIC_ID_MAP.get(TWO_PILLARS_GATEWAY))) - .decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP - .applyChance(gatewayChance)); } } diff --git a/src/main/resources/assets/dimdoors/lang/en_us.json b/src/main/resources/assets/dimdoors/lang/en_us.json index d11ae497..a698d8c8 100644 --- a/src/main/resources/assets/dimdoors/lang/en_us.json +++ b/src/main/resources/assets/dimdoors/lang/en_us.json @@ -184,5 +184,7 @@ "dimdoors.graphics.riftSize": "Rift Size", "dimdoors.graphics.riftSize.tooltip": "Multiplier affecting how large rifts should be rendered, 1 being the default size.", "dimdoors.graphics.riftJitter": "Rift Jitter", - "dimdoors.graphics.riftJitter.tooltip": "Multiplier affecting how much rifts should jitter, 1 being the default size." + "dimdoors.graphics.riftJitter.tooltip": "Multiplier affecting how much rifts should jitter, 1 being the default size.", + "argument.dimdoors.schematic.invalidNamespace": "Invalid schematic namespace. Expected one of %s, found %s.", + "command.dimdoors.schematicv2.unknownSchematic": "Unknown schematic \"%s\" in namespace \"%s\" " } \ No newline at end of file