Cleaned up and fixed dimteleport
Changes to be committed: modified: src/main/java/org/dimdev/dimdoors/command/DimTeleportCommand.java modified: src/main/java/org/dimdev/dimdoors/command/ModCommands.java deleted: src/main/java/org/dimdev/dimdoors/command/SaveSchemCommand.java deleted: src/main/java/org/dimdev/dimdoors/command/SchematicCommand.java modified: src/main/java/org/dimdev/dimdoors/command/SchematicV2Command.java modified: src/main/java/org/dimdev/dimdoors/command/arguments/SchematicNamespaceArgumentType.java
This commit is contained in:
parent
6a6d3ecb9b
commit
9ee0cf93fa
6 changed files with 19 additions and 103 deletions
|
@ -17,6 +17,10 @@ public class DimTeleportCommand {
|
|||
dispatcher.register(CommandManager.literal("dimteleport")
|
||||
.then(CommandManager
|
||||
.argument("dimension", DimensionArgumentType.dimension())
|
||||
.executes(ctx -> {
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
return teleport(player, DimensionArgumentType.getDimensionArgument(ctx, "dimension"), player.getPos());
|
||||
})
|
||||
.then(CommandManager
|
||||
.argument("coordinates", Vec3ArgumentType.vec3())
|
||||
.executes(ctx -> {
|
||||
|
|
|
@ -6,9 +6,7 @@ public final class ModCommands {
|
|||
public static void init() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
DimTeleportCommand.register(dispatcher);
|
||||
SchematicCommand.register(dispatcher);
|
||||
PocketCommand.register(dispatcher);
|
||||
SaveSchemCommand.register(dispatcher);
|
||||
SchematicV2Command.register(dispatcher);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package org.dimdev.dimdoors.command;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import org.dimdev.dimcore.schematic.Schematic;
|
||||
import org.dimdev.dimdoors.pockets.SchematicHandler;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
public class SaveSchemCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("saveschem")
|
||||
.then(CommandManager
|
||||
.argument("name", StringArgumentType.string())
|
||||
.executes(ctx -> {
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
if (!ModDimensions.isDimDoorsPocketDimension(player.world)) {
|
||||
throw new CommandException(new TranslatableText("commands.generic.dimdoors.not_in_pocket"));
|
||||
}
|
||||
|
||||
Pocket pocket = PocketRegistry.instance(player.getServerWorld().getRegistryKey()).getPocketAt(player.getBlockPos());
|
||||
if (pocket == null)
|
||||
throw new CommandException(new TranslatableText("commands.generic.dimdoors.not_in_pocket"));
|
||||
|
||||
Vector3i size = pocket.getSize().add(1, 1, 1).mul(16).sub(1, 1, 1);
|
||||
Schematic schematic = Schematic.createFromWorld(player.world, pocket.getOrigin(), pocket.getOrigin().add(new Vec3i(size.getX(), size.getY(), size.getZ())));
|
||||
|
||||
String name = StringArgumentType.getString(ctx, "name");
|
||||
|
||||
schematic.name = name;
|
||||
schematic.author = player.getName().getString();
|
||||
|
||||
SchematicHandler.INSTANCE.saveSchematicForEditing(schematic, name);
|
||||
|
||||
ctx.getSource().sendError(new TranslatableText("commands.saveschem.success"));
|
||||
return 1;
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package org.dimdev.dimdoors.command;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import org.dimdev.dimcore.schematic.Schematic;
|
||||
import org.dimdev.dimcore.schematic.SchematicConverter;
|
||||
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
public class SchematicCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("schematic")
|
||||
.then(CommandManager.literal("place")
|
||||
.then(CommandManager.argument("schematic_name", StringArgumentType.string())
|
||||
.executes(ctx -> {
|
||||
SchematicConverter.reloadConversions();
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
String id = StringArgumentType.getString(ctx, "schematic_name");
|
||||
|
||||
try (InputStream in = SchematicCommand.class.getResourceAsStream("/data/dimdoors/pockets/schematic/ruins/" + id + ".schem")) {
|
||||
Schematic.fromTag(NbtIo.readCompressed(in))
|
||||
.place(
|
||||
(ServerWorld) player.world,
|
||||
(int) player.getPos().x,
|
||||
(int) player.getPos().y,
|
||||
(int) player.getPos().z
|
||||
);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println(id + " placed");
|
||||
|
||||
return 1;
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ 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.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.command.arguments.SchematicNamespaceArgumentType;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
@ -40,7 +41,7 @@ public class SchematicV2Command {
|
|||
String id = StringArgumentType.getString(ctx, "schematic_name");
|
||||
String ns = SchematicNamespaceArgumentType.getValue(ctx, "namespace");
|
||||
|
||||
try (InputStream in = SchematicCommand.class.getResourceAsStream("/data/dimdoors/pockets/schematic/v2/" + ns + "/" + id + ".schem")) {
|
||||
try (InputStream in = DimensionalDoorsInitializer.class.getResourceAsStream("/data/dimdoors/pockets/schematic/v2/" + ns + "/" + id + ".schem")) {
|
||||
SchematicPlacer.place(
|
||||
Schematic.fromTag(NbtIo.readCompressed(in)),
|
||||
ctx.getSource().getWorld(),
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.dimdev.dimdoors.command.arguments;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
|
@ -9,24 +10,32 @@ 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 com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
public class SchematicNamespaceArgumentType implements ArgumentType<String> {
|
||||
private static final Collection<String> EXAMPLES = ImmutableList.of("ruins", "blank", "nether", "private", "public");
|
||||
private static final Collection<String> NAMESPACES = 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();
|
||||
if (!NAMESPACES.contains(value)) {
|
||||
throw new SimpleCommandExceptionType(new TranslatableText("argument.dimdoors.schematic.invalidNamespace", String.join(", ", NAMESPACES), value)).create();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getExamples() {
|
||||
return EXAMPLES;
|
||||
return NAMESPACES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
return CommandSource.suggestMatching(NAMESPACES, builder);
|
||||
}
|
||||
|
||||
public static String getValue(CommandContext<?> context, final String name) {
|
||||
|
|
Loading…
Reference in a new issue