1

ComputerCraft mod から Turtle 用のマイニング プログラムを作成したいと考えています。私はこれを作成しました:

function initVariables()
    stone = 0
    cobblestone = 0
    coal = 0
    iron = 0
    gold = 0
    redstone = 0
    diamond = 0
    lapis = 0
    dirt = 0
    gravel = 0
    sand = 0
    emerald = 0
    mossy = 0
end

function count()
    local success, data = turtle.inspect()

    if success then
        if data.name == "minecraft:stone" then stone = stone + 1 end
        if data.name == "minecraft:cobblestone" then cobblestone = cobblestone + 1 end
        if data.name == "minecraft:coal_ore" then coal = coal + 1 end
        if data.name == "minecraft:iron_ore" then iron = iron + 1 end
        if data.name == "minecraft:gold_ore" then gold = gold + 1 end
        if data.name == "minecraft:redstone_ore" then redstone = redstone + 1 end
        if data.name == "minecraft:diamond_ore" then diamond = diamond + 1 end
        if data.name == "minecraft:lapis_ore" then lapis = lapis + 1 end
        if data.name == "minecraft:dirt" then dirt = dirt + 1 end
        if data.name == "minecraft:gravel" then gravel = gravel + 1 end
        if data.name == "minecraft:sand" then sand = sand + 1 end
        if data.name == "minecraft:emerald_ore" then emerald = emerald + 1 end
        if data.name == "minecraft:mossy_cobblestone" then mossy = mossy + 1 end
    end
end

function display()
    print("I have mined:")
        if stone > 0 then
            print(stone .. " blocks of stone")
        end

        if cobblestone > 0 then
            print(cobblestone .. " blocks of cobblestone")
        end

        if coal > 0 then
            print(coal .. " coal ores")
        end

        if iron > 0 then
            print(iron .. " iron ores")
        end

        if gold > 0 then
            print(gold .. " gold ores")
        end

        if redstone > 0 then
            print(redstone .. " redstone ores")
        end

        if diamond > 0 then
            print(diamond .. " diamond ores")
        end

        if lapis > 0 then
            print(lapis .. " lapis ores")
        end

        if dirt > 0 then
            print(dirt .. " blocks of dirt")
        end

        if gravel > 0 then
            print(gravel .. " blocks of gravel")
        end

        if sand > 0 then
            print(sand .. " blocks of sand")
        end

        if emerald > 0 then
            print(emerald .. " emerald ores")
        end

        if mossy > 0 then
            print(mossy .. " blocks of mossy cobblestone")
        end
end

function refuel()
    turtle.select(1)
    turtle.refuel(1)
end

function checkIfBack()
    fuelCount = turtle.getItemCount(1)
    if fuelCount < 5 then
        return true
    else
        return false
    end
end

function back()
    if checkIfBack() == true then
        turtle.turnLeft()
        turtle.turnLeft()

        local stopblock, data = turtle.inspect()
        if data.name ~= "minecraft:redstone_block" then
            if turtle.forward() == false then
                turtle.attack()
            else
                turtle.forward()
            end
            return false
        else
            return true
        end
    end
end

function move()
    if back() == false then
        fuel = turtle.getTurtleLevel()
        if fuel < 10 then refuel() end
        if turtle.inspect() == false then
            turtle.forward()
        else
            count()
            turtle.dig()
            turtle.attack()
        end
    else
        print("END OF PROGRAM")
    end
end

initVariables()
while true do move() end

しかし、カメは 3 ブロック前に進み、向きを変え、3 ブロック前に進み、向きを変え、3 ブロック前に進みます。

私は何を間違っていますか?

4

1 に答える 1