diff --git a/examples/nav_dash.lua b/examples/nav_dash.lua index 8ebe729..cb1c46a 100644 --- a/examples/nav_dash.lua +++ b/examples/nav_dash.lua @@ -26,4 +26,67 @@ screen.setTextScale(0.5) TARDIM NAV| 11 -]] \ No newline at end of file +]] + +local function dim_char(dimension_str) + + if dimension_str == "minecraft:overworld" then + return "OWR" + elseif dimension_str == "minecraft:the_nether" then + return "NETH" + elseif dimension_str == "minecraft:the_end" then + return "END" + else + return "???" + end + +end + +screen.setCursorPos(math.floor((15 - 10) / 2), 1) +screen.write("TARDIM NAV") + +while true do + screen.setCursorPos(1, 3) + + local pos = tardim.getCurrentLocation() + screen.write("Current pos") + screen.setCursorPos(1, 4) + screen.write("X: " .. pos.pos.x) + screen.setCursorPos(1, 5) + screen.write("Y: " .. pos.pos.y) + screen.setCursorPos(1, 6) + screen.write("Z: " .. pos.pos.z) + screen.setCursorPos(1, 7) + screen.write("Dimension: " .. dim_char(pos.dimension)) + screen.setCursorPos(1, 8) + screen.write("Facing: " .. pos.facing) + + local dest = tardim.getTravelLocation() + screen.setCursorPos(1, 10) + screen.write("Destination") + screen.setCursorPos(1, 11) + screen.write("X: " .. dest.pos.x) + screen.setCursorPos(1, 12) + screen.write("Y: " .. dest.pos.y) + screen.setCursorPos(1, 13) + screen.write("Z: " .. dest.pos.z) + screen.setCursorPos(1, 14) + screen.write("Dimension: " .. dim_char(dest.dimension)) + screen.setCursorPos(1, 15) + screen.write("Facing: " .. dest.facing) + + local fuel = tardim.getFuel() + screen.setCursorPos(1, 17) + screen.write("Fuel") + screen.setCursorPos(1, 18) + screen.write("REM.: " .. fuel .. "/100") + screen.setCursorPos(1, 19) + local Required = tardim.calculateFuelForJourney() + screen.write("REQ.: " .. Required) + screen.setCursorPos(1, 20) + screen.write("ENOUGH: " .. (fuel >= Required and "YES" or "NO")) + + local inFlight = tardim.isInFlight() + screen.setCursorPos(1, 22) + screen.write("IN FLIGHT: " .. (inFlight and "YES" or "NO")) +end \ No newline at end of file diff --git a/src/main/java/su/a71/tardim_ic/tardim_ic/digital_interface/DigitalInterfacePeripheral.java b/src/main/java/su/a71/tardim_ic/tardim_ic/digital_interface/DigitalInterfacePeripheral.java index 847dcf4..36cb34b 100644 --- a/src/main/java/su/a71/tardim_ic/tardim_ic/digital_interface/DigitalInterfacePeripheral.java +++ b/src/main/java/su/a71/tardim_ic/tardim_ic/digital_interface/DigitalInterfacePeripheral.java @@ -294,20 +294,19 @@ public class DigitalInterfacePeripheral implements IPeripheral { @LuaFunction(mainThread = true) public final ObjectLuaTable getTravelLocation() throws LuaException { TardimData data = getTardimData(); - if (data.getTravelLocation() != null) { - Location loc = data.getTravelLocation(); - return new ObjectLuaTable(Map.of( + if (data.getTravelLocation() == null) { + data.setTravelLocation(data.getCurrentLocation()); + } + Location loc = data.getTravelLocation(); + return new ObjectLuaTable(Map.of( "dimension", loc.getLevel().location().toString(), "pos", new ObjectLuaTable(Map.of( "x", loc.getPos().getX(), "y", loc.getPos().getY(), "z", loc.getPos().getZ() )), - "facing", loc.getFacing().toString() - )); - } else { - return null; - } + "facing", loc.getFacing().toString() + )); } /**