New schematic argument type
Changes to be committed: modified: src/main/java/org/dimdev/dimdoors/command/ModCommands.java modified: src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java new file: src/main/java/org/dimdev/dimdoors/command/arguments/SchematicNamespaceArgumentType.java modified: src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java modified: src/main/resources/assets/dimdoors/lang/en_us.json
This commit is contained in:
parent
c452eaa502
commit
6a6d3ecb9b
5 changed files with 54 additions and 44 deletions
|
@ -9,6 +9,7 @@ public final class ModCommands {
|
||||||
SchematicCommand.register(dispatcher);
|
SchematicCommand.register(dispatcher);
|
||||||
PocketCommand.register(dispatcher);
|
PocketCommand.register(dispatcher);
|
||||||
SaveSchemCommand.register(dispatcher);
|
SaveSchemCommand.register(dispatcher);
|
||||||
|
SchematicV2Command.register(dispatcher);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,57 +3,44 @@ package org.dimdev.dimdoors.command;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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.Schematic;
|
||||||
import org.dimdev.dimcore.schematic.v2.SchematicPlacer;
|
import org.dimdev.dimcore.schematic.v2.SchematicPlacer;
|
||||||
|
import org.dimdev.dimdoors.command.arguments.SchematicNamespaceArgumentType;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
|
|
||||||
import net.minecraft.nbt.NbtIo;
|
import net.minecraft.nbt.NbtIo;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
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.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
public class SchematicV2Command {
|
public class SchematicV2Command {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
dispatcher.register(literal("schematicv2")
|
dispatcher.register(literal("schematicv2")
|
||||||
// TODO: Create an argument type for this
|
.then(argument("namespace", new SchematicNamespaceArgumentType())
|
||||||
.then(literal("ruins")
|
|
||||||
.then(argument("schematic_name", StringArgumentType.string())
|
.then(argument("schematic_name", StringArgumentType.string())
|
||||||
.executes((ctx) -> place(ctx, "ruins"))
|
.executes(SchematicV2Command::place)
|
||||||
)
|
|
||||||
)
|
|
||||||
.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"))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int place(CommandContext<ServerCommandSource> ctx, String namespace) throws CommandSyntaxException {
|
private static int place(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
|
||||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||||
String id = StringArgumentType.getString(ctx, "schematic_name");
|
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(
|
SchematicPlacer.place(
|
||||||
Schematic.fromTag(NbtIo.readCompressed(in)),
|
Schematic.fromTag(NbtIo.readCompressed(in)),
|
||||||
ctx.getSource().getWorld(),
|
ctx.getSource().getWorld(),
|
||||||
|
@ -61,9 +48,10 @@ public class SchematicV2Command {
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String> {
|
||||||
|
private static final Collection<String> 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<String> getExamples() {
|
||||||
|
return EXAMPLES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValue(CommandContext<?> context, final String name) {
|
||||||
|
return context.getArgument(name, String.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,37 +22,21 @@ import net.minecraft.world.gen.feature.Feature;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
public final class ModFeatures {
|
public final class ModFeatures {
|
||||||
public static final Feature<SchematicGatewayFeatureConfig> GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway"), new SchematicGatewayFeature(SchematicGatewayFeatureConfig.CODEC));
|
|
||||||
public static final Feature<SchematicV2GatewayFeatureConfig> GATEWAY_FEATURE_V2 = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "gateway_v2"), new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC));
|
public static final Feature<SchematicV2GatewayFeatureConfig> 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 SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY_V2;
|
||||||
public static final ConfiguredFeature<?, ?> SANDSTONE_PILLARS_FEATURE_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() {
|
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_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 {
|
static {
|
||||||
ModBlocks.init();
|
ModBlocks.init();
|
||||||
|
|
||||||
SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsGateway();
|
|
||||||
TWO_PILLARS_GATEWAY = new TwoPillarsGateway();
|
|
||||||
SANDSTONE_PILLARS_GATEWAY_V2 = new SandstonePillarsV2Gateway();
|
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)))
|
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
|
.decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP
|
||||||
.applyChance(gatewayChance));
|
.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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,5 +184,7 @@
|
||||||
"dimdoors.graphics.riftSize": "Rift Size",
|
"dimdoors.graphics.riftSize": "Rift Size",
|
||||||
"dimdoors.graphics.riftSize.tooltip": "Multiplier affecting how large rifts should be rendered, 1 being the default 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": "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\" "
|
||||||
}
|
}
|
Loading…
Reference in a new issue