Never trust a spinning Dalek, they will give you wrong methods!
This commit is contained in:
parent
16ccb99f60
commit
3912bfb160
1 changed files with 40 additions and 26 deletions
|
@ -9,6 +9,7 @@ import dan200.computercraft.api.lua.ObjectLuaTable;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -391,17 +392,23 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final String getDoorRotation() throws LuaException {
|
public final String getDoorRotation() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
double rotation = data.getDoorRotation();
|
Direction rotation = data.getTravelLocation().getFacing();
|
||||||
if (rotation == 0) {
|
switch (rotation) {
|
||||||
return "north";
|
case NORTH -> {
|
||||||
} else if (rotation == 90) {
|
return "north";
|
||||||
return "east";
|
}
|
||||||
} else if (rotation == 180) {
|
case EAST -> {
|
||||||
return "south";
|
return "east";
|
||||||
} else if (rotation == 270) {
|
}
|
||||||
return "west";
|
case SOUTH -> {
|
||||||
} else {
|
return "south";
|
||||||
throw new LuaException("Invalid door rotation");
|
}
|
||||||
|
case WEST -> {
|
||||||
|
return "west";
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
throw new LuaException("Invalid door rotation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,12 +420,14 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
||||||
public final void setDoorRotation(String rotation) throws LuaException {
|
public final void setDoorRotation(String rotation) throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case "north" -> data.setDoorRotation(0);
|
case "north" -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||||
case "east" -> data.setDoorRotation(90);
|
case "east" -> data.getTravelLocation().setFacing(Direction.EAST);
|
||||||
case "south" -> data.setDoorRotation(180);
|
case "south" -> data.getTravelLocation().setFacing(Direction.SOUTH);
|
||||||
case "west" -> data.setDoorRotation(270);
|
case "west" -> data.getTravelLocation().setFacing(Direction.WEST);
|
||||||
default -> throw new LuaException("Invalid door rotation");
|
default -> throw new LuaException("Invalid door rotation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -427,18 +436,23 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public final void toggleDoorRotation() throws LuaException {
|
public final void toggleDoorRotation() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
double rotation = data.getDoorRotation();
|
if (data.getTravelLocation() == null) {
|
||||||
if (rotation == 0) {
|
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||||
data.setDoorRotation(90);
|
|
||||||
} else if (rotation == 90) {
|
|
||||||
data.setDoorRotation(180);
|
|
||||||
} else if (rotation == 180) {
|
|
||||||
data.setDoorRotation(270);
|
|
||||||
} else if (rotation == 270) {
|
|
||||||
data.setDoorRotation(0);
|
|
||||||
} else {
|
|
||||||
throw new LuaException("Invalid door rotation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.getTravelLocation().getFacing() == null) {
|
||||||
|
data.getTravelLocation().setFacing(Direction.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (data.getTravelLocation().getFacing()) {
|
||||||
|
case NORTH -> data.getTravelLocation().setFacing(Direction.EAST);
|
||||||
|
case EAST -> data.getTravelLocation().setFacing(Direction.SOUTH);
|
||||||
|
case SOUTH -> data.getTravelLocation().setFacing(Direction.WEST);
|
||||||
|
case WEST -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||||
|
default -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue