Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- local id=1 -- obviously set per turtle's position as explained above, moved into a .txt config file assigned below
- -- 7 turtles, id set's it's position
- -- 7 6 5
- -- 4 3 2
- -- 1
- -- 1 just places soul sand if it's block is clear
- -- 2,3, and 4 place soul sand if they're block is clear and then blip a redstone signal up
- -- 5,6, and 7 wait for redstone blip on bottom and then place wither skull's
- -- Note there's no need to verify inventory since they don't pick stuff up, just fill the inventory with sand for 1-4
- -- and skulls for 5-7 and it should construct withers.
- -- This really only works if explosions are disabled in your claim...
- -- I added the requirement for a redstone signal at the back to allow a way to turn it on and off.
- -- I also added a dig command to clear out the block in front of it, this helps 'reset' things in case the skulls are placed first
- -- (possibly due to running out of soulsand or something)
- -- I added a dig at the 'off' redstone state to make accessing the turtles easier since there's a block in the back to transmit the
- -- redstone signal and with the sandstone in the front accessing turtle 3 in particular was a bother
- local function getTurtleID()
- local file = fs.open("turtleID.txt", "r")
- if not file then
- error("Failed to open turtleID.txt. Please create the file with a number from 1 to 7.")
- end
- local id = tonumber(file.readLine())
- file.close()
- if not id or id < 1 or id > 7 then
- error("Invalid turtle ID in turtleID.txt. Must be a number from 1 to 7.")
- end
- return id
- end
- local turtleID = getTurtleID()
- function findNextItem()
- local currentSlot = turtle.getSelectedSlot()
- local totalSlots = 16 -- Turtle has 16 slots
- -- Check all slots, starting from current
- for i = 0, totalSlots - 1 do
- local slotToCheck = (currentSlot + i - 1) % totalSlots + 1
- turtle.select(slotToCheck)
- if turtle.getItemCount() > 0 then
- return true -- Found a non-empty slot
- end
- end
- -- No non-empty slots found
- turtle.select(currentSlot) -- Return to original slot
- return false
- end
- -- debug function
- local function pauseMe()
- print("Press any key...")
- os.pullEvent("key")
- end
- local function placeForward()
- local has_block, data = turtle.inspect()
- if not has_block then
- turtle.place()
- return 1
- end
- return 0
- end
- while findNextItem() do -- might as well exit if we run out of stuff
- while redstone.getInput("back")==true do
- if turtleID>4 then
- local loop=0
- print("Waiting for redstone signal from below.")
- while redstone.getInput("bottom")==false do
- sleep(.5) -- wait for go signal
- -- periodically the skulls get placed too soon, so we'll let #6 do an intermittent dig to reset things
- if turtleID==6 then
- loop=loop+1 -- 20 loops should be ~10 seconds in .5 second steps
- if loop==20 then
- turtle.dig()
- turtle.place()
- loop=0
- end
- end
- end
- print("Redstone signal received.")
- redstone.setOutput("bottom",true)
- while redstone.getInput("bottom")==true do
- sleep(.5) -- wait for signal to stop=ack below
- end
- print("Redstone signal acknowledged.")
- redstone.setOutput("bottom",false)
- while placeForward()==0 do
- sleep(.5) -- try until successful
- -- the loop==20 above should cover this, if this fails it's probably empty the outer loop should catch that turtle.dig() -- if it's failing try to clear the blockage
- end
- print("Block placed forward")
- else
- if placeForward()==1 then
- print("placed inventory forward")
- if turtleID>1 and turtleID<5 then -- need to exclude 1 since it doesn't get signaled back by turtleID 3 (not necessary)
- redstone.setOutput("top",true)
- while redstone.getInput("top")==false do
- sleep(.5)
- end
- redstone.setOutput("top",false) -- wait for turtle above to acknowledge signal
- end
- else
- print("Space blocked")
- end
- sleep(5)
- -- still not need with loop=20 above turtle.dig() -- not 100% sure this may require a mining turtle...so splurge and invest in a diamond pick
- end
- print("Turtle ",turtleID," Waiting for redstone startup at 5 second intervals")
- sleep(5)
- -- redstone signal present loop
- end
- print("available item slot selected (or exit)")
- -- inventory not empty loop
- end
- print("exit it is.")
- pauseMe()
Add Comment
Please, Sign In to add comment