SHOW:
|
|
- or go back to the newest paste.
1 | - | -- variation on box miner but instead of bobbing up and down like a sewing needle this is the more classic run straight through |
1 | + | -- local id=1 -- obviously set per turtle's position as explained above, moved into a .txt config file assigned below |
2 | - | -- also as I'm doing this for clay I'll set it to only dig up or down if there is clay present. |
2 | + | |
3 | -- 7 turtles, id set's it's position | |
4 | - | depth=3 -- small makes testing retrieval easier if I get flip logic wrong |
4 | + | -- 7 6 5 |
5 | - | width=8 |
5 | + | -- 4 3 2 |
6 | - | length=8 |
6 | + | -- 1 |
7 | - | flip=0 |
7 | + | -- 1 just places soul sand if it's block is clear |
8 | -- 2,3, and 4 place soul sand if they're block is clear and then blip a redstone signal up | |
9 | -- 5,6, and 7 wait for redstone blip on bottom and then place wither skull's | |
10 | -- Note there's no need to verify inventory since they don't pick stuff up, just fill the inventory with sand for 1-4 | |
11 | -- and skulls for 5-7 and it should construct withers. | |
12 | -- This really only works if explosions are disabled in your claim... | |
13 | -- I added the requirement for a redstone signal at the back to allow a way to turn it on and off. | |
14 | - | local function goUp() |
14 | + | -- 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 |
15 | - | while not turtle.up() do |
15 | + | -- (possibly due to running out of soulsand or something) |
16 | - | turtle.digUp() |
16 | + | -- 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 |
17 | -- redstone signal and with the sandstone in the front accessing turtle 3 in particular was a bother | |
18 | ||
19 | local function getTurtleID() | |
20 | - | local function mineClayUp() |
20 | + | local file = fs.open("turtleID.txt", "r") |
21 | - | local has_block, data = turtle.inspectUp() |
21 | + | if not file then |
22 | - | if has_block then |
22 | + | error("Failed to open turtleID.txt. Please create the file with a number from 1 to 7.") |
23 | - | if data.name == "minecraft:clay" then |
23 | + | |
24 | - | turtle.digUp() |
24 | + | local id = tonumber(file.readLine()) |
25 | file.close() | |
26 | if not id or id < 1 or id > 7 then | |
27 | error("Invalid turtle ID in turtleID.txt. Must be a number from 1 to 7.") | |
28 | end | |
29 | - | local function mineClayDown() |
29 | + | return id |
30 | - | local has_block, data = turtle.inspectDown() |
30 | + | |
31 | - | if has_block then |
31 | + | |
32 | - | if data.name == "minecraft:clay" then |
32 | + | local turtleID = getTurtleID() |
33 | - | turtle.digDown() |
33 | + | |
34 | function findNextItem() | |
35 | local currentSlot = turtle.getSelectedSlot() | |
36 | local totalSlots = 16 -- Turtle has 16 slots | |
37 | ||
38 | - | local function goForward() |
38 | + | -- Check all slots, starting from current |
39 | - | while not turtle.forward() do |
39 | + | for i = 0, totalSlots - 1 do |
40 | - | mineClayDown() |
40 | + | local slotToCheck = (currentSlot + i - 1) % totalSlots + 1 |
41 | - | mineClayUp() |
41 | + | turtle.select(slotToCheck) |
42 | - | turtle.dig() |
42 | + | if turtle.getItemCount() > 0 then |
43 | - | mineClayUp() |
43 | + | return true -- Found a non-empty slot |
44 | - | mineClayDown() |
44 | + | |
45 | end | |
46 | ||
47 | -- No non-empty slots found | |
48 | - | local function goDown() |
48 | + | turtle.select(currentSlot) -- Return to original slot |
49 | - | turtle.digDown() |
49 | + | return false |
50 | - | turtle.down() |
50 | + | |
51 | ||
52 | ||
53 | - | turtle.digDown() |
53 | + | -- debug function |
54 | - | turtle.down() |
54 | + | |
55 | - | turtle.digDown() |
55 | + | |
56 | - | turtle.down() |
56 | + | |
57 | end | |
58 | - | for z=1,depth do |
58 | + | |
59 | local function placeForward() | |
60 | - | for x=1,length do |
60 | + | local has_block, data = turtle.inspect() |
61 | if not has_block then | |
62 | - | for z=1,width do |
62 | + | turtle.place() |
63 | - | goForward() |
63 | + | return 1 |
64 | - | end -- at width |
64 | + | |
65 | - | if flip==0 then |
65 | + | return 0 |
66 | - | flip=1 |
66 | + | |
67 | - | turtle.turnRight() |
67 | + | |
68 | - | goForward() |
68 | + | while findNextItem() do -- might as well exit if we run out of stuff |
69 | - | turtle.turnRight() |
69 | + | |
70 | while redstone.getInput("back")==true do | |
71 | - | turtle.turnLeft() |
71 | + | if turtleID>4 then |
72 | - | goForward() |
72 | + | local loop=0 |
73 | - | turtle.turnLeft() |
73 | + | print("Waiting for redstone signal from below.") |
74 | - | flip=0 |
74 | + | while redstone.getInput("bottom")==false do |
75 | sleep(.5) -- wait for go signal | |
76 | - | end -- at length |
76 | + | -- periodically the skulls get placed too soon, so we'll let #6 do an intermittent dig to reset things |
77 | if turtleID==6 then | |
78 | - | goDown() |
78 | + | loop=loop+1 -- 20 loops should be ~10 seconds in .5 second steps |
79 | - | goDown() |
79 | + | if loop==20 then |
80 | turtle.dig() | |
81 | - | if flip==0 then |
81 | + | turtle.place() |
82 | - | turtle.turnLeft() |
82 | + | loop=0 |
83 | - | else |
83 | + | end |
84 | - | turtle.TurnRight() |
84 | + | |
85 | end | |
86 | - | -- print("Debug: Check heading and depth.") |
86 | + | print("Redstone signal received.") |
87 | - | -- pauseMe() |
87 | + | redstone.setOutput("bottom",true) |
88 | - | end -- at depth |
88 | + | while redstone.getInput("bottom")==true do |
89 | sleep(.5) -- wait for signal to stop=ack below | |
90 | - | print("Return to surface (if applicable).") |
90 | + | |
91 | - | x=0 |
91 | + | print("Redstone signal acknowledged.") |
92 | - | while not turtle.up() or x<(depth+2) do -- up until you hit air or reach 'depth' height (relative 0) |
92 | + | redstone.setOutput("bottom",false) |
93 | - | goUp() |
93 | + | while placeForward()==0 do |
94 | - | x=x+1 |
94 | + | sleep(.5) -- try until successful |
95 | -- 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 | |
96 | end | |
97 | print("Block placed forward") | |
98 | else | |
99 | if placeForward()==1 then | |
100 | print("placed inventory forward") | |
101 | if turtleID>1 and turtleID<5 then -- need to exclude 1 since it doesn't get signaled back by turtleID 3 (not necessary) | |
102 | redstone.setOutput("top",true) | |
103 | while redstone.getInput("top")==false do | |
104 | sleep(.5) | |
105 | end | |
106 | redstone.setOutput("top",false) -- wait for turtle above to acknowledge signal | |
107 | end | |
108 | else | |
109 | print("Space blocked") | |
110 | end | |
111 | sleep(5) | |
112 | -- 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 | |
113 | end | |
114 | ||
115 | print("Turtle ",turtleID," Waiting for redstone startup at 5 second intervals") | |
116 | sleep(5) | |
117 | ||
118 | -- redstone signal present loop | |
119 | end | |
120 | ||
121 | print("available item slot selected (or exit)") | |
122 | -- inventory not empty loop | |
123 | end | |
124 | print("exit it is.") | |
125 | pauseMe() | |
126 |