· 4 years ago · Oct 07, 2021, 06:30 AM
1--Get Rich 2 strip mine (Saxburger 2014 - updated 2021 for use with enderchest)
2
3-- [Pastebin get sAPI ("s" file)] --
4-- Code adapted from "pastebin" computercraft file (by Dan200)
5-- This program requires sAPI and needs to download it from pastebin
6if not http then
7 printError( "Pastebin requires http API" )
8 printError( "Set enableAPI_http to true in ComputerCraft.cfg" )
9 return
10end
11local function get(paste)
12 write( "Connecting to pastebin.com... " )
13 local response = http.get(
14 "http://pastebin.com/raw.php?i="..textutils.urlEncode( paste )
15 )
16 if response then
17 print( "Success." )
18 sleep(1)
19 local sResponse = response.readAll()
20 response.close()
21 return sResponse
22 else
23 printError( "Download of \"s\" file failed." )
24 sleep(1)
25 end
26end
27-- Determine file to download
28local sCode = "Y5T6b0aM" -- pastebin code of sAPI ("s" file) current version
29local sFile = "s" -- file name of sAPI
30local sPath = shell.resolve( sFile )
31if fs.exists( sPath ) then
32 --print( "sAPI (\"s\" file) already exists!" )
33else
34 -- GET the contents from pastebin
35 local res = get(sCode)
36 if res then
37 local file = fs.open( sPath, "w" )
38 file.write( res )
39 file.close()
40 print("")
41 print( "This program needs sAPI to function.")
42 print( "Successfully downloaded sAPI as \"" .. sFile .. "\".")
43 print( "Program will start in a few seconds ...")
44 sleep(7)
45 end
46end
47
48 -- [loads functions from sAPI ("s" file)]
49os.loadAPI("s")
50
51local args = { ... }
52local rowlength = args[1]
53local columnpairs = args[2]
54local tcount = 0 -- counts blocks before placing torches
55local dumpCount = 0 -- counts items dumped in enderchest
56if rowlength == nil or columnpairs == nil then
57 s.clearscreen()
58 print(s.txtcent("-- Get Rich 2 Strip Mine --"))
59 print(s.txtcent(" +Use with Enderchests+"))
60 print("1: Place fuel in slot 1")
61 print("2: Place torches in slot 2")
62 print("3: Place dumpchest in slot 3")
63 print("4: Place torchchest in slot 4")
64 print("")
65 print("Usage: getrich <length> <tunnel pairs>")
66 print(" * follow turtle and mine the walls *")
67 return
68end
69s.setdefaultfuel(1,0,1) --sets fuel to slot 1 (1); manual refill (0); 1 fuel at a time (1)
70s.setslotfullcheck(16)
71s.clearscreen()
72print(s.txtcent("-- Get Rich 2 Strip Mine --"))
73print(s.txtcent(" +Use with Enderchests+"))
74print("1: Place fuel in slot 1")
75print("2: Place torches in slot 2")
76print("3: Place dumpchest in slot 3")
77print("4: Place torchchest in slot 4")
78print("")
79print(" * follow turtle and mine the walls *")
80print(" <- \"Any key\" to continue ->")
81read()
82
83--mining
84function torches()
85 if tcount == 5 then
86 if turtle.getItemCount(2) < 2 then
87 turtle.select(4)
88 turtle.placeDown()
89 turtle.select(2)
90 if turtle.getItemCount(2) == 1 then
91 turtle.suckDown(63)
92 end
93 if turtle.getItemCount(2) == 0 then
94 turtle.suckDown(64)
95 end
96 turtle.select(4)
97 turtle.digDown()
98 end
99 turtle.select(5)
100 s.pbd(2,0)
101 tcount = 0
102 else
103 tcount = tcount + 1
104 end
105end
106function dump()
107 local slotsFilled = 0
108 for n=5,16 do
109 if turtle.getItemCount(n) > 0 then
110 slotsFilled = slotsFilled + 1
111 end
112 end
113 if slotsFilled > 11 then
114 print(" dumping items...")
115 turtle.select(3)
116 turtle.placeDown()
117 for i=5,16 do
118 dumpCount = dumpCount + turtle.getItemCount(i)
119 turtle.select(i)
120 turtle.dropDown()
121 end
122 print(" * Total Items Dumped = " .. dumpCount)
123 turtle.select(3)
124 turtle.digDown()
125 end
126 slotsFilled = 0
127 turtle.select(5)
128end
129function dig(length)
130 s.dd()
131 s.du()
132 for i = 1, length, 1 do
133 s.mf()
134 s.dd()
135 s.du()
136 dump()
137 torches()
138 end
139end
140turtle.select(4)
141turtle.placeDown()
142turtle.select(2)
143if turtle.getItemCount(2) == 1 then
144 turtle.suckDown(63)
145end
146if turtle.getItemCount(2) == 0 then
147 turtle.suckDown(64)
148end
149turtle.select(4)
150turtle.digDown()
151for ctr = 1, columnpairs, 1 do
152 dig(rowlength)
153 s.r()
154 dig(3)
155 s.r()
156 dig(rowlength)
157 s.l()
158 dig(3)
159 s.l()
160end
161print(" dumping items...")
162turtle.select(3)
163turtle.placeDown()
164for i=5,16 do
165 dumpCount = dumpCount + turtle.getItemCount(i)
166 turtle.select(i)
167 turtle.dropDown()
168end
169print(" * Total Items Dumped = " .. dumpCount)
170turtle.select(3)
171turtle.digDown()
172slotsFilled = 0
173print("# Mining Complete! #")