CC: Tweaked

CC: Tweaked

57M Downloads

Make turtle.forward() and turtle.back() atomically teleport and consume fuel

umnikos opened this issue ยท 2 comments

commented

As an effort to circumvent issue #535 (which will probably never be fixed) I have been developing a reboot-resistant programming language for making programs that resume from where they left off when the chunk unloaded. The main inspiration for this is LAMA, and like LAMA the built-in movement functions check the fuel level to determine if a move operation was executed or not. The problem is, this currently doesn't actually work 100% of the time, as the following code is not atomic and if the chunk unloads between the two lines the turtle moves twice instead of once:

        // Move
        if (!turtle.teleportTo(oldWorld, newPosition)) return TurtleCommandResult.failure("Movement failed");

        // Consume fuel
        turtle.consumeFuel(1);
commented

The above code runs on the main thread, so the chunk will never be unloaded between those two function calls - that only happens on tick end (Or possibly tick start. But definitely never in the middle of a tick!).

What exactly do you mean by the turtle moves twice instead of once here?

commented

Good to know, I guess I'll have to track down the bug in my own code.