Lua scripts for the computercraft mod for minecraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

64 lines
1.6 KiB

-- Active slaves which will activate an engine next to it (to get content of a chest)
-- Slaves should be aligned with the master
-- It leaks at the moment (because engines have a cool down and pipes are slow)
-- Possible other (simpler) slave: use the turtle as a chest and put it next to a diamond pipe
-- (this requires more diamond, but less redstone engines/chests and probably wont leak)
local args = { ... }
local threshold = 5
local function count_total()
local c = 0
for i = 1, 9 do c = c + turtle.getItemCount(i) end
return c
end
local function count_space()
local c = 0
for i = 1, 9 do c = c + turtle.getItemSpace(i) end
return c
end
rednet.open("right")
while true do
-- we are using wireless to get the distance
-- so the master should be aligned with the slaves
local id, mess, dist = rednet.receive(1)
if mess == args[1] then
if count_total() < threshold then
rednet.send(id, "empty")
else
rednet.send(id, "ack")
-- Wait for the pipes to be empty (and not leak)
-- TODO: find out magic value to wait...
rs.setOutput("left", false)
sleep(2)
-- GO!!!
turtle.up()
for i = 1, dist do turtle.forward() end
print("I will leave again in 5 seconds...")
sleep(5)
print("Bye!")
for i = 1, dist do turtle.back() end
turtle.down()
rednet.send(id, "return")
print("Back home :)")
end
end
-- This will power the engine next to the turtle
-- We don't want to fill if we're full
-- NOTE: we can't use the side of the modem...
if count_space() > threshold then
rs.setOutput("left", true)
else
rs.setOutput("left", false)
end
end