Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require "component"
- local compRobot = assert(component.robot, "Unable to find robot component. Is this a robot?")
- local robot = require "robot"
- local sides = require "sides"
- local robotBase = require "robotBase"
- local crafting = require "crafting"
- local inventory = assert(component.inventory_controller, "Requires inventory controller upgrade to run!")
- local ID = { stone = 1 }
- local pickaxeByMaterial = { [crafting.ID.cobblestone] = 274, [crafting.ID.diamond] = 278, }
- local slotAssigns = { [4] = robotBase.ID.coal, [8] = ID.stone, [12] = crafting.ID.cobblestone, [13] = pickaxeByMaterial[crafting.ID.diamond], [16] = crafting.ID.plank, }
- function isStone(direction)
- robot.select(8)
- return compRobot.compareTo(direction)
- end
- function getStackInfo(slot)
- return inventory.getStackInSlot(sides.back, slot)
- end
- function getFreeSlot()
- for slot=1,robotBase.getInventorySize() do
- if ((not slotAssigns[slot]) and (robot.count(slot) == 0)) then
- return slot
- end
- end
- return nil
- end
- function assignSlots()
- local stack
- local assignTo = {}
- for slot, id in pairs(slotAssigns) do
- assignTo[id] = slot
- stack = getStackInfo(slot)
- if (stack and (stack.id ~= id)) then
- local freeSlot = getFreeSlot()
- if (not freeSlot) then
- return false
- else
- robot.select(slot)
- robot.transferTo(freeSlot)
- end
- end
- end
- local assignSlot
- for slot=1,robotBase.getInventorySize() do
- stack = getStackInfo(slot)
- if (stack) then
- assignSlot = assignTo[stack.id]
- if (assignSlot) then
- robot.select(slot)
- robot.transferTo(assignSlot, robot.space(assignSlot))
- end
- end
- end
- for slot, id in pairs(slotAssigns) do
- if (robot.count(slot) <= 0) then
- return false
- end
- end
- return true
- end
- function equipPickaxe(material)
- if (robot.durability()) then
- local freeSlot = getFreeSlot()
- if (not freeSlot) then
- return false, "Not enough free inventory space"
- end
- robot.select(freeSlot)
- inventory.equip()
- end
- local slotWithPickaxe = crafting.findItems(pickaxeByMaterial[material], 1)
- if (not slotWithPickaxe) then
- if (not crafting.craftPickaxe(material)) then
- return false, "Unable to craft a pickaxe"
- end
- slotWithPickaxe = crafting.findItems(pickaxeByMaterial[material], 1)
- if (not slotWithPickaxe) then
- return false, "Crafted pickaxe vanished"
- end
- end
- robot.select(slotWithPickaxe)
- return inventory.equip()
- end
- function initialize()
- print("Checking fuel...")
- if (not robotBase.checkFuel()) then
- print("Unable to find fuel, please add some coal.")
- return
- end
- print("Fuel found.")
- print("Sorting inventory...")
- if (not assignSlots()) then
- print("Either not enough free inventory space left, or missing one of coal, cobblestone, planks , (clean) stone or diamond pickaxe.")
- return
- end
- print("Inventory sorted.")
- print("Grabbing me a pickaxe...")
- local success, errorMessage = equipPickaxe(crafting.ID.cobblestone)
- if (not success) then
- print(errorMessage)
- return false
- end
- print("Pickaxe equipped, let's go!")
- end
- initialize()
Advertisement
Add Comment
Please, Sign In to add comment