Attempts at readding /pocket and /saveschem.

This commit is contained in:
Waterpicker 2020-07-15 06:07:41 -05:00
parent ff5804fc6f
commit b7b3d2bbe6
7 changed files with 211 additions and 0 deletions

View file

@ -3,6 +3,8 @@ package org.dimdev.dimdoors;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.commands.CommandPocket;
import org.dimdev.dimdoors.commands.CommandSaveSchem;
import org.dimdev.dimdoors.commands.DimTeleportCommand;
import org.dimdev.dimdoors.commands.SchematicCommand;
import org.dimdev.dimdoors.entity.ModEntityTypes;
@ -43,5 +45,8 @@ public class DimensionalDoorsInitializer implements ModInitializer {
private void registerCommands() {
CommandRegistry.INSTANCE.register(false, DimTeleportCommand::register);
CommandRegistry.INSTANCE.register(false, SchematicCommand::register);
CommandRegistry.INSTANCE.register(false, CommandPocket::register);
CommandRegistry.INSTANCE.register(false, CommandSaveSchem::register);
}
}

View file

@ -0,0 +1,80 @@
package org.dimdev.dimdoors.commands;
import com.flowpowered.math.vector.Vector3i;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
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 org.dimdev.dimdoors.commands.arguments.GroupArugmentType;
import org.dimdev.dimdoors.commands.arguments.NameArugmentType;
import org.dimdev.dimdoors.pockets.PocketGenerator;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
import org.dimdev.dimdoors.rift.targets.EntityTarget;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.pocketlib.Pocket;
import org.dimdev.util.Location;
import org.dimdev.util.TeleportUtil;
public class CommandPocket {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("pocket")
.then(CommandManager.argument("group", GroupArugmentType.group())
.then(CommandManager.argument("name", NameArugmentType.name())
.then(CommandManager
.argument("setup", BoolArgumentType.bool())
.executes(ctx -> {
ServerPlayerEntity player = ctx.getSource().getPlayer();
if (!ModDimensions.isDimDoorsPocketDimension(player.world)) {
throw new CommandException(new TranslatableText("commands.generic.dimdoors.not_in_pocket"));
}
String group = ctx.getArgument("group", String.class);
String name = ctx.getArgument("name", String.class);
boolean setup = BoolArgumentType.getBool(ctx, "setup");
pocket(group, name, setup, player);
return 1;
})
)
.executes(ctx -> {
ServerPlayerEntity player = ctx.getSource().getPlayer();
if (!ModDimensions.isDimDoorsPocketDimension(player.world)) {
throw new CommandException(new TranslatableText("commands.generic.dimdoors.not_in_pocket"));
}
String group = ctx.getArgument("group", String.class);
String name = ctx.getArgument("name", String.class);
pocket(group, name, true, player);
return 1;
}))));
}
public static void pocket(String group, String name, boolean setup, ServerPlayerEntity player) {
try {
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(group, name);
Pocket pocket = PocketGenerator.generatePocketFromTemplate(player.getServerWorld(), template, null, setup);
// Teleport the player there
if (RiftRegistry.instance(player.world).getPocketEntrance(pocket) != null) {
EntityTarget entrance = (EntityTarget) player.world.getBlockEntity(RiftRegistry.instance(player.world).getPocketEntrance(pocket).pos);
entrance.receiveEntity(player, 0);
} else {
Vector3i size = pocket.getSize().add(1, 1, 1).mul(15).div(2);
TeleportUtil.teleport(player, new Location(player.getServerWorld(), pocket.getOrigin().add(size.getX(), size.getY(), size.getZ())));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,47 @@
package org.dimdev.dimdoors.commands;
import com.flowpowered.math.vector.Vector3i;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
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;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.pocketlib.Pocket;
import org.dimdev.pocketlib.PocketRegistry;
import org.dimdev.util.schem.Schematic;
public class CommandSaveSchem {
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()).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;
}))
);
}
}

View file

@ -0,0 +1,33 @@
package org.dimdev.dimdoors.commands.arguments;
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.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import java.util.concurrent.CompletableFuture;
public class GroupArugmentType implements ArgumentType<String> {
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
public static GroupArugmentType group() {
return new GroupArugmentType();
}
public static <S> PocketTemplate getPocketTemplate(CommandContext<S> context, String name) {
return context.getArgument(name, PocketTemplate.class);
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestMatching(SchematicHandler.INSTANCE.getTemplateGroups().stream(), builder);
}
}

View file

@ -0,0 +1,30 @@
package org.dimdev.dimdoors.commands.arguments;
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.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import org.dimdev.dimdoors.pockets.SchematicHandler;
import java.util.concurrent.CompletableFuture;
public class NameArugmentType implements ArgumentType<String> {
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
public static NameArugmentType name() {
return new NameArugmentType();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
String group = context.getArgument("group", String.class);
return CommandSource.suggestMatching(SchematicHandler.INSTANCE.getTemplateNames(group), builder);
}
}

View file

@ -1,11 +1,13 @@
package org.dimdev.pocketlib;
import com.flowpowered.math.vector.Vector3i;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import org.dimdev.annotatednbt.Saved;
import org.dimdev.util.EntityUtils;
@ -97,4 +99,9 @@ public final class Pocket {
public void setSize(int x, int y, int z) {
box = new BlockBox(box.minX, box.minY, box.minZ, box.minX + x, box.minY + y, box.minZ + z);
}
public Vector3i getSize() {
Vec3i dimensions = box.getDimensions();
return new Vector3i(dimensions.getX(), dimensions.getY(), dimensions.getZ());
}
}

View file

@ -3,6 +3,7 @@ package org.dimdev.util;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@ -27,4 +28,12 @@ public final class TeleportUtil {
entity.setOnFireFor(0); // Workaround for https://bugs.mojang.com/browse/MC-100097
}
}
public static void teleport(ServerPlayerEntity player, Location location) {
teleport(player, location.world, location.pos, 0);
}
public static void teleport(ServerPlayerEntity player, RotatedLocation location) {
teleport(player, location.world, location.pos, (int) location.yaw);
}
}