· 5 years ago · Jun 25, 2020, 06:28 AM
1--Civilwargeeky's Quarry Program--
2 VERSION = "3.6.4.5"
3--[[
4Recent Changes:
5 Parameter Files! Create a file of parameters, and use -file to load it!
6 Works will with -forcePrompt
7 Quarry no longer goes to start at end of row!
8 Turtle can go left!
9 QuadCopters! Check Lyqyd's thread
10New Parameters:
11 -overfuel/fuelMultiplier [number]: This number is is what neededFuel is multiplied by when fuel is low.
12 -version: This will display the current version number and end the program
13 -file [fileName]: This will load a custom configuration file (basically a list of parameters). "##" starts comment lines. In the future "#" will start programs to run (but only through shell)
14 -preciseTotals [t/f]: If true, turtle will write exactly what it mined to the logs. It may also transmit it over rednet.
15 -forcePrompt [param]: This will add to a list of parameters to force prompt for. So if you say "-forcePrompt doRefuel" it will prompt you "Length","Width","Height","Invert","Do Refuel" etc.
16]]
17--Defining things
18civilTable = nil; _G.civilTable = {}; setmetatable(civilTable, {__index = getfenv()}); setfenv(1,civilTable)
19originalDay = os.day() --Used in logging
20numResumed = 0 --Number of times turtle has been resumed
21-------Defaults for Arguments----------
22--Arguments assignable by text
23x,y,z = 3,3,3 --These are just in case tonumber fails
24inverted = false --False goes from top down, true goes from bottom up [Default false]
25rednetEnabled = false --Default rednet on or off [Default false]
26--Arguments assignable by tArgs
27dropSide = "front" --Side it will eject to when full or done [Default "front"]
28careAboutResources = true --Will not stop mining once inventory full if false [Default true]
29doCheckFuel = true --Perform fuel check [Default true]
30doRefuel = false --Whenever it comes to start location will attempt to refuel from inventory [Default false]
31keepOpen = 1 --How many inventory slots it will attempt to keep open at all times [Default 1]
32fuelSafety = "moderate" --How much fuel it will ask for: safe, moderate, and loose [Default moderate]
33excessFuelAmount = math.huge --How much fuel the turtle will get maximum. Limited by turtle.getFuelLimit in recent CC [Default math.huge]
34fuelMultiplier = 1 --How much extra fuel turtle will ask for when it does need fuel [Default 1]
35saveFile = "Civil_Quarry_Restore" --Where it saves restore data [Default "Civil_Quarry_Restore"]
36autoResume = true --If true, turtle will auto-restart when loaded. [Default true]
37startupRename = "oldStartup.quarry" --What the startup is temporarily renamed to [Default "oldStartup.quarry"]
38startupName = "startup" --What the turtle auto-resumes with [Default "startup"]
39doBackup = true --If it will keep backups for session persistence [Default true]
40uniqueExtras = 8 --How many different items (besides cobble) the turtle expects. [Default 8]
41maxTries = 200 --How many times turtle will try to dig a block before it "counts" bedrock [Default 200]
42gpsEnabled = false -- If option is enabled, will attempt to find position via GPS api [Default false]
43gpsTimeout = 3 --The number of seconds the program will wait to get GPS coords. Not in arguments [Default 3]
44legacyRednet = false --Use this if playing 1.4.7
45logging = true --Whether or not the turtle will log mining runs. [Default ...still deciding]
46logFolder = "Quarry_Logs" --What folder the turtle will store logs in [Default "Quarry_Logs"]
47logExtension = "" --The extension of the file (e.g. ".txt") [Default ""]
48flatBedrock = false --If true, will go down to bedrock to set startDown [Default false]
49startDown = 0 --How many blocks to start down from the top of the mine [Default 0]
50preciseTotals = false --If true, will record exact totals and names for all materials [Default false]
51goLeftNotRight = false --Quarry to left, not right (parameter is "left") [Default false]
52oreQuarry = false --Enables ore quarry functionality [Default false]
53oreQuarryBlacklistName = "oreQuarryBlacklist.txt" --This is the file that will be parsed for item names [Default "oreQuarryBlacklist"]
54dumpCompareItems = true --If ore quarry, the turtle will dump items compared to (like cobblestone) [Default true]
55frontChest = false --If oreQuarry and chest checking, you can turn this on to make turtle check in front of itself for chests as well [Default false]
56lavaBuffer = 500 --If using a lava bucket, this is the buffer it will wait for before checking for lava [Default 500]
57inventoryMax = 16 --The max number of slots in the turtle inventory [Default 16] (Not assignable by parameter)
58quadEnabled = false --Whether or not to request a quadRotor when out of fuel [Default false]
59quadTimeout = 60 * 5 --How long the turtle will wait for a quadRotor [Default 5 minutes]
60--Standard number slots for fuel (you shouldn't care)
61fuelTable = { --Will add in this amount of fuel to requirement.
62safe = 1000,
63moderate = 200,
64loose = 0 } --Default 1000, 200, 0
65--Standard rednet channels
66channels = {
67send = os.getComputerID() + 1 ,
68receive = os.getComputerID() + 101 ,
69confirm = "Turtle Quarry Receiver",
70message = "Civil's Quarry",
71fingerprint = "quarry"
72}
73
74--AVERAGE USER: YOU DON'T CARE BELOW THIS POINT
75
76local help_paragraph = [[
77Welcome!: Welcome to quarry help. Below are help entries for all parameters. Examples and tips are at the bottom.
78-default: This will force no prompts. If you use this and nothing else, only defaults will be used.
79-dim: [length] [width] [height] This sets the dimensions for the quarry
80-invert: [t/f] If true, quarry will be inverted (go up instead of down)
81-rednet: [t/f] If true and you have a wireless modem on the turtle, will attempt to make a rednet connection for sending important information to a screen
82-restore / -resume: If your quarry stopped in the middle of its run, use this to resume at the point where the turtle was. Not guarenteed to work properly. For more accurate location finding, check out the -GPS parameter
83-autoResume / autoRestore: Turtle will automatically resume if stopped. Replaces startup
84-oreQuarry: [t/f] If true, the turtle will use ore quarry mode. It will not mine the blocks that are placed in the turtle initially. So if you put in stone, it will ignore stone blocks and only mine ores.
85-oreQuarry: [t/f] If you are using a newer version of CC, you won't have to put in any compare blocks. (CC 1.64+)
86-blacklist: [file name] If using oreQuarry, this is the blacklist file it will read. Example --
87 minecraft:stone
88 minecraft:sand
89 ThermalExpansion:Sponge
90 ThermalFoundation:Storage
91
92 Note: If you have bspkrsCore, look
93 for "UniqueNames.txt" in your config
94-file: [file name] Will load a file of parameters. One parameter per line. # is a comment line (See the forum thread for more detailed directions)
95-atChest: [force] This is for use with "-restore," this will tell the restarting turtle that it is at its home chest, so that if it had gotten lost, it now knows where it is.
96-doRefuel: [t/f] If true, the turtle will refuel itself with coal and planks it finds on its mining run
97-doCheckFuel: [t/f] If you for some reason don't want the program to check fuel usage, set to false. This is honestly a hold-over from when the refueling algorithm was awful...
98-overfuel: [number] When fuel is below required, fuel usage is multiplied by this. Large numbers permit more quarries without refueling
99-fuelMultiplier: [number] See overfuel
100-uniqueExtras: [number] The expected number of slots filled with low-stacking items like ore. Higher numbers request more fuel.
101-maxFuel: [number] How much the turtle will fuel to max (limited by turtle in most cases)
102-chest: [side] This specifies what side the chest at the end will be on. You can say "top", "bottom", "front", "left", or "right"
103-enderChest: [slot] This one is special. If you use "-enderChest true" then it will use an enderChest in the default slot. However, you can also do "-enderChest [slot]" then it will take the ender chest from whatever slot you tell it to. Like 7... or 14... or whatever.
104-fuelChest: [slot] See the above, but for a fueling chest. Reccommend use with -maxFuel and -doCheckFuel false
105-lava: [slot] If using an oreQuarry, will fill itself with lava it finds to maxFuel
106-lavaBuffer: [number] The amount of fuel below maxFuel the turtle will wait for before using lava again
107-GPS: [force] If you use "-GPS" and there is a GPS network, then the turtle will record its first two positions to precisly calculate its position if it has to restart. This will only take two GPS readings
108-quad: [t/f] This forces the use of GPS. Make sure you have a network set up. This will request to be refueled by a quadrotor from Lyqyd's mod if the turtle is out of fuel
109-quadTimeout: [number] The amount of time the turtle will wait for a quadRotor
110-sendChannel: [number] This is what channel your turtle will send rednet messages on
111-receiveChannel: [number] This is what channel your turtle will receive rednet messages on
112-legacyRednet: [t/f] Check true if using 1.4.7
113-startY: [current Y coord] Randomly encountering bedrock? This is the parameter for you! Just give it what y coordinate you are at right now. If it is not within bedrock range, it will never say it found bedrock
114-startupRename: [file name] What to rename any existing startup to.
115-startupName: [file name] What the turtle will save its startup file to.
116-extraDropItems: [force] If oreQuarry then this will prompt the user for extra items to drop, but not compare to (like cobblestone)
117-dumpCompareItems: [t/f] If oreQuarry and this is true, the turtle will dump off compare blocks instead of storing them in a chest
118-oldOreQuarry: [t/f] If you are using new CC versions, you can use this to use the old oreQuarry.
119-compareChest: [slot] If using oldOreQuarry, this will allow you to check for dungeon chests and suck from them.
120-frontChest: [t/f] If using oreQuarry/oldOreQuarry, this will check in front of itself for chests as well.
121-left: [t/f] If true, turtle will quarry to the left instead of the right
122-maxTries: [number] This is the number of times the turtle will try to dig before deciding its run into bedrock.
123-forcePrompt: [parameter] Whatever parameter you specify, it will always prompt you, like it does now for invert and dim.
124-logging: [t/f] If true, will record information about its mining run in a folder at the end of the mining run
125-preciseTotals: [t/f] If true (and turtle.inspect exists), it will log a detailed record of every block the turtle mines and send it over rednet
126-doBackup: [t/f] If false, will not back up important information and cannot restore, but will not make an annoying file (Actually I don't really know why anyone would use this...)
127-saveFile: [word] This is what the backup file will be called
128-logFolder: [word] The folder that quarry logs will be stored in
129-logExtension: [word] The extension given to each quarry log (e.g. ".txt" or ".notepad" or whatever)
130-keepOpen: [number] This is the number of the slots the turtle will make sure are open. It will check every time it mines
131-careAboutResources: [t/f] Who cares about the materials! If set to false, it will just keep mining when its inventory is full
132-startDown: [number] If you set this, the turtle will go down this many blocks from the start before starting its quarry
133 =
134 C _ |
135 |
136 |
137 |
138 |_ _ _ _ >
139-flatBedrock: [t/f] If true, turtle will find bedrock and "zero" itself so it ends on bedrock level
140-promptAll: This is the opposite of -Default, it prompts for everything
141-listParams: This will list out all your selected parameters and end quarry. Good for testing
142-manualPos: [xPos] [zPos] [yPos] [facing] This is for advanced use. If the server reset when the turtle was in the middle of a 100x100x100 quarry, fear not, you can now manually set the position of the turtle. yPos is always positive. The turtle's starting position is 0, 1, 1, 0. Facing is measured 0 - 3. 0 is forward, and it progresses clockwise. Example- "-manualPos 65 30 30 2"
143-version: Displays the current quarry version and stops the program
144-help: Thats what this is :D
145Examples: Everything below is examples and tips for use
146Important Note:
147 None of the above parameters are necessary. They all have default values, and the above are just if you want to change them.
148Examples [1]:
149 Want to just start a quarry from the interface, without going through menus? It's easy! Just use some parameters. Assume you called the program "quarry." To start a 10x6x3 quarry, you just type in "quarry -dim 10 6 3 -default".
150 You just told it to start a quarry with dimensions 10x6x3, and "-default" means it won't prompt you about invert or rednet. Wasn't that easy?
151Examples [2]:
152 Okay, so you've got the basics of this now, so if you want, you can type in really long strings of stuff to make the quarry do exactly what you want. Now, say you want a 40x20x9, but you want it to go down to diamond level, and you're on the surface (at y = 64). You also want it to send rednet messages to your computer so you can see how its doing.
153Examples [2] [cont.]:
154 Oh yeah! You also want it to use an ender chest in slot 12 and restart if the server crashes. Yeah, you can do that. You would type
155 "quarry -dim 40x20x9 -invert false -startDown 45 -rednet true -enderChest 12 -restore"
156 BAM. Now you can just let that turtle do it's thing
157Tips:
158 The order of the parameters doesn't matter. "quarry -invert false -rednet true" is the same as "quarry -rednet true -invert false"
159
160 Capitalization doesn't matter. "quarry -iNVErt FALSe" does the same thing as "quarry -invert false"
161Tips [cont.]:
162 For [t/f] parameters, you can also use "yes" and "no" so "quarry -invert yes"
163
164 For [t/f] parameters, it only cares about the first letter. So you can use "quarry -invert t" or "quarry -invert y"
165Tips [cont.]:
166 If you are playing with fuel turned off, the program will automatically change settings for you so you don't have to :D
167
168 If you want, you can load this program onto a computer, and use "quarry -help" so you can have help with the parameters whenever you want.
169Internal Config:
170 At the top of this program is an internal configuration file. If there is some setup that you use all the time, you can just change the config value at the top and run "quarry -default" for a quick setup.
171
172 You can also use this if there are settings that you don't like the default value of.
173]]
174--NOTE: BIOS 114 MEANS YOU FORGOT A COLON
175--NOTE: THIS ALSO BREAKS IF YOU REMOVE "REDUNDANT" WHITESPACE
176--Parsing help for display
177--[[The way the help table works:
178All help indexes are numbered. There is a help[i].title that contains the title,
179and the other lines are in help[i][1] - help[i][#help[i] ]
180Different lines (e.g. other than first) start with a space.
181As of now, the words are not wrapped, fix that later]]
182local help = {}
183local i = 0
184local titlePattern = ".-%:" --Find the beginning of the line, then characters, then a ":"
185local textPattern = "%:.+" --Find a ":", then characters until the end of the line
186for a in help_paragraph:gmatch("\n?.-\n") do --Matches in between newlines
187 local current = string.sub(a,1,-2).."" --Concatenate Trick
188 if string.sub(current,1,1) ~= " " then
189 i = i + 1
190 help[i] = {}
191 help[i].title = string.sub(string.match(current, titlePattern),1,-2)..""
192 help[i][1] = string.sub(string.match(current,textPattern) or " ",3,-1)
193 elseif string.sub(current,1,1) == " " then
194 table.insert(help[i], string.sub(current,2, -1).."")
195 end
196end
197
198local supportsRednet
199if peripheral.find then
200 supportsRednet = peripheral.find("modem") or false
201else
202 supportsRednet = (peripheral.getType("right") == "modem") or false
203end
204
205--Pre-defining variables that need to be saved
206 xPos,yPos,zPos,facing,percent,mined,moved,relxPos, rowCheck, connected, isInPath, layersDone, attacked, startY, chestFull, gotoDest, atChest, fuelLevel, numDropOffs, allowedItems, compareSlots, dumpSlots, selectedSlot, extraDropItems, oldOreQuarry, specialSlots, relzPos, eventInsertionPoint
207 = 0, 1, 1, 0, 0, 0, 0, 1, true , false, true, 1, 0, 0, false, "", false, 0, 0, {}, {}, {}, 1, false, false, {explicit = {}}, 0, 1
208
209--These are slot options that need to exist as variables for parameters to work.
210 enderChest, fuelChest, lavaBucket, compareChest
211= false,