Always assume your code is going to compile.

This commit is contained in:
Andrey Nikitin 2023-02-02 01:16:05 +03:00
parent ac2e1172fe
commit fa3a2c9414
2 changed files with 71 additions and 9 deletions

View file

@ -26,4 +26,67 @@ screen.setTextScale(0.5)
TARDIM NAV| 11 TARDIM NAV| 11
]] ]]
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

View file

@ -294,20 +294,19 @@ public class DigitalInterfacePeripheral implements IPeripheral {
@LuaFunction(mainThread = true) @LuaFunction(mainThread = true)
public final ObjectLuaTable getTravelLocation() throws LuaException { public final ObjectLuaTable getTravelLocation() throws LuaException {
TardimData data = getTardimData(); TardimData data = getTardimData();
if (data.getTravelLocation() != null) { if (data.getTravelLocation() == null) {
Location loc = data.getTravelLocation(); data.setTravelLocation(data.getCurrentLocation());
return new ObjectLuaTable(Map.of( }
Location loc = data.getTravelLocation();
return new ObjectLuaTable(Map.of(
"dimension", loc.getLevel().location().toString(), "dimension", loc.getLevel().location().toString(),
"pos", new ObjectLuaTable(Map.of( "pos", new ObjectLuaTable(Map.of(
"x", loc.getPos().getX(), "x", loc.getPos().getX(),
"y", loc.getPos().getY(), "y", loc.getPos().getY(),
"z", loc.getPos().getZ() "z", loc.getPos().getZ()
)), )),
"facing", loc.getFacing().toString() "facing", loc.getFacing().toString()
)); ));
} else {
return null;
}
} }
/** /**