Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected void execute() {
Craft craft1 = getCraft();
if (craft1.getCruising()) {
CruiseDirection direction = craft1.getCruiseDirection();
craft1.setCruiseDirection(direction.getRotated(rotation));
craft1.setCruiseDirection(direction.getRotated2D(rotation));
}

// if you rotated a subcraft, update the parent with the new blocks
Expand Down
57 changes: 16 additions & 41 deletions api/src/main/java/net/countercraft/movecraft/CruiseDirection.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
package net.countercraft.movecraft;

import org.bukkit.block.BlockFace;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public enum CruiseDirection {
NORTH((byte) 0x3), //0x3
SOUTH((byte) 0x2), //0x2
EAST((byte) 0x4), //0x4
WEST((byte) 0x5), //0x5
UP((byte) 0x42), //0x42
DOWN((byte) 0x43), //0x43
NONE((byte) 0x0);

private final byte raw;

CruiseDirection(byte rawDirection) {
raw = rawDirection;
}

public byte getRaw() {
return raw;
}
public static CruiseDirection fromRaw(byte rawDirection) {
if(rawDirection == (byte) 0x3)
return NORTH;
else if(rawDirection == (byte) 0x2)
return SOUTH;
else if(rawDirection == (byte) 0x4)
return EAST;
else if(rawDirection == (byte) 0x5)
return WEST;
else if(rawDirection == (byte) 0x42)
return UP;
else if(rawDirection == (byte) 0x43)
return DOWN;
else
return NONE;
}

public static CruiseDirection fromBlockFace(BlockFace direction) {
NORTH,
SOUTH,
EAST,
WEST,
UP,
DOWN,
NONE;

@Contract(pure = true)
public static CruiseDirection fromBlockFace(@NotNull BlockFace direction) {
return switch (direction.getOppositeFace()) {
case NORTH -> NORTH;
case SOUTH -> SOUTH;
Expand All @@ -49,19 +26,17 @@ public static CruiseDirection fromBlockFace(BlockFace direction) {
};
}

public CruiseDirection getOpposite() {
public CruiseDirection getOpposite2D() {
return switch (this) {
case NORTH -> SOUTH;
case SOUTH -> NORTH;
case EAST -> WEST;
case WEST -> EAST;
case UP -> DOWN;
case DOWN -> UP;
case NONE -> NONE;
default -> this;
};
}

public CruiseDirection getRotated(MovecraftRotation rotation) {
public CruiseDirection getRotated2D(@NotNull MovecraftRotation rotation) {
return switch(rotation) {
case CLOCKWISE -> switch (this) {
case NORTH -> EAST;
Expand All @@ -70,7 +45,7 @@ public CruiseDirection getRotated(MovecraftRotation rotation) {
case WEST -> NORTH;
default -> this;
};
case ANTICLOCKWISE -> getRotated(MovecraftRotation.CLOCKWISE).getOpposite();
case ANTICLOCKWISE -> getRotated2D(MovecraftRotation.CLOCKWISE).getOpposite2D();
case NONE -> this;
};
}
Expand Down