Skip to content

PULL REQUEST turtle.readRotationSensor() #2302

@lostallmymoney

Description

@lostallmymoney

Hey, there, since you confirmed the bug as a duplicate I've gotten here this fix.
Since I HATE PULL REQUESTS IT'S SO WEIRD, and there's like 12 branches...
here is all the code needed inside of projects/common/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java

/**
     * Read the rotation sensor value.
     * <p>
     * Returns a 4-bit register (0-15) that increments each time the turtle turns.
     *
     * @return The current rotation sensor value (0-15).
     * @cc.treturn number The rotation sensor value.
     * @cc.since 1.116.2
     */
    @LuaFunction
    public final int readRotationSensor() {
        return ((TurtleBrain) turtle).getRotationShaft();
    }

Here is all that is needed inside of projects/common/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java

    private static final String NBT_ROTATION_SHAFT = "RotationShaft";
    private int rotationShaft = 0;

    //Read state
        rotationShaft = nbt.contains(NBT_ROTATION_SHAFT) ? nbt.getInt(NBT_ROTATION_SHAFT) : 0;
//Write state
        nbt.putInt(NBT_ROTATION_SHAFT, rotationShaft);

@Override
    public void setDirection(Direction dir) {
        owner.setDirection(dir);
        rotationShaft = (rotationShaft + 1) & 0xF;
    }

public int getRotationShaft() {
        return rotationShaft;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn extension of a feature or a new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions