Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Theelf111

Mining robot spontaneously turning off without error message

Question

I've made a simple mining program but after a while of mining the robot just turns off and the analyzer doesn't give an error message.
 

code:

local robot = component.proxy(component.list("robot")())
local inventory_controller = component.proxy(component.list("inventory_controller")())
local generator = component.proxy(component.list("generator")())

local inventorySize = robot.inventorySize()
local maxEnergy = computer.maxEnergy()

local trash = {}
trash["minecraft:cobblestone"] = true
trash["minecraft:dirt"] = true
trash["minecraft:gravel"] = true
trash["minecraft:stone"] = true

function rebind()
    robot = component.proxy(component.list("robot")())
    inventory_controller = component.proxy(component.list("inventory_controller")())
    generator = component.proxy(component.list("generator")())
end

function select(n)
    if not robot.select(n) then
        rebind()
        robot.select(n)
    end
end

function inventoryManagement()
    select(1)
    if robot.place(0) then
        for i = 2, inventorySize do
            item = inventory_controller.getStackInInternalSlot(i)
            if item then
                if trash[item["name"]] then
                    select(i)
                    robot.drop(1, 64)
                elseif not(string.find(item["name"], "minecraft:coal") or string.find(item["name"], "pickaxe")) then
                    select(i)
                    robot.drop(0, 64);
                end
            end
        end
    end
    select(1)
    swing(0)
end

function refuel()
    for i = 2, inventorySize do
        item = inventory_controller.getStackInInternalSlot(i)
        if item then
            if string.find(item["name"], "minecraft:coal") then
                select(i)
                generator.insert(16)
            end
        end
    end
end

function equip()
    for i = 2, inventorySize do
        item = inventory_controller.getStackInInternalSlot(i)
        if item then
            if string.find(item["name"], "pickaxe") then
                select(i)
                inventory_controller.equip()
                break;
            end
        end
        if i == inventorySize then
            computer.shutdown()
        end
    end
end

function swing(n)
    success, result = robot.swing(n)
    while not(success) do
        if result == "air" then
            break
        elseif result == "block" then
            equip()
        end
        success, result = robot.swing(n)
    end
end

function move(n)
    while not robot.move(n) do
        swing(n)
    end
end

b = 1
while true do
    for a = 1, 16 do
        if a == 1 then
            robot.turn(b % 2 == 1)
        end
        if a == 16 then
            robot.turn(b % 2 == 0)
        end
        swing(0)
        swing(1)
        swing(3)
        if a == 16 then
            inventoryManagement()
        end
        move(3)
    end
    b = b + 1

    if computer.energy() / maxEnergy < 0.75 and generator.count() < 16 then
        refuel()
    end
    computer.pullSignal(0)
end

the turtle has an ender chest from ender storage in it's first inventory slot and pickaxes / coal in it's inventory. When it shuts off it hasn't run out of pickaxes or energy, the problem seems to only happen when it's doing the inventoryManagement() function.

Minecraft version: 1.12.2

Tier 2 robot with 2 inventory upgrades, 1 inventory controller upgrade, 1 generator upgrade and a chunk loader upgarde.

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Ok, turns out I'm just incredibly stupid. Since i was using a tier 2 robot i had to use an upgrade container to get the chunk loader upgrade, because i put in the chunk loader upgrade after starting the robot it was set to be inactive by default.

edit: not sure why this would cause it to shut down though as running it on robots without chunk loader upgrades and moving 36 chunks away doesn't seem to break anything.

Edited by Theelf111
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.