Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = 20240122.1500
- -- https://www.youtube.com/watch?v=i-eBj0qLmRU
- --[[
- |S|T|C| S = smoker, T = turtle, C = chest/barrel (for crafted dried kelp blocks)
- |H|C| H = hopper, C= single or double chest (could also use barrel
- Script for turtle placed next to a smoker / furnace
- SuckDown output from smoker which is a chest below
- Craft dried kelp into dried kelp blocks
- if fuel required place into smoker on the right
- else rotate 180 and place in chest on the left
- ]]
- local storage = 0
- local backup = false
- local totalStored = 0
- local slots = {1,2,3,5,6,7,9,10,11}
- local function isItemOfType(direction, itemTable)
- -- check if item in front of turtle is a specific type
- local success, data = false, nil
- if direction == "up" then
- success, data= turtle.inspectUp()
- elseif direction == "down" then
- success, data= turtle.inspectDown()
- else
- success, data= turtle.inspect() -- check if anything in front
- end
- if success then -- a block is in front
- if type(itemTable) == "table" then -- Are we checking for multiple items eg {"chest", "barrel"} ?
- for _, item in ipairs(itemTable) do -- iterate items
- if data.name:find(item) ~= nil then -- match found
- return true
- end
- end
- elseif type(itemTable) == "string" then -- checking for single item
- if data.name:find(itemTable) ~= nil then -- match found
- return true
- end
- end
- end
- return false -- no match
- end
- local function getStorage()
- -- turtle has already been aligned with smoker/furnace. Now find chest/barrel
- -- use no. of turns to base future rotations to face storage
- print("Locating storage")
- backup = isItemOfType("up", {"chest", "barrel"}) -- check for fuel backup storage
- if backup then
- print("Found backup fuel supply above")
- end
- local turns = 0
- repeat
- if isItemOfType("forward", {"chest", "barrel"}) then -- look for chest or barrel
- storage = turns -- storage = current no of turns
- else
- turtle.turnRight()
- turns = turns + 1
- end
- until storage > 0 or turns == 4 -- limit to 4 in case no storage present
- if storage > 0 then -- has the turtle rotated?
- for i = 1, storage do -- rotate in opposite direction until facing smelter
- turtle.turnLeft()
- end
- end
- end
- local function orientate()
- print("Checking position")
- while not isItemOfType("forward", {"smoker", "furnace"}) do -- true if facing a smoker or furnace
- turtle.turnRight() -- not facing smoker so turn
- end
- end
- local function craftKelp()
- turtle.select(16) -- select a slot out of crafting area
- turtle.suckDown() -- remove items from chest below (dried kelp)
- local quantity = turtle.getItemCount(16) -- count items obtained
- print(quantity.. " dried kelp found")
- if quantity >= 9 then -- need min 9 to craft
- local amount = math.floor(quantity / 9) -- calculate how many to put in each of 9 slots
- for slot = 1, 9 do
- turtle.transferTo(slots[slot], amount) -- fill slots with same amount each
- end
- turtle.dropDown() -- drop remaining back into chest
- turtle.select(1) -- put crafted items in slot 1
- if turtle.craft() then
- return true
- end
- end
- return false
- end
- local function needsFuel()
- -- check if smelter is in 'lit' state.
- -- attempt to remove fuel from smelter if not lit
- local success, data = turtle.inspect()
- if success then -- smelter found
- if data.name:find("smoker") ~= nil or data.name:find("furnace") ~= nil then
- if not data.state.lit then -- if not lit, check for unused fuel
- turtle.select(2) -- use spare slot
- if turtle.suck() then -- fuel present
- turtle.drop(1) -- replace fuel
- turtle.select(1) -- reset selected slot to 1
- return false
- end
- turtle.select(1) -- not lit, no fuel = refuel
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- local function addFuelBackup()
- -- make sure backup fuel store has 3 blocks in it
- local retValue = false
- turtle.select(2) -- select empty slot
- turtle.suckUp() -- remove any stored fuel
- print("Checking fuel backup")
- if turtle.getItemCount(2) < 3 then -- check how much fuel was in storage
- turtle.select(1) -- add 1 more block from recently crafted
- turtle.dropUp(1)
- end
- turtle.select(2) -- replace blocks removed for counting
- turtle.dropUp()
- return turtle.getItemCount(1) -- return any remaining blocks
- end
- local function run()
- -- infinite loop to constantly attend to kelp farm smelter
- local slots = {1, 2, 3, 5, 6, 7, 9, 10, 11} -- translate turtle 16 slots into equivalent crafting slots
- while true do -- infinite loop
- if craftKelp() then -- try crafting kelp block
- -- at least 1 block crafted
- if needsFuel() then -- check if needs fuel
- print("Refuelling smelter")
- turtle.select(1)
- turtle.drop(1) -- drop crafted blocks into smoker fuel slot
- end
- local count = turtle.getItemCount(1)
- if count > 0 then -- spare dried kelp blocks available
- count = addFuelBackup()
- if count > 0 then -- still some kelp left
- for turns = 1, storage do
- turtle.turnRight() -- face storage
- end
- print("Storing "..count.." excess dried kelp blocks")
- totalStored = totalStored + count
- turtle.select(1)
- turtle.drop() -- drop into storage
- for turns = 1, storage do
- turtle.turnLeft() -- face smelter
- end
- end
- end
- else -- not crafted: could be insufficient kelp or out of fuel
- print("Waiting 10 seconds for further smelting")
- sleep(10)
- if craftKelp() then
- print("Refuelling smelter 2nd attempt")
- turtle.drop(1) -- drop crafted blocks into smoker fuel slot
- else
- if backup then
- print("Refuelling smelter from backup")
- turtle.select(1)
- turtle.suckUp(1)
- turtle.drop()
- end
- end
- end
- for time = 60, 1, -1 do -- wait 1 minute
- term.clear()
- term.setCursorPos(1, 1)
- print("Stored so far: "..totalStored.." blocks")
- print("Next kelp craft cycle: "..time.." secs")
- sleep(1)
- end
- end
- end
- local function main()
- orientate()
- getStorage()
- run()
- end
- main()
Add Comment
Please, Sign In to add comment