Add .tp
This commit is contained in:
@@ -45,6 +45,7 @@ public class MeteorRejectsAddon extends MeteorAddon {
|
||||
commands.add(new BookDupeCommand());
|
||||
commands.add(new GiveCommand());
|
||||
commands.add(new SaveSkinCommand());
|
||||
commands.add(new TeleportCommand());
|
||||
commands.add(new TerrainExport());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package cloudburst.rejects.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.client.MinecraftClient;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.argument.*;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ClientPosArgumentType implements ArgumentType<Vec3d> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0 0 0", "~ ~ ~", "~0.5 ~1 ~-5");
|
||||
private static final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
|
||||
public ClientPosArgumentType() {
|
||||
}
|
||||
|
||||
public static ClientPosArgumentType blockPos() {
|
||||
return new ClientPosArgumentType();
|
||||
}
|
||||
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
if (!(context.getSource() instanceof CommandSource)) {
|
||||
return Suggestions.empty();
|
||||
} else {
|
||||
String string = builder.getRemaining();
|
||||
Object collection2 = ((CommandSource)context.getSource()).getBlockPositionSuggestions();
|
||||
|
||||
return CommandSource.suggestPositions(string, (Collection)collection2, builder, CommandManager.getCommandValidator(this::parse));
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec3d getPos(final CommandContext<?> context, final String name) {
|
||||
return context.getArgument(name, Vec3d.class);
|
||||
}
|
||||
|
||||
|
||||
public Vec3d parse(StringReader reader) throws CommandSyntaxException {
|
||||
int i = reader.getCursor();
|
||||
double x,y,z;
|
||||
CoordinateArgument coordinateArgument = CoordinateArgument.parse(reader);
|
||||
CoordinateArgument coordinateArgument2;
|
||||
CoordinateArgument coordinateArgument3;
|
||||
if (reader.canRead() && reader.peek() == ' ') {
|
||||
reader.skip();
|
||||
coordinateArgument2 = CoordinateArgument.parse(reader);
|
||||
if (reader.canRead() && reader.peek() == ' ') {
|
||||
reader.skip();
|
||||
coordinateArgument3 = CoordinateArgument.parse(reader);
|
||||
} else {
|
||||
reader.setCursor(i);
|
||||
throw Vec3ArgumentType.INCOMPLETE_EXCEPTION.createWithContext(reader);
|
||||
}
|
||||
} else {
|
||||
reader.setCursor(i);
|
||||
throw Vec3ArgumentType.INCOMPLETE_EXCEPTION.createWithContext(reader);
|
||||
}
|
||||
|
||||
x = coordinateArgument.toAbsoluteCoordinate(mc.player.getX());
|
||||
y = coordinateArgument2.toAbsoluteCoordinate(mc.player.getY());
|
||||
z = coordinateArgument3.toAbsoluteCoordinate(mc.player.getZ());
|
||||
|
||||
return new Vec3d(x,y,z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cloudburst.rejects.commands;
|
||||
|
||||
import cloudburst.rejects.arguments.ClientPosArgumentType;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import minegame159.meteorclient.systems.commands.Command;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
|
||||
public class TeleportCommand extends Command {
|
||||
|
||||
|
||||
public TeleportCommand() {
|
||||
super("teleport","Sends a packet to the server with new position. Allows to teleport small distances.", "tp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<CommandSource> builder) {
|
||||
builder.then(argument("pos", ClientPosArgumentType.blockPos()).executes(ctx -> {
|
||||
Vec3d pos = ClientPosArgumentType.getPos(ctx, "pos");
|
||||
mc.player.updatePosition(pos.getX(), pos.getY(), pos.getZ());
|
||||
return SINGLE_SUCCESS;
|
||||
}));
|
||||
|
||||
builder.then(argument("pos", ClientPosArgumentType.blockPos()).then(argument("yaw", FloatArgumentType.floatArg()).then(argument("pitch",FloatArgumentType.floatArg()).executes(ctx -> {
|
||||
Vec3d pos = ClientPosArgumentType.getPos(ctx, "pos");
|
||||
float yaw = FloatArgumentType.getFloat(ctx, "yaw");
|
||||
float pitch = FloatArgumentType.getFloat(ctx, "pitch");
|
||||
mc.player.updatePositionAndAngles(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
|
||||
return SINGLE_SUCCESS;
|
||||
}))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user