| 1 | package net.minecraft.commands.arguments.coordinates;
|
| 2 |
|
| 3 | import com.mojang.brigadier.StringReader;
|
| 4 | import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
| 5 | import net.minecraft.commands.CommandSourceStack;
|
| 6 | import net.minecraft.world.phys.Vec2;
|
| 7 | import net.minecraft.world.phys.Vec3;
|
| 8 |
|
| 9 | public record WorldCoordinates(WorldCoordinate x, WorldCoordinate y, WorldCoordinate z) implements Coordinates {
|
| 10 | public static final WorldCoordinates ZERO_ROTATION = absolute(new Vec2(0.0F, 0.0F));
|
| 11 |
|
| 12 | @Override
|
| 13 | public Vec3 getPosition(final CommandSourceStack sender) {
|
| 14 | Vec3 pos = sender.getPosition();
|
| 15 | return new Vec3(this.x.get(pos.x), this.y.get(pos.y), this.z.get(pos.z));
|
| 16 | }
|
| 17 |
|
| 18 | @Override
|
| 19 | public Vec2 getRotation(final CommandSourceStack sender) {
|
| 20 | Vec2 rot = sender.getRotation();
|
| 21 | return new Vec2((float)this.x.get(rot.x), (float)this.y.get(rot.y));
|
| 22 | }
|
| 23 |
|
| 24 | @Override
|
| 25 | public boolean isXRelative() {
|
| 26 | return this.x.isRelative();
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public boolean isYRelative() {
|
| 31 | return this.y.isRelative();
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public boolean isZRelative() {
|
| 36 | return this.z.isRelative();
|
| 37 | }
|
| 38 |
|
| 39 | public static WorldCoordinates parseInt(final StringReader reader) throws CommandSyntaxException {
|
| 40 | int start = reader.getCursor();
|
| 41 | WorldCoordinate x = WorldCoordinate.parseInt(reader);
|
| 42 | if (reader.canRead() && reader.peek() == ' ') {
|
| 43 | reader.skip();
|
| 44 | WorldCoordinate y = WorldCoordinate.parseInt(reader);
|
| 45 | if (reader.canRead() && reader.peek() == ' ') {
|
| 46 | reader.skip();
|
| 47 | WorldCoordinate z = WorldCoordinate.parseInt(reader);
|
| 48 | return new WorldCoordinates(x, y, z);
|
| 49 | } else {
|
| 50 | reader.setCursor(start);
|
| 51 | throw Vec3Argument.ERROR_NOT_COMPLETE.createWithContext(reader);
|
| 52 | }
|
| 53 | } else {
|
| 54 | reader.setCursor(start);
|
| 55 | throw Vec3Argument.ERROR_NOT_COMPLETE.createWithContext(reader);
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | public static WorldCoordinates parseDouble(final StringReader reader, final boolean centerCorrect) throws CommandSyntaxException {
|
| 60 | int start = reader.getCursor();
|
| 61 | WorldCoordinate x = WorldCoordinate.parseDouble(reader, centerCorrect);
|
| 62 | if (reader.canRead() && reader.peek() == ' ') {
|
| 63 | reader.skip();
|
| 64 | WorldCoordinate y = WorldCoordinate.parseDouble(reader, false);
|
| 65 | if (reader.canRead() && reader.peek() == ' ') {
|
| 66 | reader.skip();
|
| 67 | WorldCoordinate z = WorldCoordinate.parseDouble(reader, centerCorrect);
|
| 68 | return new WorldCoordinates(x, y, z);
|
| 69 | } else {
|
| 70 | reader.setCursor(start);
|
| 71 | throw Vec3Argument.ERROR_NOT_COMPLETE.createWithContext(reader);
|
| 72 | }
|
| 73 | } else {
|
| 74 | reader.setCursor(start);
|
| 75 | throw Vec3Argument.ERROR_NOT_COMPLETE.createWithContext(reader);
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | public static WorldCoordinates absolute(final double x, final double y, final double z) {
|
| 80 | return new WorldCoordinates(new WorldCoordinate(false, x), new WorldCoordinate(false, y), new WorldCoordinate(false, z));
|
| 81 | }
|
| 82 |
|
| 83 | public static WorldCoordinates absolute(final Vec2 rotation) {
|
| 84 | return new WorldCoordinates(new WorldCoordinate(false, rotation.x), new WorldCoordinate(false, rotation.y), new WorldCoordinate(true, 0.0));
|
| 85 | }
|
| 86 | }
|
| 87 |
|