Restock torches and pickaxe

master
D4VID 10 months ago
parent 2e03f26861
commit 4885b48fe8

@ -44,6 +44,28 @@ local function store(whitelist)
end
end
---Take an item from the facing inventory and put it in the specified internal slot
---@param item string
---@param internal_slot number
---@return boolean success
local function take(item, internal_slot)
local slots = inventory.getInventorySize(sides.forward)
for slot = 1, slots do
local stack = inventory.getStackInSlot(sides.forward, slot)
if stack then
if stack.name == item then
robot.select(internal_slot)
inventory.suckFromSlot(sides.forward, slot, robot.space()) -- take as many items to fill the slot
return true
end
end
end
return false
end
return {
store = store,
take = take,
}

@ -2,6 +2,9 @@ local robot = require("robot")
local nav = require("navigator")
local chest = require("chest")
local miner = require("miner")
local component = require("component")
local inventory = component.inventory_controller;
ORES = {
'minecraft:iron_ore',
@ -14,20 +17,37 @@ ORES = {
print("Mining...")
-- mine, starts facing east, goes east and scans south
miner.mine(32)
-- ends facing "west"
robot.turnRight()
-- store items
print("Storing ores")
chest.store(ORES)
robot.turnLeft()
nav.forward(2)
robot.turnRight()
print("Storing the rest")
chest.store()
robot.turnRight()
nav.forward(2)
-- ends facing east
while true do
-- mine, starts facing east, goes east and scans south
miner.mine(32)
-- ends facing "west"
robot.turnRight()
-- store items
print("Storing ores")
chest.store(ORES)
robot.turnLeft()
nav.forward(2)
robot.turnRight()
print("Storing the rest")
chest.store()
robot.turnRight()
nav.forward(2)
-- restock
robot.turnLeft()
chest.take('minecraft:torch', 1)
local can_continue = chest.take('minecraft:iron_pickaxe', 2)
robot.turnRight()
if not can_continue then
break
end
robot.select(2)
inventory.equip()
-- ends facing east
end

@ -0,0 +1,3 @@
local count = ...
print(count)
Loading…
Cancel
Save