Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --API simplifying the use of embedded chests
- --init slots table
- slots = {["coal"] = 16, ["signal"] = 16, ["sort"] = 16}
- print("All slots initialized to 16.")
- for key, value in pairs(slots) do
- print(key.." : "..value)
- end
- --CHEST UTILS INTERNAL FUNCTION
- local function refuel(side)
- print("[FUEL] refuel with at least a stack of charcoal.")
- turtle.select(1)
- --Wait for a full stack and refuel
- while ( turtle.getItemCount(1) < 64 ) do
- if side == "top" then
- turtle.suckUp()
- elseif side == "down" then
- turtle.suckDown()
- elseif side == "front" then
- turtle.suck()
- else
- return false
- end
- end
- turtle.refuel()
- turtle.select(2)
- turtle.refuel()
- turtle.select(1)
- return true
- end
- local function wait4Signal(side)
- print("[SIGNAL] wait4Signal (Redstone Torch).")
- local chest = peripheral.wrap(side)
- local nbSlot = chest.getInventorySize()
- while true do
- for i = 1,nbSlot do
- local tableInfo = chest.getStackInSlot(i)
- if tableInfo ~= nil then
- for key, value in pairs(tableInfo) do
- if (key ~= "ench") then
- print(key.." - "..value)
- end
- if ( key == "name" and value == "Redstone Torch") then -- Find Mining signal
- print("Redstone Torch found! Sending operation to workers!")
- return true
- end
- end
- end
- end
- sleep(5)
- end
- end
- local function useChest(chestType, side)
- --print("DEBUG useChest - chestType : "..chestType..", side : "..side)
- if chestType == "coal" then
- print("[INV] Providing Coal chest.")
- slot = slots["coal"]
- elseif chestType == "signal" then
- print("[INV] Providing Signal chest.")
- slot = slots["signal"]
- elseif chestType == "sort" then
- print("[INV] Providing Sorting chest.")
- slot = slots["sort"]
- else
- return false
- end
- --PLACE CHEST
- turtle.select(slot)
- if side == "top" then
- while ( turtle.detectUp() ) do
- turtle.digUp()
- end
- print("[INV] placing chest on top.")
- while ( not turtle.placeUp() ) do
- sleep(1)
- end
- elseif side == "down" then
- while ( turtle.detectDown() ) do
- turtle.digDown()
- end
- print("[INV] placing chest under.")
- while ( not turtle.placeDown() ) do
- sleep(1)
- end
- elseif side == "front" then
- while ( turtle.detect() ) do
- turtle.dig()
- end
- print("[INV] placing chest in front.")
- while ( not turtle.place() ) do
- sleep(1)
- end
- else
- end
- --USE CHEST
- if chestType == "signal" then
- wait4Signal(side)
- elseif chestType == "coal" then
- refuel(side)
- elseif chestType == "sort" then
- print("TODO : redo sort process")
- else
- return false
- end
- --STORE CHEST
- print("[INV] retrieving chest.")
- turtle.select(slot)
- while ( turtle.getItemCount(slot) == 0 ) do
- if side == "top" then
- turtle.digUp()
- elseif side == "down" then
- turtle.digDown()
- elseif side == "front" then
- turtle.dig()
- else
- return false
- end
- sleep(1)
- end
- turtle.select(1)
- return true
- end
- --CHEST UTILS USER FUNCTION
- function useCoalChest(side)
- --print("DEBUG useCoalChest - side : "..side)
- return useChest("coal", side)
- end
- function useSignalChest(side)
- --print("DEBUG useSignalChest - side : "..side)
- return useChest("signal", side)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement