Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
games:minecraft:public:computer_craft:quarry_script [2023/03/16 05:46] – clay | games:minecraft:public:computer_craft:quarry_script [2024/01/23 21:59] (current) – clay | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== MOVED TO THE CLAYTONIA GIT SERVER ====== | ||
+ | ===== This is an outdated archive! ===== | ||
+ | |||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ | |||
+ | |||
====== Quarry Miner ====== | ====== Quarry Miner ====== | ||
Line 12: | Line 27: | ||
==== Instructions ==== | ==== Instructions ==== | ||
+ | * Steps 1-4 only needs done the 1st time you place down a turtle. | ||
+ | * Step 5 is optional | ||
+ | * Step 6 is what you run each time you place down a previsouly configured turtle. | ||
1. Place turtle, and a chest to the left of it. | 1. Place turtle, and a chest to the left of it. | ||
Line 23: | Line 41: | ||
< | < | ||
- | OR | ||
- | 4b. Download quarry program from pastebin | + | < |
- | < | + | < |
5a. Create black-list | 5a. Create black-list | ||
Line 47: | Line 64: | ||
</ | </ | ||
- | 5c. The black list feature from step 5a stopped working sometime around 1.19.2 so I started hardcoding the black list into the script. You can add blocks to the blacklist in the script around line 768. | + | 5c. Not nessisary for everyone, only need to do this if the blacklist feature fails for you. Skip this step unless you know what you're doing. |
+ | The black list feature from step 5a stopped working sometime around 1.19.2 so I started hardcoding the black list into the script. You can add blocks to the blacklist in the script around line 768. | ||
Example: | Example: | ||
< | < | ||
--oreQuarry blacklist | --oreQuarry blacklist | ||
- | local blacklist = { " | + | local blacklist = { " |
" | " | ||
</ | </ | ||
Line 59: | Line 77: | ||
6. Run quarry | 6. Run quarry | ||
- | 6a. Skips stone/ | + | 6a. Skips everything on the blacklist and only brings ores back to the chest. |
< | < | ||
- | 6b. Mines everything | + | 6b. Mines everything, makes a big hole! |
< | < | ||
- | Note: add -startDown X to the end of 6a if the turtle messes up and needs to start a few levels down. Example to -startDown 50 blocks from the start. | + | Note: add -startDown X to the end of 6a if the turtle messes up and needs to start a few levels down. I have found this work better than the -restore argument. Example to -startDown 50 blocks from the start. |
< | < | ||
==== Arguments ==== | ==== Arguments ==== | ||
- | <code> | + | |
- | -default: This will force no prompts. If you use this and nothing else, only defaults will be used. | + | <markdown> |
- | -dim: [length] [width] [height] This sets the dimensions for the quarry | + | Welcome!: Welcome to quarry help. Below are help entries for all parameters. Examples and tips are at the bottom. |
- | -invert: [t/f] If true, quarry will be inverted (go up instead of down) | + | - **-dim**: [length] [width] [height] This sets the dimensions for the quarry |
- | -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 | + | - **-invert**: [t/f] If true, quarry will be inverted (go up instead of down) |
- | -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 | + | - **-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 |
- | -autoResume / autoRestore: | + | - **-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 |
- | -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. | + | - -autoResume / autoRestore: |
- | -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+) | + | - -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. |
- | -blacklist: [file name] If using oreQuarry, this is the blacklist file it will read. Example | + | - -oreQuarry: [t/f] If you are using a newer version of CC, you won't have to put in any compare blocks. (CInternal Config: |
+ | - -blacklist: [file name] If using oreQuarry, this is the blacklist file it will read. | ||
+ | Example | ||
minecraft: | minecraft: | ||
minecraft: | minecraft: | ||
ThermalExpansion: | ThermalExpansion: | ||
ThermalFoundation: | ThermalFoundation: | ||
+ | - If you have bspkInternal Config: | ||
+ | - -atChest: [force] This is for use with " | ||
+ | - -doRefuel: [t/f] If true, the turtle will refuel itself with coal and planks it finds on its mining run | ||
+ | - -doCheckFuel: | ||
+ | - -uniqueExtras: | ||
+ | - -chest: [side] This specifies what side the chest at the end will be on. You can say " | ||
+ | - -enderChest: | ||
+ | - -GPS: [force] If you use " | ||
+ | - -sendChannel: | ||
+ | - -receiveChannel: | ||
+ | - -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 | ||
+ | - -startupRename: | ||
+ | - -startupName: | ||
+ | - -extraDropItems: | ||
+ | - -dumpCompareItems: | ||
+ | - -oldOreQuarry: | ||
+ | - -maxTries: [number] This is the number of times the turtle will try to dig before deciding its run into bedrock. | ||
+ | - -logging: [t/f] If true, will record information about its mining run in a folder at the end of the mining run | ||
+ | - -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...) | ||
+ | - -saveFile: [word] TInternal Config:his is what the backup file will be called | ||
+ | - -logFolder: [word] The folder that quarry logs will be stored in | ||
+ | - -logExtension: | ||
+ | - -keepOpen: [number] This is the number of the slots the turtle will make sure are open. It will check every time it mines | ||
+ | - __**-careAboutResources**__: | ||
+ | - -startDown: [number] If you set this, the turtle will go down this many blocks from the start before starting its quarry | ||
+ | - -promptAll: This is the opposite of -Default, it prompts for everything | ||
+ | - -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' | ||
+ | - -help: Thats what this is :D | ||
- | If you have bspkrsCore, look for " | + | ### Examples: Everything below is examples and tips for use |
- | -atChest: [force] This is for use with " | + | |
- | -doRefuel: [t/f] If true, the turtle will refuel itself with coal and planks it finds on its mining run | + | |
- | -doCheckFuel: | + | |
- | -uniqueExtras: | + | |
- | -chest: [side] This specifies what side the chest at the end will be on. You can say " | + | |
- | -enderChest: | + | |
- | -GPS: [force] If you use " | + | |
- | -sendChannel: | + | |
- | -receiveChannel: | + | |
- | -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 | + | |
- | -startupRename: | + | |
- | -startupName: | + | |
- | -extraDropItems: | + | |
- | -dumpCompareItems: | + | |
- | -oldOreQuarry: | + | |
- | -maxTries: [number] This is the number of times the turtle will try to dig before deciding its run into bedrock. | + | |
- | -logging: [t/f] If true, will record information about its mining run in a folder at the end of the mining run | + | |
- | -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...) | + | |
- | -saveFile: [word] This is what the backup file will be called | + | |
- | -logFolder: [word] The folder that quarry logs will be stored in | + | |
- | -logExtension: | + | |
- | -keepOpen: [number] This is the number of the slots the turtle will make sure are open. It will check every time it mines | + | |
- | -careAboutResources: | + | |
- | -startDown: [number] If you set this, the turtle will go down this many blocks from the start before starting its quarry | + | |
- | = | + | |
- | C _ | | + | |
- | | | + | |
- | | | + | |
- | | | + | |
- | |_ _ _ _ > | + | |
- | -promptAll: This is the opposite of -Default, it prompts for everything | + | |
- | -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' | + | |
- | -help: Thats what this is :D | + | |
- | Examples: Everything below is examples and tips for use | + | |
Important Note: | Important Note: | ||
None of the above parameters are necessary. They all have default values, and the above are just if you want to change them. | None of the above parameters are necessary. They all have default values, and the above are just if you want to change them. | ||
- | Examples [1]: | + | #### Examples [1]: |
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 " | 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 " | ||
You just told it to start a quarry with dimensions 10x6x3, and " | You just told it to start a quarry with dimensions 10x6x3, and " | ||
- | Examples [2]: | + | #### Examples [2]: |
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. | 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. | ||
- | Examples [2] [cont.]: | + | ##### Examples [2] [cont.]: |
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 | 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 | ||
" | " | ||
BAM. Now you can just let that turtle do it's thing | BAM. Now you can just let that turtle do it's thing | ||
- | Tips: | ||
- | The order of the parameters doesn' | ||
- | Capitalization doesn' | + | ### Tips: |
+ | - The order of the parameters doesn' | ||
+ | |||
+ | - Capitalization doesn' | ||
Tips [cont.]: | Tips [cont.]: | ||
For [t/f] parameters, you can also use " | For [t/f] parameters, you can also use " | ||
- | For [t/f] parameters, it only cares about the first letter. So you can use " | + | - For [t/f] parameters, it only cares about the first letter. So you can use " |
- | Tips [cont.]: | + | - If you are playing with fuel turned off, the program will automatically change settings for you so you don't have to :D |
- | If you are playing with fuel turned off, the program will automatically change settings for you so you don't have to :D | + | - If you want, you can load this program onto a computer, and use " |
- | If you want, you can load this program onto a computer, and use " | + | ### Internal Config: |
- | Internal Config: | + | |
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 " | 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 " | ||
- | You can also use this if there are settings that you don't like the default value of.</code> | + | You can also use this if there are settings that you don't like the default value of.</markdown> |
==== Pastebin ==== | ==== Pastebin ==== | ||
Line 152: | Line 166: | ||
==== Lua script ==== | ==== Lua script ==== | ||
+ | [[games: | ||
- | <file lua miner.lua> | ||
- | --Civilwargeeky' | ||
- | VERSION = " | ||
- | --[[ | ||
- | Recent Changes: | ||
- | Parameter Files! Create a file of parameters, and use -file to load it! | ||
- | Works will with -forcePrompt | ||
- | Quarry no longer goes to start at end of row! | ||
- | Turtle can go left! | ||
- | QuadCopters! Check Lyqyd' | ||
- | New Parameters: | ||
- | -overfuel/ | ||
- | -version: This will display the current version number and end the program | ||
- | -file [fileName]: This will load a custom configuration file (basically a list of parameters). "##" | ||
- | -preciseTotals [t/f]: If true, turtle will write exactly what it mined to the logs. It may also transmit it over rednet. | ||
- | -forcePrompt [param]: This will add to a list of parameters to force prompt for. So if you say " | ||
- | ]] | ||
- | --Defining things | ||
- | civilTable = nil; _G.civilTable = {}; setmetatable(civilTable, | ||
- | originalDay = os.day() --Used in logging | ||
- | numResumed = 0 --Number of times turtle has been resumed | ||
- | -------Defaults for Arguments---------- | ||
- | --Arguments assignable by text | ||
- | x,y,z = 3,3,3 --These are just in case tonumber fails | ||
- | inverted = false --False goes from top down, true goes from bottom up [Default false] | ||
- | rednetEnabled = false --Default rednet on or off [Default false] | ||
- | --Arguments assignable by tArgs | ||
- | dropSide = " | ||
- | careAboutResources = true --Will not stop mining once inventory full if false [Default true] | ||
- | doCheckFuel = true --Perform fuel check [Default true] | ||
- | doRefuel = false --Whenever it comes to start location will attempt to refuel from inventory [Default false] | ||
- | keepOpen = 1 --How many inventory slots it will attempt to keep open at all times [Default 1] | ||
- | fuelSafety = " | ||
- | excessFuelAmount = math.huge --How much fuel the turtle will get maximum. Limited by turtle.getFuelLimit in recent CC [Default math.huge] | ||
- | fuelMultiplier = 1 --How much extra fuel turtle will ask for when it does need fuel [Default 1] | ||
- | saveFile = " | ||
- | autoResume = true --If true, turtle will auto-restart when loaded. [Default true] | ||
- | startupRename = " | ||
- | startupName = " | ||
- | doBackup = true --If it will keep backups for session persistence [Default true] | ||
- | uniqueExtras = 8 --How many different items (besides cobble) the turtle expects. [Default 8] | ||
- | maxTries = 200 --How many times turtle will try to dig a block before it " | ||
- | gpsEnabled = false -- If option is enabled, will attempt to find position via GPS api [Default false] | ||
- | gpsTimeout = 3 --The number of seconds the program will wait to get GPS coords. Not in arguments [Default 3] | ||
- | legacyRednet = false --Use this if playing 1.4.7 | ||
- | logging = true --Whether or not the turtle will log mining runs. [Default ...still deciding] | ||
- | logFolder = " | ||
- | logExtension = "" | ||
- | flatBedrock = false --If true, will go down to bedrock to set startDown [Default false] | ||
- | startDown = 0 --How many blocks to start down from the top of the mine [Default 0] | ||
- | preciseTotals = false --If true, will record exact totals and names for all materials [Default false] | ||
- | goLeftNotRight = false --Quarry to left, not right (parameter is " | ||
- | oreQuarry = false --Enables ore quarry functionality [Default false] | ||
- | oreQuarryBlacklistName = " | ||
- | dumpCompareItems = true --If ore quarry, the turtle will dump items compared to (like cobblestone) [Default true] | ||
- | frontChest = 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] | ||
- | lavaBuffer = 500 --If using a lava bucket, this is the buffer it will wait for before checking for lava [Default 500] | ||
- | inventoryMax = 16 --The max number of slots in the turtle inventory [Default 16] (Not assignable by parameter) | ||
- | quadEnabled = false --Whether or not to request a quadRotor when out of fuel [Default false] | ||
- | quadTimeout = 60 * 5 --How long the turtle will wait for a quadRotor [Default 5 minutes] | ||
- | --Standard number slots for fuel (you shouldn' | ||
- | fuelTable = { --Will add in this amount of fuel to requirement. | ||
- | safe = 1000, | ||
- | moderate = 200, | ||
- | loose = 0 } --Default 1000, 200, 0 | ||
- | --Standard rednet channels | ||
- | channels = { | ||
- | send = os.getComputerID() + 1 , | ||
- | receive = os.getComputerID() + 101 , | ||
- | confirm = " | ||
- | message = " | ||
- | fingerprint = " | ||
- | } | ||
- | |||
- | --AVERAGE USER: YOU DON'T CARE BELOW THIS POINT | ||
- | |||
- | local help_paragraph = [[ | ||
- | Welcome!: Welcome to quarry help. Below are help entries for all parameters. Examples and tips are at the bottom. | ||
- | -default: This will force no prompts. If you use this and nothing else, only defaults will be used. | ||
- | -dim: [length] [width] [height] This sets the dimensions for the quarry | ||
- | -invert: [t/f] If true, quarry will be inverted (go up instead of down) | ||
- | -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 | ||
- | -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 | ||
- | -autoResume / autoRestore: | ||
- | -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. | ||
- | -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+) | ||
- | -blacklist: [file name] If using oreQuarry, this is the blacklist file it will read. Example -- | ||
- | minecraft: | ||
- | minecraft: | ||
- | ThermalExpansion: | ||
- | ThermalFoundation: | ||
- | | ||
- | Note: If you have bspkrsCore, look | ||
- | for " | ||
- | -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) | ||
- | -atChest: [force] This is for use with " | ||
- | -doRefuel: [t/f] If true, the turtle will refuel itself with coal and planks it finds on its mining run | ||
- | -doCheckFuel: | ||
- | -overfuel: [number] When fuel is below required, fuel usage is multiplied by this. Large numbers permit more quarries without refueling | ||
- | -fuelMultiplier: | ||
- | -uniqueExtras: | ||
- | -maxFuel: [number] How much the turtle will fuel to max (limited by turtle in most cases) | ||
- | -chest: [side] This specifies what side the chest at the end will be on. You can say " | ||
- | -enderChest: | ||
- | -fuelChest: [slot] See the above, but for a fueling chest. Reccommend use with -maxFuel and -doCheckFuel false | ||
- | -lava: [slot] If using an oreQuarry, will fill itself with lava it finds to maxFuel | ||
- | -lavaBuffer: | ||
- | -GPS: [force] If you use " | ||
- | -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' | ||
- | -quadTimeout: | ||
- | -sendChannel: | ||
- | -receiveChannel: | ||
- | -legacyRednet: | ||
- | -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 | ||
- | -startupRename: | ||
- | -startupName: | ||
- | -extraDropItems: | ||
- | -dumpCompareItems: | ||
- | -oldOreQuarry: | ||
- | -compareChest: | ||
- | -frontChest: | ||
- | -left: [t/f] If true, turtle will quarry to the left instead of the right | ||
- | -maxTries: [number] This is the number of times the turtle will try to dig before deciding its run into bedrock. | ||
- | -forcePrompt: | ||
- | -logging: [t/f] If true, will record information about its mining run in a folder at the end of the mining run | ||
- | -preciseTotals: | ||
- | -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...) | ||
- | -saveFile: [word] This is what the backup file will be called | ||
- | -logFolder: [word] The folder that quarry logs will be stored in | ||
- | -logExtension: | ||
- | -keepOpen: [number] This is the number of the slots the turtle will make sure are open. It will check every time it mines | ||
- | -careAboutResources: | ||
- | -startDown: [number] If you set this, the turtle will go down this many blocks from the start before starting its quarry | ||
- | = | ||
- | C _ | | ||
- | | | ||
- | | | ||
- | | | ||
- | |_ _ _ _ > | ||
- | -flatBedrock: | ||
- | -promptAll: This is the opposite of -Default, it prompts for everything | ||
- | -listParams: | ||
- | -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' | ||
- | -version: Displays the current quarry version and stops the program | ||
- | -help: Thats what this is :D | ||
- | Examples: Everything below is examples and tips for use | ||
- | Important Note: | ||
- | None of the above parameters are necessary. They all have default values, and the above are just if you want to change them. | ||
- | Examples [1]: | ||
- | 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 " | ||
- | You just told it to start a quarry with dimensions 10x6x3, and " | ||
- | Examples [2]: | ||
- | 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. | ||
- | Examples [2] [cont.]: | ||
- | 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 | ||
- | " | ||
- | BAM. Now you can just let that turtle do it's thing | ||
- | Tips: | ||
- | The order of the parameters doesn' | ||
- | | ||
- | Capitalization doesn' | ||
- | Tips [cont.]: | ||
- | For [t/f] parameters, you can also use " | ||
- | | ||
- | For [t/f] parameters, it only cares about the first letter. So you can use " | ||
- | Tips [cont.]: | ||
- | If you are playing with fuel turned off, the program will automatically change settings for you so you don't have to :D | ||
- | | ||
- | If you want, you can load this program onto a computer, and use " | ||
- | Internal Config: | ||
- | 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 " | ||
- | | ||
- | You can also use this if there are settings that you don't like the default value of. | ||
- | ]] | ||
- | --NOTE: BIOS 114 MEANS YOU FORGOT A COLON | ||
- | --NOTE: THIS ALSO BREAKS IF YOU REMOVE " | ||
- | --Parsing help for display | ||
- | --[[The way the help table works: | ||
- | All help indexes are numbered. There is a help[i].title that contains the title, | ||
- | and the other lines are in help[i][1] - help[i][# | ||
- | Different lines (e.g. other than first) start with a space. | ||
- | As of now, the words are not wrapped, fix that later]] | ||
- | local help = {} | ||
- | local i = 0 | ||
- | local titlePattern = " | ||
- | local textPattern = " | ||
- | for a in help_paragraph: | ||
- | local current = string.sub(a, | ||
- | if string.sub(current, | ||
- | i = i + 1 | ||
- | help[i] = {} | ||
- | help[i].title = string.sub(string.match(current, | ||
- | help[i][1] = string.sub(string.match(current, | ||
- | elseif string.sub(current, | ||
- | table.insert(help[i], | ||
- | end | ||
- | end | ||
- | |||
- | local supportsRednet | ||
- | if peripheral.find then | ||
- | supportsRednet = peripheral.find(" | ||
- | else | ||
- | supportsRednet = (peripheral.getType(" | ||
- | end | ||
- | |||
- | --Pre-defining variables that need to be saved | ||
- | xPos, | ||
- | = 0, | ||
- | |||
- | --These are slot options that need to exist as variables for parameters to work. | ||
- | enderChest, fuelChest, lavaBucket, compareChest | ||
- | = false, | ||
- | |||
- | local chestID, lavaID, lavaMeta = " | ||
- | |||
- | local statusString | ||
- | |||
- | --Initializing various inventory management tables | ||
- | for i=1, inventoryMax do | ||
- | allowedItems[i] = 0 --Number of items allowed in slot when dropping items | ||
- | dumpSlots[i] = false --Does this slot contain junk items? | ||
- | end --compareSlots is a table of the compare slots, not all slots with a condition | ||
- | totals = {cobble = 0, fuel = 0, other = 0} -- Total for display (cannot go inside function), this goes up here because many functions use it | ||
- | |||
- | local function newSpecialSlot(index, | ||
- | value = tonumber(value) or 0 --We only want numerical indexes | ||
- | local flag = false --Used in slot moving, moved slot is returned for ease of use | ||
- | local function check(num) return num >= 1 and num <= inventoryMax end | ||
- | if not check(value) then error(" | ||
- | local function getFirstFree(start) | ||
- | for i=1, math.max(inventoryMax-value, | ||
- | for a=-1,1,2 do | ||
- | local num = value + (a*i) | ||
- | if check(num) and not specialSlots[num] then return num end | ||
- | end | ||
- | end | ||
- | return false | ||
- | end | ||
- | if specialSlots[value] and specialSlots[value] ~= index then --If we aren't trying to override the same slot :P | ||
- | if not explicit then | ||
- | value = getFirstFree(value) or error(" | ||
- | elseif explicit and not specialSlots.explicit[value] then --Moving around other slots | ||
- | flag = getFirstFree(value) | ||
- | if not flag then error(" | ||
- | specialSlots[flag] = specialSlots[value] | ||
- | specialSlots[specialSlots[value]] = flag --These will get set to the new thing later | ||
- | else | ||
- | error(' | ||
- | end | ||
- | end | ||
- | specialSlots[index] = value | ||
- | specialSlots[value] = index | ||
- | if explicit then | ||
- | specialSlots.explicit[value] = index | ||
- | end | ||
- | return value, flag | ||
- | end | ||
- | |||
- | function resetDumpSlots() | ||
- | for i=1, inventoryMax do | ||
- | if oldOreQuarry then | ||
- | if turtle.getItemCount(i) > 0 and i~= specialSlots.enderChest then | ||
- | dumpSlots[i] = true | ||
- | else | ||
- | dumpSlots[i] = false | ||
- | end | ||
- | else | ||
- | dumpSlots[i] = false | ||
- | end | ||
- | end | ||
- | if not oldOreQuarry and specialSlots.enderChest == 1 then | ||
- | dumpSlots[2] = true | ||
- | elseif not oldOreQuarry then | ||
- | dumpSlots[1] = true | ||
- | end | ||
- | end | ||
- | |||
- | local function copyTable(tab) if type(tab) ~= " | ||
- | |||
- | --NOTE: rowCheck is a bit. true = " | ||
- | |||
- | local foundBedrock = false | ||
- | |||
- | local checkFuel, checkFuelLimit | ||
- | if turtle then --Function inits | ||
- | checkFuel = turtle.getFuelLevel | ||
- | if turtle.getFuelLevel() == " | ||
- | checkFuel = function() return math.huge end --Infinite Fuel | ||
- | end --There is no " | ||
- | if turtle.getFuelLimit then | ||
- | checkFuelLimit = function() return math.min(turtle.getFuelLimit(), | ||
- | if turtle.getFuelLimit() == " | ||
- | checkFuelLimit = function() return math.huge end | ||
- | end | ||
- | else | ||
- | checkFuelLimit = function() return excessFuelAmount end --If the function doesn' | ||
- | end | ||
- | |||
- | |||
- | turtle.select(1) --To ensure this is correct | ||
- | end | ||
- | |||
- | |||
- | function select(slot) | ||
- | if slot ~= selectedSlot and slot > 0 and slot <= inventoryMax then | ||
- | selectedSlot = slot | ||
- | return turtle.select(slot), | ||
- | end | ||
- | end | ||
- | |||
- | |||
- | | ||
- | --Input Phase | ||
- | local function screen(xPos, | ||
- | xPos, yPos = xPos or 1, yPos or 1 | ||
- | term.setCursorPos(xPos, | ||
- | local function screenLine(xPos, | ||
- | term.setCursorPos(xPos, | ||
- | |||
- | screen(1,1) | ||
- | print(" | ||
- | print("" | ||
- | |||
- | local sides = {top = " | ||
- | local tArgs --Will be set in initializeArgs | ||
- | local originalArgs = {...} | ||
- | local changedT, tArgsWithUpper, | ||
- | changedT.new = function(key, | ||
- | changedT.remove = function(num) changedT[num or # | ||
- | local function capitalize(text) return (string.upper(string.sub(text, | ||
- | local function initializeArgs() | ||
- | tArgs = copyTable(originalArgs) --" | ||
- | for i=1, #tArgs do --My signature key-value pair system, now with upper | ||
- | tArgsWithUpper[i] = tArgs[i] | ||
- | tArgsWithUpper[tArgsWithUpper[i]] = i | ||
- | tArgs[i] = tArgs[i]: | ||
- | tArgs[tArgs[i]] = i | ||
- | if tArgs[i] == " | ||
- | forcePrompts[tArgs[i+1]: | ||
- | end | ||
- | end | ||
- | end | ||
- | initializeArgs() | ||
- | |||
- | local restoreFound, | ||
- | function parseParam(name, | ||
- | --[[ Guide to Variables | ||
- | originalValue: | ||
- | givenValue: This is the value after the parameter. So -invert fAlSe, givenValue is " | ||
- | ]] | ||
- | if variableExists ~= false then variableExists = true end --Almost all params should have the variable exist. Some don't exist unless invoked | ||
- | if trigger == nil then trigger = true end --Defaults to being able to run | ||
- | if not trigger then return end --This is what the trigger is for. Will not run if trigger not there | ||
- | if restoreFoundSwitch or tArgs[" | ||
- | if not restoreFoundSwitch and (tArgs[" | ||
- | local toGetText = name: | ||
- | local formatType = formatString: | ||
- | local args = formatString: | ||
- | local variable = variableOverride or name --Goes first to the override for name | ||
- | local func = loadstring(" | ||
- | setfenv(func, | ||
- | local originalValue = assert(func)() --This is the default value, for checking to add to changed table | ||
- | if originalValue == nil and variableExists then error(" | ||
- | local givenValue, toRet, values --Initializing for use | ||
- | if tArgs[" | ||
- | givenValue = tArgsWithUpper[tArgs[" | ||
- | elseif forcePrompt then | ||
- | write(displayText.."? | ||
- | givenValue = io.read() | ||
- | end | ||
- | if formatType == " | ||
- | toRet = (tArgs[" | ||
- | end | ||
- | if not (givenValue or toRet) or (type(givenValue) == " | ||
- | if formatType == " | ||
- | toRet = givenValue: | ||
- | elseif formatType == " | ||
- | toRet = givenValue: | ||
- | elseif formatType == " | ||
- | toRet = tonumber(givenValue) --Note this is a local, not the above so we don't change anything | ||
- | if not toRet then return end --We need a number... Otherwise compare errors | ||
- | if formatType == " | ||
- | local startNum, endNum = formatString: | ||
- | startNum, endNum = tonumber(startNum), | ||
- | if not ((toRet >= startNum) and (toRet <= endNum)) then return end --Can' | ||
- | elseif formatType == " | ||
- | local exclusionTab = {} --Ignore the wizardry here. Just getting arguments without format string | ||
- | for a in args: | ||
- | if not exclusionTab[givenValue] then toRet = sides[givenValue] end --If side is not excluded | ||
- | elseif formatType == " | ||
- | toRet = {} | ||
- | for a in args: | ||
- | table.insert(toRet, | ||
- | end | ||
- | elseif formatType == " | ||
- | if givenValue: | ||
- | toRet = false | ||
- | else | ||
- | local userNumber, correction = givenValue: | ||
- | toRet, correction = newSpecialSlot(variable, | ||
- | if correction then changedT[changedT[specialSlots[correction]]][2] = tostring(correction) end --This changes the value field of the changedT index taken from the named pointer (which is the value in specialSlots under correction) | ||
- | end | ||
- | elseif formatType == " | ||
- | else error(" | ||
- | end | ||
- | if toRet == nil then return end --Don' | ||
- | tempParam = toRet --This is what loadstring will see :D | ||
- | local func = loadstring(variable.." | ||
- | setfenv(func, | ||
- | func() | ||
- | tempParam = nil --Cleanup of global | ||
- | if toRet ~= originalValue and displayText ~= "" | ||
- | changedT.new(displayText, | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | |||
- | local paramLookup = {} | ||
- | local function addParam(...) | ||
- | local args = {...} | ||
- | if not paramLookup[args[1]] then | ||
- | local toRet = copyTable(args) | ||
- | for i=2, table.maxn(toRet) do --Have to do this because table.remove breaks on nil | ||
- | toRet[i-1] = toRet[i] | ||
- | end | ||
- | table.remove(toRet) | ||
- | paramLookup[args[1]] = toRet | ||
- | end | ||
- | return parseParam(unpack(args, | ||
- | end | ||
- | |||
- | local function paramAlias(original, | ||
- | local a = paramLookup[original] | ||
- | if a then | ||
- | if a[5] == nil then a[5] = original end --This is variableOverride because the originals won't put a variable override | ||
- | return parseParam(alias, | ||
- | else | ||
- | error(" | ||
- | end | ||
- | end | ||
- | |||
- | --Check if it is a turtle | ||
- | if not(turtle or tArgs[" | ||
- | print(" | ||
- | print(" | ||
- | if ({os.pullEvent(" | ||
- | end | ||
- | |||
- | if tArgs[" | ||
- | print(" | ||
- | local pos = 1 | ||
- | local key = 0 | ||
- | while pos <= #help and key ~= keys.q do | ||
- | if pos < 1 then pos = 1 end | ||
- | screen(1,1) | ||
- | print(help[pos].title) | ||
- | for a=1, #help[pos] do print(help[pos][a]) end | ||
- | repeat | ||
- | _, key = os.pullEvent(" | ||
- | until key == 200 or key == 208 or key == keys.q | ||
- | if key == 200 then pos = pos - 1 end | ||
- | if key == 208 then pos = pos + 1 end | ||
- | end | ||
- | error("", | ||
- | end | ||
- | |||
- | if tArgs[" | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | |||
- | --Loading custom parameter lists | ||
- | local function split(str, sep) | ||
- | assert(#sep == 1, "Split seperator too long. Got '" | ||
- | if not str: | ||
- | local toRet = {} | ||
- | toRet[1] = str: | ||
- | for i in str: | ||
- | toRet[# | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | |||
- | if addParam(" | ||
- | if not fs.exists(parameterFile) then | ||
- | print(" | ||
- | sleep(3) | ||
- | changedT.remove() | ||
- | else | ||
- | local file = fs.open(parameterFile, | ||
- | local text = file.readAll() | ||
- | file.close() | ||
- | text = text.." | ||
- | text = text: | ||
- | local commands = {} --Contains all the parameters | ||
- | local append = table.insert | ||
- | for _, a in pairs(split(text," | ||
- | local words = split(a," | ||
- | if not a: | ||
- | append(originalArgs," | ||
- | for i=2, #words do | ||
- | append(originalArgs, | ||
- | end | ||
- | else --Otherwise the dashes are already ordered where we want! | ||
- | for i=1, #words do | ||
- | append(originalArgs, | ||
- | end | ||
- | end | ||
- | end | ||
- | initializeArgs() --Manipulate the args again, because we modified them | ||
- | print(" | ||
- | sleep(0.5) --Give em a sec | ||
- | end | ||
- | end | ||
- | |||
- | |||
- | |||
- | --Saving | ||
- | addParam(" | ||
- | addParam(" | ||
- | |||
- | restoreFound = fs.exists(saveFile) | ||
- | restoreFoundSwitch = (tArgs[" | ||
- | if restoreFoundSwitch then | ||
- | local file = fs.open(saveFile," | ||
- | local test = file.readAll() ~= "" | ||
- | file.close() | ||
- | if test then | ||
- | local temp = shell and copyTable(shell) --For whatever reason, the shell table doesn' | ||
- | os.run(getfenv(1), | ||
- | shell = temp | ||
- | numResumed = numResumed + 1 | ||
- | if checkFuel() ~= math.huge then --If turtle uses fuel | ||
- | if fuelLevel - checkFuel() == 1 then | ||
- | if facing == 0 then xPos = xPos + 1 | ||
- | elseif facing == 2 then xPos = xPos - 1 | ||
- | elseif facing == 1 then zPos = zPos + 1 | ||
- | elseif facing == 3 then zPos = zPos - 1 end | ||
- | elseif fuelLevel - checkFuel() ~= 0 then | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | os.pullEvent(" | ||
- | end | ||
- | end | ||
- | if gpsEnabled then --If it had saved gps coordinates | ||
- | print(" | ||
- | local currLoc = {gps.locate(gpsTimeout)} or {} | ||
- | local backupPos = {xPos, yPos, zPos} --This is for comparing to later | ||
- | if #currLoc > 0 and # | ||
- | print(" | ||
- | if currLoc[1] == gpsStartPos[1] and currLoc[3] == gpsStartPos[3] then --X coord, y coord, z coord in that order | ||
- | xPos, yPos, zPos = 0,1,1 | ||
- | if facing ~= 0 then turnTo(0) end | ||
- | print(" | ||
- | else | ||
- | if inverted then --yPos setting | ||
- | ------------------------------------------------FIX THIS | ||
- | end | ||
- | local a, b = copyTable(gpsStartPos), | ||
- | local flag = true --So we can account for left quarry | ||
- | if b[3] - a[3] == -1 then--If went north (-Z) | ||
- | a[1] = a[1] - 1 --Shift x one to west to create a " | ||
- | xPos, zPos = -currLoc[3] + a[3], currLoc[1] + -a[1] | ||
- | elseif b[1] - a[1] == 1 then--If went east (+X) | ||
- | a[3] = a[3] - 1 --Shift z up one to north to create a " | ||
- | xPos, zPos = currLoc[1] + -a[1], currLoc[3] + -a[3] | ||
- | elseif b[3] - a[3] == 1 then--If went south (+Z) | ||
- | a[1] = a[1] + 1 --Shift x one to east to create a " | ||
- | xPos, zPos = currLoc[3] + a[3], -currLoc[1] + a[3] | ||
- | elseif b[1] - a[1] == -1 then--If went west (-X) | ||
- | a[3] = a[3] + 1 --Shift z down one to south to create a " | ||
- | xPos, zPos = -currLoc[1] + a[1], -currLoc[3] + a[3] | ||
- | else | ||
- | flag = false | ||
- | print(" | ||
- | print(" | ||
- | end | ||
- | if flag and goLeftNotRight then --This accounts for left quarry (barred to left only because there might be errors in a regular, causing neg/0 | ||
- | zPos = math.abs(zPos-1) + 1 | ||
- | end | ||
- | end | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | for i=1, 3, 2 do --We want 1 and 3, but 2 could be coming back to start. | ||
- | if backupPos[i] ~= currLoc[i] then | ||
- | events = {} --We want to remove event queue if not in proper place, so won't turn at end of row or things. | ||
- | end | ||
- | end | ||
- | else | ||
- | print(" | ||
- | end | ||
- | print(" | ||
- | end | ||
- | else | ||
- | fs.delete(saveFile) | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | else --If turtle is just starting | ||
- | events = {} --This is the event queue :D | ||
- | originalFuel = checkFuel() --For use in logging. To see how much fuel is REALLY used | ||
- | end | ||
- | |||
- | --Dimensions | ||
- | if tArgs[" | ||
- | local a,b,c = x,y,z | ||
- | local num = tArgs[" | ||
- | x = tonumber(tArgs[num + 1]) or x; z = tonumber(tArgs[num + 2]) or z; y = tonumber(tArgs[num + 3]) or y | ||
- | if a ~= x then changedT.new(" | ||
- | if c ~= z then changedT.new(" | ||
- | if b ~= y then changedT.new(" | ||
- | elseif not (tArgs[" | ||
- | print(" | ||
- | print("" | ||
- | --This will protect from negatives, letters, and decimals | ||
- | term.write(" | ||
- | x = math.floor(math.abs(tonumber(io.read()) or x)) | ||
- | term.write(" | ||
- | z = math.floor(math.abs(tonumber(io.read()) or z)) | ||
- | term.write(" | ||
- | y = math.floor(math.abs(tonumber(io.read()) or y)) | ||
- | changedT.new(" | ||
- | end | ||
- | --Params: parameter/ | ||
- | --Invert | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Inventory | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Rednet | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Quad Rotor --Must be before GPS | ||
- | if addParam(" | ||
- | gpsEnabled = true | ||
- | end | ||
- | addParam(" | ||
- | --GPS | ||
- | addParam(" | ||
- | if gpsEnabled and not restoreFoundSwitch then | ||
- | gpsStartPos = {gps.locate(gpsTimeout)} --Stores position in array | ||
- | gpsEnabled = # | ||
- | if quadEnabled and not gpsEnabled then | ||
- | error(" | ||
- | end | ||
- | end | ||
- | --Fuel | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | excessFuelAmount = excessFuelAmount or math.huge --Math.huge apparently doesn' | ||
- | addParam(" | ||
- | addParam(" | ||
- | paramAlias(" | ||
- | paramAlias(" | ||
- | --Logging | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Misc | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Inventory | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | if preciseTotals and not restoreFoundSwitch then | ||
- | exactTotals = {} --Don' | ||
- | end | ||
- | --Auto Startup | ||
- | addParam(" | ||
- | paramAlias(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --Ore Quarry | ||
- | addParam(" | ||
- | if oreQuarry and not turtle.inspect then | ||
- | oldOreQuarry = true | ||
- | oreQuarry = false | ||
- | end | ||
- | addParam(" | ||
- | paramAlias(" | ||
- | paramAlias(" | ||
- | addParam(" | ||
- | --Old Ore | ||
- | addParam(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | paramAlias(" | ||
- | addParam(" | ||
- | addParam(" | ||
- | --New Ore | ||
- | addParam(" | ||
- | paramAlias(" | ||
- | --Mod Related | ||
- | |||
- | --Extra | ||
- | if tArgs[" | ||
- | screen() | ||
- | print(" | ||
- | for key, val in ipairs(changedT) do | ||
- | if not val.hidden then | ||
- | print(val[1],": | ||
- | end | ||
- | end | ||
- | error(" | ||
- | end | ||
- | | ||
- | |||
- | --for flatBedrock | ||
- | if flatBedrock then | ||
- | inverted = false | ||
- | end | ||
- | |||
- | --Auto Startup functions | ||
- | local function doAutoResumeStuff() | ||
- | if fs.exists(startupName) then | ||
- | if fs.exists(startupRename) then fs.delete(startupRename) end | ||
- | fs.move(startupName, | ||
- | end | ||
- | local file = fs.open(startupName," | ||
- | file.writeLine( --The below is on the left because spacing | ||
- | [[ | ||
- | --This is an auto-generated startup | ||
- | --Made by civilwargeeky' | ||
- | print(" | ||
- | print(" | ||
- | function deleteStuff() | ||
- | fs.delete(" | ||
- | if fs.exists(" | ||
- | fs.move(" | ||
- | end | ||
- | end | ||
- | local event | ||
- | if fs.exists(" | ||
- | for i=5,1,-1 do | ||
- | print(i) | ||
- | os.startTimer(1) | ||
- | event = os.pullEvent() | ||
- | if event == " | ||
- | end | ||
- | if event == " | ||
- | os.run({}," | ||
- | else | ||
- | |||
- | deleteStuff() | ||
- | end | ||
- | else | ||
- | print(" | ||
- | deleteStuff() | ||
- | end | ||
- | ]]) | ||
- | file.close() | ||
- | end | ||
- | if autoResume and not restoreFoundSwitch then --Don' | ||
- | doAutoResumeStuff() | ||
- | end | ||
- | --oreQuarry blacklist | ||
- | local blacklist = { " | ||
- | " | ||
- | for a,b in pairs(copyTable(blacklist)) do | ||
- | blacklist[b], | ||
- | end | ||
- | if fs.exists(oreQuarryBlacklistName) then --Loading user-defined blacklist | ||
- | local file = fs.open(oreQuarryBlacklistName, | ||
- | blacklist = {} | ||
- | for a in file: | ||
- | blacklist[a: | ||
- | end | ||
- | file: | ||
- | end | ||
- | |||
- | --Manual Position | ||
- | if tArgs[" | ||
- | local a = tArgs[" | ||
- | xPos, zPos, yPos, facing = tonumber(tArgs[a+1]) or xPos, tonumber(tArgs[a+2]) or zPos, tonumber(tArgs[a+3]) or yPos, tonumber(tArgs[a+4]) or facing | ||
- | changedT.new(" | ||
- | restoreFoundSwitch = true --So it doesn' | ||
- | for i=0,4 do tArgs[a+i] = "" | ||
- | end | ||
- | if addParam(" | ||
- | local neededLayer = math.floor((yPos+1)/ | ||
- | if neededLayer > 2 and neededLayer%3 ~= 2 then --If turtle was not on a proper mining layer | ||
- | print(" | ||
- | sleep(4) | ||
- | neededLayer = 2 | ||
- | end | ||
- | xPos, zPos, yPos, facing, rowCheck, layersDone = 0,1,1, 0, true, math.ceil(neededLayer/ | ||
- | doAutoResumeStuff() --This was probably deleted when they hit a key to launch with -atChest | ||
- | events = {{" | ||
- | end | ||
- | |||
- | |||
- | local function saveProgress(extras) --Session persistence | ||
- | exclusions = { modem = true, shell = true, _ENV = true} | ||
- | if doBackup then | ||
- | local toWrite = "" | ||
- | for a,b in pairs(getfenv(1)) do | ||
- | if not exclusions[a] then | ||
- | --print(a ," | ||
- | if type(b) == " | ||
- | if type(b) == " | ||
- | if type(b) ~= " | ||
- | toWrite = toWrite..a.." | ||
- | end | ||
- | end | ||
- | end | ||
- | toWrite = toWrite.." | ||
- | local file | ||
- | repeat | ||
- | file = fs.open(saveFile," | ||
- | until file | ||
- | file.write(toWrite) | ||
- | if type(extras) == " | ||
- | for a, b in pairs(extras) do | ||
- | file.write(a.." | ||
- | end | ||
- | end | ||
- | if checkFuel() ~= math.huge then --Used for location comparing | ||
- | file.write(" | ||
- | end | ||
- | file.close() | ||
- | end | ||
- | end | ||
- | |||
- | local area = x*z | ||
- | local volume = x*y*z | ||
- | local lastHeight = y%3 | ||
- | layers = math.ceil(y/ | ||
- | local yMult = layers --This is basically a smart y/3 for movement | ||
- | local moveVolume = (area * yMult) --Kept for display percent | ||
- | --Calculating Needed Fuel-- | ||
- | do --Because many local variables unneeded elsewhere | ||
- | local changeYFuel = 2*(y + startDown) | ||
- | local dropOffSupplies = 2*(x + z + y + startDown) --Assumes turtle as far away as possible, and coming back | ||
- | local frequency = math.ceil(((moveVolume/ | ||
- | --max of 15 full stacks because once one item is picked up, slot is " | ||
- | if enderChest then frequency = 0 end --Never goes back to start | ||
- | neededFuel = moveVolume + changeYFuel + (frequency * dropOffSupplies) + ((x + z) * layers) --x + z *layers because turtle has to come back from far corner every layer | ||
- | neededFuel = neededFuel + fuelTable[fuelSafety] --For safety | ||
- | end | ||
- | |||
- | if neededFuel > checkFuelLimit() and doCheckFuel then--Checks for if refueling goes over turtle fuel limit | ||
- | if not (doRefuel or fuelChest) then | ||
- | screen() | ||
- | print(" | ||
- | print(" | ||
- | local _, key = os.pullEvent(" | ||
- | if key == " | ||
- | screen(); print(" | ||
- | elseif key == " | ||
- | doCheckFuel = false | ||
- | elseif key == " | ||
- | --pass | ||
- | else --Not for number two because this is default | ||
- | doRefuel = true | ||
- | end | ||
- | end | ||
- | neededFuel = checkFuelLimit()-checkFuel()-1 | ||
- | end | ||
- | |||
- | |||
- | --Getting Fuel | ||
- | local hasRefueled --This is for oldOreQuarry prompting | ||
- | if doCheckFuel and checkFuel() < neededFuel then | ||
- | neededFuel = math.min(math.floor(neededFuel * fuelMultiplier), | ||
- | hasRefueled = true | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | sleep(2) --So they can read everything. | ||
- | term.clear() | ||
- | local oneFuel, neededFuelItems = 0,0 --Initializing Variables | ||
- | local currSlot = 0 | ||
- | local function output(text, | ||
- | local currX, currY = term.getCursorPos() | ||
- | term.setCursorPos(x, | ||
- | term.clearLine() | ||
- | term.write(text) | ||
- | term.setCursorPos(currX, | ||
- | end | ||
- | local function roundTo(num, | ||
- | if num >= target then return target elseif num < 0 then return 0 else return num end | ||
- | end | ||
- | local function updateScreen() | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | output(" | ||
- | end | ||
- | while checkFuel() < neededFuel do | ||
- | currSlot = currSlot + 1 | ||
- | select(currSlot) | ||
- | if currSlot ~= 1 and not turtle.refuel(0) then --If it's not the first slot, and not fuel, go back to start | ||
- | currSlot = 1; select(currSlot) | ||
- | end | ||
- | updateScreen() | ||
- | while turtle.getItemCount(currSlot) == 0 do | ||
- | sleep(1.5) | ||
- | end | ||
- | repeat --TODO: Probably unnecessary loop, remove later | ||
- | local previous = checkFuel() | ||
- | turtle.refuel(1) | ||
- | oneFuel = checkFuel() - previous | ||
- | updateScreen() | ||
- | until (oneFuel or 0) > 0 --Not an if to prevent errors if fuel taken out prematurely. | ||
- | neededFuelItems = math.ceil((neededFuel - checkFuel()) / oneFuel) | ||
- | turtle.refuel(roundTo(neededFuelItems, | ||
- | if turtle.getItemCount(roundTo(currSlot + 1, inventoryMax)) == 0 then --Resets if no more fuel | ||
- | currSlot = 0 | ||
- | end | ||
- | neededFuelItems = math.ceil((neededFuel - checkFuel()) / oneFuel) --This line is not repeated uselessly, it's for the display function | ||
- | end | ||
- | select(1) | ||
- | end | ||
- | --Ender Chest Obtaining | ||
- | function promptSpecialSlot(specialSlot, | ||
- | local function isInRange(toCheck, | ||
- | while not isInRange(turtle.getItemCount(specialSlots[specialSlot]), | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(" | ||
- | sleep(1) | ||
- | end | ||
- | print(name," | ||
- | end | ||
- | function checkSpecialSlot(specialSlot, | ||
- | if restoreFoundSwitch and turtle.getItemCount(specialSlots[specialSlot]) == 0 then --If the turtle was stopped while dropping off items. | ||
- | select(specialSlots[specialSlot]) | ||
- | turtle.dig() | ||
- | select(1) | ||
- | end | ||
- | promptSpecialSlot(specialSlot, | ||
- | allowedItems[specialSlots[specialSlot]] = 1 | ||
- | sleep(1) | ||
- | end | ||
- | if enderChest then | ||
- | checkSpecialSlot(" | ||
- | end | ||
- | if fuelChest then | ||
- | checkSpecialSlot(" | ||
- | end | ||
- | if lavaBucket then | ||
- | checkSpecialSlot(" | ||
- | select(specialSlots.lavaBucket) | ||
- | if turtle.refuel(1) then --Just in case they actually put in a lava bucket >:( | ||
- | print(" | ||
- | sleep(2) | ||
- | end | ||
- | select(1) | ||
- | end | ||
- | if compareChest then | ||
- | checkSpecialSlot(" | ||
- | end | ||
- | |||
- | --Setting which slots are marked as compare slots | ||
- | if oldOreQuarry then | ||
- | if not restoreFoundSwitch then --We don't want to reset compare blocks every restart | ||
- | local counter = 0 | ||
- | for i=1, inventoryMax do if turtle.getItemCount(i) > 0 and not specialSlots[i] then counter = counter+1 end end --If the slot has items, but isn't enderChest slot if it is enabled | ||
- | |||
- | screen(1,1) | ||
- | print(" | ||
- | if counter == 0 or hasRefueled then --If there are no compare slots, or the turtle has refueled, and probably has fuel in inventory | ||
- | print(" | ||
- | |||
- | print(" | ||
- | repeat until ({os.pullEvent(" | ||
- | else | ||
- | print(" | ||
- | sleep(1) | ||
- | end | ||
- | for i=1, inventoryMax do | ||
- | if turtle.getItemCount(i) > 0 then | ||
- | if not specialSlots[i] then | ||
- | table.insert(compareSlots, | ||
- | allowedItems[i] = 1 --Blacklist is for dropping off items. The number is maximum items allowed in slot when dropping off | ||
- | dumpSlots[i] = true --We also want to ignore all excess of these items, like dirt | ||
- | end | ||
- | end | ||
- | end | ||
- | if extraDropItems then | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(" | ||
- | repeat until ({os.pullEvent(" | ||
- | for i=1, | ||
- | if not dumpSlots[i] and turtle.getItemCount(i) > 0 then --I don't want to modify from above, so I check it hasn't been assigned. | ||
- | dumpSlots[i] = true | ||
- | allowedItems[i] = 1 | ||
- | end | ||
- | end | ||
- | end | ||
- | --This is could go very wrong if this isn't here | ||
- | if # | ||
- | end | ||
- | local counter = 0 | ||
- | for a, b in pairs(compareSlots) do if turtle.getItemCount(b) > 0 then counter = counter + 1 end end | ||
- | if counter == 0 then | ||
- | screen(1,1) | ||
- | print(" | ||
- | if ({os.pullEvent(" | ||
- | end | ||
- | elseif not oreQuarry then --This was screwing up dumpCompareItems | ||
- | dumpCompareItems = false --If not an ore quarry, this should definitely be false | ||
- | if specialSlots.enderChest == 1 then | ||
- | dumpSlots[2] = true | ||
- | else | ||
- | dumpSlots[1] = true | ||
- | end | ||
- | end | ||
- | |||
- | --Rednet Handshake | ||
- | function newMessageID() | ||
- | return math.random(1, | ||
- | end | ||
- | function sendMessage(send, | ||
- | if legacyRednet then | ||
- | if type(message) == " | ||
- | return modem.transmit(send, | ||
- | end | ||
- | return modem.transmit(send , receive, {fingerprint = channels.fingerprint, | ||
- | end | ||
- | if rednetEnabled then | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(" | ||
- | if peripheral.find then | ||
- | modem = peripheral.find(" | ||
- | else | ||
- | modem = peripheral.wrap(" | ||
- | end | ||
- | modem.open(channels.receive) | ||
- | local i = 0 | ||
- | repeat | ||
- | local id = os.startTimer(3) | ||
- | i=i+1 | ||
- | print(" | ||
- | sendMessage(channels.send, | ||
- | local message = {} --Have to initialize as table to prevent index nil | ||
- | repeat | ||
- | local event, idCheck, channel, | ||
- | if locMessage then message = locMessage end | ||
- | if legacyRednet then --For that one guy that uses 1.4.7 | ||
- | message = {message = message} | ||
- | end | ||
- | until (event == " | ||
- | until message.message == channels.confirm | ||
- | connected = true | ||
- | print(" | ||
- | sleep(1.5) | ||
- | end | ||
- | function biometrics(isAtBedrock, | ||
- | if not rednetEnabled then return end --This function won't work if rednet not enabled :P | ||
- | local toSend = { label = os.getComputerLabel() or "No Label", | ||
- | percent = percent, zPos = relzPos, xPos = relxPos, yPos = yPos, | ||
- | layersDone = layersDone, x = x, z = z, layers = layers, | ||
- | openSlots = getNumOpenSlots(), | ||
- | chestFull = chestFull, isAtChest = (xPos == 0 and yPos == 1 and zPos == 1), | ||
- | isGoingToNextLayer = (gotoDest == " | ||
- | fuel = checkFuel(), | ||
- | } | ||
- | if requestQuad and isInPath then --If we are requesting a quadRotor to send help | ||
- | if not gps.locate(gpsTimeout) then | ||
- | print(" | ||
- | sleep(1) | ||
- | else | ||
- | toSend.firstPos = gpsStartPos | ||
- | toSend.secondPos = gpsSecondPos | ||
- | toSend.emergencyLocation = {gps.locate(gpsTimeout)} | ||
- | end | ||
- | end | ||
- | sendMessage(channels.send, | ||
- | id = os.startTimer(0.1) | ||
- | local event, received | ||
- | repeat | ||
- | local locEvent, idCheck, confirm, _, locMessage, distance = os.pullEvent() | ||
- | event, received = locEvent, locMessage or {message = "" | ||
- | if legacyRednet and type(received) == " | ||
- | received = {message = received} | ||
- | end | ||
- | until (event == " | ||
- | if event == " | ||
- | local message = received.message: | ||
- | if message == " | ||
- | count(true) | ||
- | display() | ||
- | error(" | ||
- | end | ||
- | if message == " | ||
- | endingProcedure() | ||
- | error(' | ||
- | end | ||
- | if message == " | ||
- | dropOff() | ||
- | end | ||
- | if message == " | ||
- | print(" | ||
- | statusString = " | ||
- | toSend.status = statusString | ||
- | os.startTimer(3) | ||
- | repeat --The turtle sends out periodic messages, which will clear the receiver' | ||
- | | ||
- | local event, idCheck, confirm, _, message, distance = os.pullEvent() | ||
- | if event == " | ||
- | until (event == " | ||
- | statusString = nil | ||
- | end | ||
- | if message == " | ||
- | print(" | ||
- | emergencyRefuel(true) | ||
- | end | ||
- | |||
- | end | ||
- | --Showing changes to settings | ||
- | screen(1,1) | ||
- | print(" | ||
- | if #changedT == 0 then | ||
- | print(" | ||
- | else | ||
- | for i=1, #changedT do | ||
- | if not changedT[i].hidden then | ||
- | print(changedT[i][1],": | ||
- | end | ||
- | end | ||
- | end | ||
- | print(" | ||
- | |||
- | |||
- | |||
- | ---------------------------------------------------------------- | ||
- | --Define ALL THE FUNCTIONS | ||
- | --Event System Functions | ||
- | function eventSetInsertionPoint(num) | ||
- | eventInsertionPoint = num or 1 | ||
- | end | ||
- | function eventAddAt(pos, | ||
- | return table.insert(events, | ||
- | end | ||
- | function eventAdd(...) --Just a wrapper | ||
- | return eventAddAt(eventInsertionPoint, | ||
- | end | ||
- | function eventGet(pos) | ||
- | return events[tonumber(pos) or #events] | ||
- | end | ||
- | function eventPop(pos) | ||
- | return table.remove(events, | ||
- | end | ||
- | function eventRun(value, | ||
- | local argsList = {...} | ||
- | if type(value) == " | ||
- | if value: | ||
- | value = value .. " | ||
- | for a, b in pairs(argsList) do --Appending arguments | ||
- | local toAppend | ||
- | if type(b) == " | ||
- | elseif type(b) == " | ||
- | else toAppend = tostring(b) end | ||
- | value = value .. (toAppend or " | ||
- | end | ||
- | if value: | ||
- | value = value: | ||
- | end | ||
- | value = value .. " | ||
- | end | ||
- | --print(value) --Debug | ||
- | local func = loadstring(value) | ||
- | setfenv(func, | ||
- | return func() | ||
- | end | ||
- | end | ||
- | function eventClear(pos) | ||
- | if pos then events[pos] = nil else events = {} end | ||
- | end | ||
- | function runAllEvents() | ||
- | while #events > 0 do | ||
- | local toRun = eventGet() | ||
- | --print(toRun[1]) --Debug | ||
- | eventRun(unpack(toRun)) | ||
- | eventPop() | ||
- | end | ||
- | end | ||
- | |||
- | --Display Related Functions | ||
- | function display() --This is just the last screen that displays at the end | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | if rednetEnabled then | ||
- | print("" | ||
- | print(" | ||
- | if legacyRednet then --This was the traditional stopping signal | ||
- | print(" | ||
- | sendMessage(channels.send, | ||
- | end | ||
- | local finalTable = {mined = mined, cobble = totals.cobble, | ||
- | other = totals.other, | ||
- | if preciseTotals then | ||
- | finalTable.preciseTotals = exactTotals --This table doubles as a flag. | ||
- | end | ||
- | sendMessage(channels.send, | ||
- | modem.close(channels.receive) | ||
- | end | ||
- | if doBackup then | ||
- | fs.delete(saveFile) | ||
- | if autoResume then --Getting rid of the original startup files and replacing | ||
- | fs.delete(startupName) | ||
- | if fs.exists(startupRename) then | ||
- | fs.move(startupRename, | ||
- | end | ||
- | end | ||
- | end | ||
- | end | ||
- | function updateDisplay() --Runs in Mine(), display information to the screen in a certain place | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(mined) | ||
- | print(" | ||
- | print(percent.." | ||
- | print(" | ||
- | print(checkFuel()) | ||
- | -- screen(1,1) | ||
- | -- print(" | ||
- | -- print(xPos) | ||
- | -- print(" | ||
- | -- print(relxPos) | ||
- | -- print(" | ||
- | -- print(zPos) | ||
- | -- print(" | ||
- | -- print(yPos) | ||
- | if rednetEnabled then | ||
- | screenLine(1, | ||
- | print(" | ||
- | end | ||
- | end | ||
- | --Utility functions | ||
- | local function pad(str, length, side) | ||
- | toRet = "" | ||
- | if side == " | ||
- | toRet = str | ||
- | end | ||
- | for i=1, length-#str do | ||
- | toRet = toRet.." | ||
- | end | ||
- | if side == " | ||
- | toRet = toRet..str | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | function logMiningRun(textExtension, | ||
- | if not logging then return end | ||
- | local number, name = 0 | ||
- | if not fs.isDir(logFolder) then | ||
- | fs.delete(logFolder) | ||
- | fs.makeDir(logFolder) | ||
- | end | ||
- | repeat | ||
- | number = number + 1 --Number will be at least 2 | ||
- | name = logFolder.."/ | ||
- | until not fs.exists(name) | ||
- | local handle = fs.open(name," | ||
- | local function write(...) | ||
- | for a, b in ipairs({...}) do | ||
- | handle.write(tostring(b)) | ||
- | end | ||
- | handle.write(" | ||
- | end | ||
- | local function boolToText(bool) if bool then return " | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | write(" | ||
- | if startDown > 0 then write(" | ||
- | if exactTotals then | ||
- | write(" | ||
- | for a,b in pairs(exactTotals) do | ||
- | write(pad(a, | ||
- | end | ||
- | end | ||
- | handle.close() | ||
- | end | ||
- | --Inventory related functions | ||
- | function isFull(slots) --Checks if there are more than " | ||
- | slots = slots or inventoryMax | ||
- | local numUsed = 0 | ||
- | sleep(0) | ||
- | for i=1, inventoryMax do | ||
- | if turtle.getItemCount(i) > 0 then numUsed = numUsed + 1 end | ||
- | end | ||
- | if numUsed > slots then | ||
- | return true | ||
- | end | ||
- | return false | ||
- | end | ||
- | function countUsedSlots() --Returns number of slots with items in them, as well as a table of item counts | ||
- | local toRet, toRetTab = 0, {} | ||
- | for i=1, inventoryMax do | ||
- | local a = turtle.getItemCount(i) | ||
- | if a > 0 then toRet = toRet + 1 end | ||
- | table.insert(toRetTab, | ||
- | end | ||
- | return toRet, toRetTab | ||
- | end | ||
- | function getSlotsTable() --Just get the table from above | ||
- | local _, toRet = countUsedSlots() | ||
- | return toRet | ||
- | end | ||
- | function getChangedSlots(tab1, | ||
- | local toRet = {} | ||
- | for i=1, math.min(# | ||
- | diff = math.abs(tab2[i]-tab1[i]) | ||
- | if diff > 0 then | ||
- | table.insert(toRet, | ||
- | end | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | function getFirstChanged(tab1, | ||
- | local a = getChangedSlots(tab1, | ||
- | return (a[1] or {" | ||
- | end | ||
- | |||
- | function getRep(which, | ||
- | for a,b in pairs(list) do | ||
- | if b == which then return a end | ||
- | end | ||
- | return false | ||
- | end | ||
- | function assignTypes(types, | ||
- | types, count = types or {1}, count or 1 --Table of types and current highest type | ||
- | for i=1, inventoryMax do | ||
- | if turtle.getItemCount(i) > 0 and not specialSlots[i] then --Not special slots so we don't count ender chests | ||
- | select(i) | ||
- | for k=1, count do | ||
- | if turtle.compareTo(getRep(k, | ||
- | end | ||
- | if not types[i] then | ||
- | count = count + 1 | ||
- | types[i] = count | ||
- | end | ||
- | if oreQuarry then | ||
- | if blacklist[turtle.getItemDetail().name] then | ||
- | dumpSlots[i] = true | ||
- | else | ||
- | dumpSlots[i] = false | ||
- | end | ||
- | end | ||
- | end | ||
- | end | ||
- | select(1) | ||
- | return types, count | ||
- | end | ||
- | function getTableOfType(which, | ||
- | local toRet = {} | ||
- | for a, b in pairs(list) do | ||
- | if b == which then | ||
- | table.insert(toRet, | ||
- | end | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | |||
- | --This is so the turtle will properly get types, otherwise getRep of a type might not be a dumpSlot, even though it should be. | ||
- | if not restoreFoundSwitch then --We only want this to happen once | ||
- | if oldOreQuarry then --If its not ore quarry, this screws up type assigning | ||
- | initialTypes, | ||
- | else | ||
- | initialTypes, | ||
- | end | ||
- | end | ||
- | |||
- | function count(add) --Done any time inventory dropped and at end, true=add, false=nothing, | ||
- | local mod = -1 | ||
- | if add then mod = 1 end | ||
- | if add == false then mod = 0 end | ||
- | slot = {} --1: Filler 2: Fuel 3:Other --[1] is type, [2] is number | ||
- | for i=1, inventoryMax do | ||
- | slot[i] = {} | ||
- | slot[i][2] = turtle.getItemCount(i) | ||
- | end | ||
- | |||
- | local function iterate(toSet , rawTypes, set) | ||
- | for _, a in pairs(getTableOfType(toSet, | ||
- | slot[a][1] = set --Set official type to " | ||
- | end | ||
- | end | ||
- | |||
- | --This assigns " | ||
- | local rawTypes, numTypes = assignTypes(copyTable(initialTypes), | ||
- | |||
- | for i=1, numTypes do | ||
- | if (select(getRep(i, | ||
- | iterate(i, rawTypes, 2) --This type is fuel | ||
- | elseif dumpSlots[getRep(i, | ||
- | iterate(i, rawTypes, 1) --This type is cobble/ | ||
- | else | ||
- | iterate(i, rawTypes, 3) --This type is other | ||
- | end | ||
- | end | ||
- | |||
- | for i=1, | ||
- | if not specialSlots[i] then --Do nothing for specialSlots! | ||
- | if exactTotals and slot[i][2] > 0 then | ||
- | local data = turtle.getItemDetail(i) | ||
- | exactTotals[data.name] = (exactTotals[data.name] or 0) + (data.count * mod) | ||
- | end | ||
- | if slot[i][1] == 1 then totals.cobble = totals.cobble + (slot[i][2] * mod) | ||
- | elseif slot[i][1] == 2 then totals.fuel = totals.fuel + (slot[i][2] * mod) | ||
- | elseif slot[i][1] == 3 then totals.other = totals.other + (slot[i][2] * mod) end | ||
- | end | ||
- | end | ||
- | |||
- | select(1) | ||
- | end | ||
- | |||
- | --Refuel Functions | ||
- | function emergencyRefuel(forceBasic) | ||
- | local continueEvac = true --This turns false if more fuel is acquired | ||
- | if fuelChest then --This is pretty much the only place that this will be used | ||
- | if not fuelChestPhase then --Since I want to do things with return of enderRefuel, | ||
- | fuelChestPhase = 0 --Global variable will be saved | ||
- | fuelChestProperFacing = facing | ||
- | end | ||
- | if fuelChestPhase == 0 then | ||
- | turnTo(coterminal(fuelChestProperFacing+2)) | ||
- | dig(false) | ||
- | fuelChestPhase = 1 | ||
- | saveProgress() | ||
- | end | ||
- | if fuelChestPhase == 1 then | ||
- | select(specialSlots.fuelChest) | ||
- | turtle.place() | ||
- | fuelChestPhase = 2 | ||
- | saveProgress() | ||
- | end | ||
- | if fuelChestPhase == 2 then | ||
- | if not enderRefuel() then --Returns false if slots are full | ||
- | select(specialSlots.fuelChest) | ||
- | turtle.drop() --Somehow stuff got in here... | ||
- | end | ||
- | fuelChestPhase = 3 | ||
- | saveProgress() | ||
- | end | ||
- | if fuelChestPhase == 3 then | ||
- | select(specialSlots.fuelChest) | ||
- | dig(false) | ||
- | select(1) | ||
- | fuelChestPhase = 4 | ||
- | saveProgress() | ||
- | end | ||
- | if fuelChestPhase == 4 then | ||
- | turnTo(fuelChestProperFacing) | ||
- | fuelChestProperFacing = nil --Getting rid of saved values | ||
- | fuelChestPhase = nil | ||
- | continueEvac = false | ||
- | end | ||
- | elseif quadEnabled then --Ask for a quadRotor | ||
- | screen() | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | biometrics(nil, | ||
- | local timer, counter, counterID, event, id = os.startTimer(quadTimeout), | ||
- | local startInventory = getSlotsTable() | ||
- | repeat | ||
- | if id == counterID then counter = counter + 1; counterID = os.startTimer(1) end | ||
- | screenLine(1, | ||
- | print(" | ||
- | event, id = os.pullEvent() --Waits for a key or fuel or the timer | ||
- | until (event == " | ||
- | if event == " | ||
- | local slot = getFirstChanged(startInventory, | ||
- | select(slot) | ||
- | local initialFuel = checkFuel() | ||
- | midRunRefuel(slot) | ||
- | if checkFuel() > initialFuel then | ||
- | print(" | ||
- | continueEvac = false | ||
- | else | ||
- | print(" | ||
- | print(" | ||
- | end | ||
- | sleep(1) | ||
- | end | ||
- | elseif doRefuel or forceBasic then --Attempt an emergency refueling | ||
- | screen() | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | count(false) --Do not add count, but categorize | ||
- | local fuelSwitch, initialFuel = false, checkFuel() --Fuel switch so we don't go over limit (in emergency...) | ||
- | print(" | ||
- | for i=1, inventoryMax do | ||
- | if fuelSwitch then break end | ||
- | if turtle.getItemCount(i) > 0 and slot[i][1] == 2 then --If there are items and type 2 (fuel) | ||
- | select(i) | ||
- | fuelSwitch = midRunRefuel(i) --See above " | ||
- | end | ||
- | end | ||
- | select(1) --Cleanup | ||
- | print(" | ||
- | if checkFuel() > initialFuel then | ||
- | continueEvac = false | ||
- | print(" | ||
- | else | ||
- | print(" | ||
- | sleep(1.5) --Pause for reading | ||
- | end | ||
- | end | ||
- | return continueEvac | ||
- | end | ||
- | |||
- | function lavaRefuel(suckDir) | ||
- | if checkFuel() + lavaBuffer >= checkFuelLimit() then return false end -- we don't want to constantly over-fuel the turtle. | ||
- | local suckFunc | ||
- | if suckDir == " | ||
- | elseif suckDir == " | ||
- | else suckFunc = turtle.place end | ||
- | | ||
- | select(specialSlots.lavaBucket) | ||
- | if suckFunc() then | ||
- | midRunRefuel(specialSlots.lavaBucket, | ||
- | end | ||
- | select(1) | ||
- | return true | ||
- | end | ||
- | |||
- | --Mining functions | ||
- | function dig(doAdd, mineFunc, inspectFunc, | ||
- | if doAdd == nil then doAdd = true end | ||
- | mineFunc = mineFunc or turtle.dig | ||
- | local function retTab(tab) if type(tab) == " | ||
- | --Mine if not in blacklist. inspectFunc returns success and (table or string) so retTab filters out the string and the extra table prevents errors. | ||
- | local mineFlag = false | ||
- | if oreQuarry and inspectFunc then | ||
- | local worked, data = inspectFunc() | ||
- | if data then | ||
- | mineFlag = not blacklist[data.name] | ||
- | if data.name == chestID then | ||
- | emptyChest(suckDir) | ||
- | end | ||
- | if lavaBucket and data.name == lavaID and data.metadata == lavaMeta then | ||
- | lavaRefuel(suckDir) | ||
- | end | ||
- | end | ||
- | end | ||
- | if not oreQuarry or not inspectFunc or mineFlag then --Mines if not oreQuarry, or if the inspect passed | ||
- | if mineFunc() then | ||
- | if doAdd then | ||
- | mined = mined + 1 | ||
- | end | ||
- | | ||
- | else | ||
- | | ||
- | end | ||
- | end | ||
- | return true --This only runs if oreQuarry but item not in blacklist. true means succeeded in duty, not necessarily dug block | ||
- | end | ||
- | |||
- | function digUp(doAdd, | ||
- | return dig(doAdd, turtle.digUp, | ||
- | end | ||
- | function digDown(doAdd, | ||
- | return dig(doAdd, turtle.digDown, | ||
- | end | ||
- | if inverted then --If inverted, switch the options | ||
- | digUp, digDown = digDown, digUp | ||
- | end | ||
- | |||
- | function smartDig(doDigUp, | ||
- | if inverted then doDigUp, doDigDown = doDigDown, doDigUp end --Switching for invert | ||
- | local blockAbove, blockBelow = doDigUp and turtle.detectUp(), | ||
- | local index = 1 | ||
- | for i=1, # | ||
- | if not (blockAbove or blockBelow) then break end --We don't want to go selecting if there is nothing to dig | ||
- | index = i --To access out of scope | ||
- | select(compareSlots[i]) | ||
- | if blockAbove and turtle.compareUp() then blockAbove = false end | ||
- | if blockBelow and turtle.compareDown() then blockBelow = false end | ||
- | end | ||
- | if compareChest then | ||
- | local flag = false | ||
- | select(specialSlots.compareChest) | ||
- | if turtle.compareUp() then emptyChest(" | ||
- | if turtle.compareDown() then emptyChest(" | ||
- | end | ||
- | table.insert(compareSlots, | ||
- | if blockAbove then dig(true, turtle.digUp) end | ||
- | if blockBelow then dig(true, turtle.digDown) end | ||
- | end | ||
- | |||
- | function relxCalc() | ||
- | if layersDone % 2 == 1 then | ||
- | relzPos = zPos | ||
- | else | ||
- | relzPos = (z-zPos) + 1 | ||
- | end | ||
- | if relzPos % 2 == 1 then | ||
- | relxPos = xPos | ||
- | else | ||
- | relxPos = (x-xPos)+1 | ||
- | end | ||
- | if layersDone % 2 == 0 and z % 2 == 1 then | ||
- | relxPos = (x-relxPos)+1 | ||
- | end | ||
- | end | ||
- | function horizontalMove(movement, | ||
- | if doAdd == nil then doAdd = true end | ||
- | if movement() then | ||
- | if doAdd then | ||
- | moved = moved + 1 | ||
- | end | ||
- | if facing == 0 then | ||
- | xPos = xPos + 1 | ||
- | elseif facing == 1 then | ||
- | zPos = zPos + 1 | ||
- | elseif facing == 2 then | ||
- | xPos = xPos - 1 | ||
- | elseif facing == 3 then | ||
- | zPos = zPos - 1 | ||
- | else | ||
- | error(" | ||
- | end | ||
- | relxCalc() | ||
- | return true | ||
- | end | ||
- | return false | ||
- | end | ||
- | function forward(doAdd) | ||
- | return horizontalMove(turtle.forward, | ||
- | end | ||
- | function back(doAdd) | ||
- | return horizontalMove(turtle.back, | ||
- | end | ||
- | function verticalMove(moveFunc, | ||
- | local count = 0 | ||
- | while not moveFunc() do | ||
- | if not digFunc(true, | ||
- | attackFunc() | ||
- | sleep(0.5) | ||
- | count = count + 1 | ||
- | if count > maxTries and yPos > (startY-7) then bedrock() end | ||
- | end | ||
- | end | ||
- | yPos = yDiff + yPos | ||
- | saveProgress() | ||
- | biometrics() | ||
- | return true | ||
- | end | ||
- | function up() --Uses other function if inverted | ||
- | verticalMove(inverted and turtle.down or turtle.up, -1, digUp, attackUp) --Other functions deal with invert already | ||
- | end | ||
- | function down() | ||
- | verticalMove(inverted and turtle.up or turtle.down, | ||
- | end | ||
- | |||
- | |||
- | function right(num) | ||
- | num = num or 1 | ||
- | for i=1, num do | ||
- | facing = coterminal(facing+1) | ||
- | saveProgress() | ||
- | if not goLeftNotRight then turtle.turnRight() --Normally | ||
- | else turtle.turnLeft() end --Left Quarry | ||
- | end | ||
- | end | ||
- | function left(num) | ||
- | num = num or 1 | ||
- | for i=1, num do | ||
- | facing = coterminal(facing-1) | ||
- | saveProgress() | ||
- | if not goLeftNotRight then turtle.turnLeft() --Normally | ||
- | else turtle.turnRight() end --Left Quarry | ||
- | end | ||
- | end | ||
- | |||
- | function attack(doAdd, | ||
- | doAdd = doAdd or true | ||
- | func = func or turtle.attack | ||
- | if func() then | ||
- | if doAdd then | ||
- | attacked = attacked + 1 | ||
- | end | ||
- | return true | ||
- | end | ||
- | return false | ||
- | end | ||
- | function attackUp(doAdd) | ||
- | if inverted then | ||
- | return attack(doAdd, | ||
- | else | ||
- | return attack(doAdd, | ||
- | end | ||
- | end | ||
- | function attackDown(doAdd) | ||
- | if inverted then | ||
- | return attack(doAdd, | ||
- | else | ||
- | return attack(doAdd, | ||
- | end | ||
- | end | ||
- | |||
- | function detect(func) | ||
- | func = func or turtle.detect | ||
- | return func() | ||
- | end | ||
- | function detectUp(ignoreInvert) | ||
- | if inverted and not ignoreInvert then return detect(turtle.detectDown) | ||
- | else return detect(turtle.detectUp) end | ||
- | end | ||
- | function detectDown(ignoreInvert) | ||
- | if inverted and not ignoreInvert then return detect(turtle.detectUp) | ||
- | else return detect(turtle.detectDown) end | ||
- | end | ||
- | |||
- | |||
- | |||
- | function mine(doDigDown, | ||
- | if doCheckInv == nil then doCheckInv = true end | ||
- | if doDigDown == nil then doDigDown = true end | ||
- | if doDigUp == nil then doDigUp = true end | ||
- | if outOfPath == nil then outOfPath = false end | ||
- | isInPath = (not outOfPath) --For rednet | ||
- | if not outOfPath and (checkFuel() <= xPos + zPos + yPos + 5) then --If the turtle can just barely get back to the start, we need to get it there. We don't want this to activate coming back though... | ||
- | local continueEvac = false --It will be set true unless at start | ||
- | if xPos ~= 0 then | ||
- | continueEvac = emergencyRefuel() --This is a huge list of things to do in an emergency | ||
- | end | ||
- | if continueEvac then | ||
- | eventClear() --Clear any annoying events for evac | ||
- | local currPos = yPos | ||
- | endingProcedure() --End the program | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | end | ||
- | if frontChest and not outOfPath then | ||
- | if turtle.inspect then | ||
- | local check, data = turtle.inspect() | ||
- | if check and data.name == chestID then | ||
- | emptyChest(" | ||
- | end | ||
- | else | ||
- | local flag = false | ||
- | select(specialSlots.compareChest) | ||
- | if turtle.compare() then flag = true end | ||
- | select(1) | ||
- | if flag then | ||
- | emptyChest(" | ||
- | end | ||
- | end | ||
- | end | ||
- | | ||
- | local count = 0 | ||
- | if not outOfPath then dig() end --This speeds up the quarry by a decent amount if there are more mineable blocks than air | ||
- | while not forward(not outOfPath) do | ||
- | sleep(0) --Calls coroutine.yield to prevent errors | ||
- | count = count + 1 | ||
- | if not dig() then | ||
- | attack() | ||
- | end | ||
- | if count > 10 then | ||
- | attack() | ||
- | sleep(0.2) | ||
- | end | ||
- | if count > maxTries then | ||
- | if checkFuel() == 0 then --Don' | ||
- | saveProgress({doCheckFuel = true, doRefuel = true}) --This is emergency because this should never really happen. | ||
- | os.reboot() | ||
- | elseif yPos > (startY-7) and turtle.detect() then --If it is near bedrock | ||
- | bedrock() | ||
- | else --Otherwise just sleep for a bit to avoid sheeps | ||
- | sleep(1) | ||
- | end | ||
- | end | ||
- | end | ||
- | checkSanity() --Not kidding... This is necessary | ||
- | saveProgress(tab) | ||
- | |||
- | if not oldOreQuarry then | ||
- | if doDigUp then--The digging up and down part | ||
- | sleep(0) --Calls coroutine.yield | ||
- | if not digUp(true) and detectUp() then --This is relative: will dig down first on invert | ||
- | if not attackUp() then | ||
- | if yPos > (startY-7) then bedrock() end --Checking for bedrock, but respecting user wishes | ||
- | end | ||
- | end | ||
- | end | ||
- | if doDigDown then | ||
- | | ||
- | end | ||
- | else --If oldQuarry | ||
- | smartDig(doDigUp, | ||
- | end | ||
- | percent = math.ceil(moved/ | ||
- | updateDisplay() | ||
- | if doCheckInv and careAboutResources then | ||
- | if isFull(inventoryMax-keepOpen) then | ||
- | if not ((oreQuarry or oldOreQuarry) and dumpCompareItems) then | ||
- | dropOff() | ||
- | else | ||
- | local currInv = getSlotsTable() | ||
- | drop(nil, false, true) --This also takes care of counting. | ||
- | if # | ||
- | dropOff() | ||
- | end | ||
- | end | ||
- | end | ||
- | end | ||
- | biometrics() | ||
- | end | ||
- | --Insanity Checking | ||
- | function checkSanity() | ||
- | if not isInPath then --I don't really care if its not in the path. | ||
- | return true | ||
- | end | ||
- | if not (facing == 0 or facing == 2) and #events == 0 then --If mining and not facing proper direction and not in a turn | ||
- | turnTo(0) | ||
- | rowCheck = true | ||
- | end | ||
- | if xPos < 0 or xPos > x or zPos < 0 or zPos > z or yPos < 0 then | ||
- | saveProgress() | ||
- | print(" | ||
- | if xPos > x then goto(x, zPos, yPos, 2) end --I could do this with some fancy math, but this is much easier | ||
- | if xPos < 0 then goto(1, zPos, yPos, 0) end | ||
- | if zPos > z then goto(xPos, z, yPos, 3) end | ||
- | if zPos < 0 then goto(xPos, 1, yPos, 1) end | ||
- | relxCalc() --Get relxPos properly | ||
- | eventClear() | ||
- | |||
- | --[[ | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | end | ||
- | |||
- | local function fromBoolean(input) --Like a calculator | ||
- | if input then return 1 end | ||
- | return 0 | ||
- | end | ||
- | local function multBoolean(first, | ||
- | return (fromBoolean(first) * fromBoolean(second)) == 1 | ||
- | end | ||
- | function coterminal(num, | ||
- | limit = limit or 4 --This is for facing | ||
- | return math.abs((limit*fromBoolean(num < 0))-(math.abs(num)%limit)) | ||
- | end | ||
- | if tArgs[" | ||
- | facing = coterminal(facing) --Done to improve support for " | ||
- | if facing == 0 then rowCheck = true elseif facing == 2 then rowCheck = false end --Ditto | ||
- | relxCalc() --Ditto | ||
- | end | ||
- | |||
- | --Direction: | ||
- | function turnTo(num) | ||
- | num = num or facing | ||
- | num = coterminal(num) --Prevent errors | ||
- | local turnRight = true | ||
- | if facing-num == 1 or facing-num == -3 then turnRight = false end --0 - 1 = -3, 1 - 0 = 1, 2 - 1 = 1 | ||
- | while facing ~= num do --The above is used to smartly turn | ||
- | if turnRight then | ||
- | right() | ||
- | else | ||
- | left() | ||
- | end | ||
- | end | ||
- | end | ||
- | function goto(x,z,y, toFace, destination) | ||
- | --Will first go to desired z pos, then x pos, y pos varies | ||
- | x = x or 1; y = y or 1; z = z or 1; toFace = toFace or facing | ||
- | gotoDest = destination or "" | ||
- | statusString = "Going to ".. (destination or " | ||
- | --Possible destinations: | ||
- | if yPos > y then --Will go up first if below position | ||
- | while yPos~=y do up() end | ||
- | end | ||
- | if zPos > z then | ||
- | turnTo(3) | ||
- | elseif zPos < z then | ||
- | turnTo(1) | ||
- | end | ||
- | while zPos ~= z do mine(false, | ||
- | if xPos > x then | ||
- | turnTo(2) | ||
- | elseif xPos < x then | ||
- | turnTo(0) | ||
- | end | ||
- | while xPos ~= x do mine(false, | ||
- | if yPos < y then --Will go down after if above position | ||
- | while yPos~=y do down() end | ||
- | end | ||
- | turnTo(toFace) | ||
- | saveProgress() | ||
- | gotoDest = "" | ||
- | statusString = nil | ||
- | end | ||
- | function getNumOpenSlots() | ||
- | local toRet = 0 | ||
- | for i=1, inventoryMax do | ||
- | if turtle.getItemCount(i) == 0 then | ||
- | toRet = toRet + 1 | ||
- | end | ||
- | end | ||
- | return toRet | ||
- | end | ||
- | function emptyChest(suckDirection) | ||
- | eventAdd(" | ||
- | eventSetInsertionPoint(2) --Because dropOff adds events we want to run first | ||
- | local suckFunc | ||
- | if suckDirection == " | ||
- | suckFunc = turtle.suckUp | ||
- | elseif suckDirection == " | ||
- | suckFunc = turtle.suckDown | ||
- | else | ||
- | suckFunc = turtle.suck | ||
- | end | ||
- | repeat | ||
- | if inventoryMax - countUsedSlots() <= 0 then --If there are no slots open, need to empty | ||
- | dropOff() | ||
- | end | ||
- | until not suckFunc() | ||
- | eventClear() | ||
- | eventSetInsertionPoint() | ||
- | end | ||
- | |||
- | --Ideas: Bring in inventory change-checking functions, count blocks that have been put in, so it will wait until all blocks have been put in. | ||
- | local function waitDrop(slot, | ||
- | allowed = allowed or 0 | ||
- | while turtle.getItemCount(slot) > allowed do --No more half items stuck in slot! | ||
- | local tries = 1 | ||
- | while not whereDrop(turtle.getItemCount(slot)-allowed) do --Drop off only the amount needed | ||
- | screen(1,1) | ||
- | print(" | ||
- | chestFull = true | ||
- | biometrics()--To send that the chest is full | ||
- | tries = tries + 1 | ||
- | sleep(2) | ||
- | end | ||
- | chestFull = false | ||
- | end | ||
- | end | ||
- | |||
- | function midRunRefuel(i, | ||
- | allowed = allowed or allowedItems[i] | ||
- | local numToRefuel = turtle.getItemCount(i)-allowed | ||
- | if checkFuel() >= checkFuelLimit() then return true end --If it doesn' | ||
- | local firstCheck = checkFuel() | ||
- | if numToRefuel > 0 then turtle.refuel(1) | ||
- | else return false end --Bandaid solution: If won't refuel, don't try. | ||
- | local singleFuel | ||
- | if checkFuel() - firstCheck > 0 then singleFuel = checkFuel() - firstCheck else singleFuel = math.huge end --If fuel is 0, we want it to be huge so the below will result in 0 being taken | ||
- | --Refuel | ||
- | turtle.refuel(math.min(numToRefuel-1, | ||
- | if checkFuel() >= checkFuelLimit() then return true end --Do not need any more fuel | ||
- | return false --Turtle can still be fueled | ||
- | end | ||
- | |||
- | function enderRefuel() --Assumes a) An enderchest is in front of it b) It needs fuel | ||
- | local slot | ||
- | for a,b in ipairs(getSlotsTable()) do | ||
- | if b == 0 then slot = a; break end | ||
- | end | ||
- | if not slot then return false end --No room for fueling | ||
- | select(slot) | ||
- | repeat | ||
- | print(" | ||
- | print(" | ||
- | local tries = 0 | ||
- | while not turtle.suck() do | ||
- | sleep(1) | ||
- | statusString = "No Fuel in Ender Chest" | ||
- | biometrics() --Let user know that fuel chest is empty | ||
- | print(statusString," | ||
- | tries = tries + 1 | ||
- | end | ||
- | statusString = nil | ||
- | until midRunRefuel(slot, | ||
- | if not turtle.drop() then turtle.dropDown() end --If cannot put fuel back, just drop it, full fuel chest = user has too much fuel already | ||
- | return true -- :D | ||
- | end | ||
- | |||
- | |||
- | function drop(side, final, compareDump) | ||
- | side = sides[side] or " | ||
- | local dropFunc, detectFunc, dropFacing = turtle.drop, | ||
- | if side == " | ||
- | if side == " | ||
- | if side == " | ||
- | if side == " | ||
- | local properFacing = facing --Capture the proper direction to be facing | ||
- | |||
- | count(true) --Count number of items before drop. True means add. This is before chest detect, because could be final | ||
- | |||
- | while not compareDump and not detectFunc() do | ||
- | if final then return end --If final, we don't need a chest to be placed, but there can be | ||
- | chestFull = true | ||
- | biometrics() --Let the user know there is a problem with chest | ||
- | screen(1,1) --Clear screen | ||
- | print(" | ||
- | sleep(2) | ||
- | end | ||
- | chestFull = false | ||
- | |||
- | local fuelSwitch = false --If doRefuel, this can switch so it won't overfuel | ||
- | for i=1, | ||
- | --if final then allowedItems[i] = 0 end --0 items allowed in all slots if final ----It is already set to 1, so just remove comment if want change | ||
- | if turtle.getItemCount(i) > 0 then --Saves time, stops bugs | ||
- | if slot[i][1] == 1 and dumpCompareItems then turnTo(dropFacing) --Turn around to drop junk, not store it. dumpComapareItems is global config | ||
- | else turnTo(properFacing) --Turn back to proper position... or do nothing if already there | ||
- | end | ||
- | select(i) | ||
- | if slot[i][1] == 2 then --Intelligently refuels to fuel limit | ||
- | if doRefuel and not fuelSwitch then --Not in the conditional because we don't want to waitDrop excess fuel. Not a break so we can drop junk | ||
- | fuelSwitch = midRunRefuel(i) | ||
- | else | ||
- | waitDrop(i, allowedItems[i], | ||
- | end | ||
- | if fuelSwitch then | ||
- | waitDrop(i, allowedItems[i], | ||
- | end | ||
- | elseif not compareDump or (compareDump and slot[i][1] == 1) then --This stops all wanted items from being dropped off in a compareDump | ||
- | waitDrop(i, allowedItems[i], | ||
- | end | ||
- | end | ||
- | end | ||
- | |||
- | if compareDump then | ||
- | for i=2, inventoryMax do | ||
- | if not specialSlots[i] then --We don't want to move buckets and things into earlier slots | ||
- | select(i) | ||
- | for j=1, i-1 do | ||
- | if turtle.getItemCount(i) == 0 then break end | ||
- | turtle.transferTo(j) | ||
- | end | ||
- | end | ||
- | end | ||
- | select(1) | ||
- | end | ||
- | if oldOreQuarry or compareDump then count(nil) end--Subtract the items still there if oreQuarry | ||
- | resetDumpSlots() --So that slots gone aren't counted as dump slots next | ||
- | |||
- | select(1) --For fanciness sake | ||
- | |||
- | end | ||
- | |||
- | function dropOff() --Not local because called in mine() | ||
- | local currX, | ||
- | if careAboutResources then | ||
- | if not enderChest then --Regularly | ||
- | eventAdd(" | ||
- | eventAdd(' | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | else --If using an enderChest | ||
- | if turtle.getItemCount(specialSlots.enderChest) ~= 1 then eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | end | ||
- | runAllEvents() | ||
- | numDropOffs = numDropOffs + 1 --Analytics tracking | ||
- | end | ||
- | return true | ||
- | end | ||
- | function endingProcedure() --Used both at the end and in " | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | runAllEvents() | ||
- | --Output to a chest or sit there | ||
- | if enderChest then | ||
- | if dropSide == " | ||
- | if dropSide == " | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | end | ||
- | eventAdd(" | ||
- | eventAdd(" | ||
- | |||
- | --Display was moved above to be used in bedrock function | ||
- | eventAdd(" | ||
- | --Log current mining run | ||
- | eventAdd(" | ||
- | toQuit = true --I'll use this flag to clean up (legacy) | ||
- | runAllEvents() | ||
- | end | ||
- | function bedrock() | ||
- | foundBedrock = true --Let everyone know | ||
- | if rednetEnabled then biometrics() end | ||
- | if checkFuel() == 0 then error(" | ||
- | local origin = {x = xPos, y = yPos, z = zPos} | ||
- | print(" | ||
- | if turtle.detectUp() and not turtle.digUp() then | ||
- | print(" | ||
- | turnTo(facing+2) | ||
- | repeat | ||
- | if not forward(false) then --Tries to go back out the way it came | ||
- | if not attck() then --Just making sure not mob-blocked | ||
- | if not dig() then --Now we know its bedrock | ||
- | turnTo(facing+1) --Try going a different direction | ||
- | end | ||
- | end | ||
- | end | ||
- | until not turtle.detectUp() or turtle.digUp() --These should be absolute and we don't care about about counting resources here. | ||
- | end | ||
- | up() --Go up two to avoid any bedrock. | ||
- | up() | ||
- | eventClear() --Get rid of any excess events that may be run. Don't want that. | ||
- | endingProcedure() | ||
- | print(" | ||
- | print(origin.x," | ||
- | error("", | ||
- | end | ||
- | |||
- | function endOfRowTurn(startZ, | ||
- | local halfFacing = ((layersDone % 2 == 1) and 1) or 3 | ||
- | local toFace = coterminal(wasFacing + 2) --Opposite side | ||
- | if zPos == startZ then | ||
- | if facing ~= halfFacing then turnTo(halfFacing) end | ||
- | mine(unpack(mineFunctionTable or {})) | ||
- | end | ||
- | if facing ~= toFace then | ||
- | turnTo(toFace) | ||
- | end | ||
- | end | ||
- | |||
- | |||
- | ------------------------------------------------------------------------------------- | ||
- | --Pre-Mining Stuff dealing with session persistence | ||
- | runAllEvents() | ||
- | if toQuit then error("", | ||
- | |||
- | local doDigDown, doDigUp = (lastHeight ~= 1), (lastHeight == 0) --Used in lastHeight | ||
- | if not restoreFoundSwitch then --Regularly | ||
- | --Check if it is a mining turtle | ||
- | if not isMiningTurtle then | ||
- | local a, b = turtle.dig() | ||
- | if a then | ||
- | mined = mined + 1 | ||
- | isMiningTurtle = true | ||
- | elseif b == " | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | end | ||
- | | ||
- | if checkFuel() == 0 then --Some people forget to start their turtles with fuel | ||
- | screen(1,1) | ||
- | print(" | ||
- | print(" | ||
- | emergencyRefuel() | ||
- | if checkFuel() == 0 then | ||
- | print(" | ||
- | print(" | ||
- | print(" | ||
- | error("", | ||
- | end | ||
- | end | ||
- | | ||
- | mine(false, | ||
- | if gpsEnabled and not restoreFoundSwitch then --The initial locate is done in the arguments. This is so I can figure out what quadrant the turtle is in. | ||
- | gpsSecondPos = {gps.locate(gpsTimeout)} --Note: Does not run this if it has already been restarted. | ||
- | end | ||
- | for i = 1, startDown do | ||
- | eventAdd(" | ||
- | end | ||
- | runAllEvents() | ||
- | if flatBedrock then | ||
- | while (detectDown() and digDown(false, | ||
- | down() | ||
- | startDown = startDown + 1 | ||
- | end | ||
- | startDown = startDown - y + 1 | ||
- | for i=1, y-2 do | ||
- | up() --It has hit bedrock, now go back up for proper 3 wide mining | ||
- | end | ||
- | elseif not(y == 1 or y == 2) then | ||
- | down() --Go down to align properly. If y is one or two, it doesn' | ||
- | end | ||
- | else --restore found | ||
- | if not(layersDone == layers and not doDigDown) then digDown() end | ||
- | if not(layersDone == layers and not doDigUp) then digUp() end --Get blocks missed before stopped | ||
- | end | ||
- | --Mining Loops-------------------------------------------------------------------------- | ||
- | select(1) | ||
- | while layersDone <= layers do -------------Height--------- | ||
- | local lastLayer = layersDone == layers --If this is the last layer | ||
- | local secondToLastLayer = (layersDone + 1) == layers --This is a check for going down at the end of a layer. | ||
- | moved = moved + 1 --To account for the first position in row as " | ||
- | if not(layersDone == layers and not doDigDown) then digDown() end --This is because it doesn' | ||
- | if not restoreFoundSwitch and layersDone % 2 == 1 then rowCheck = true end | ||
- | relxCalc() | ||
- | while relzPos <= z do -------------Width---------- | ||
- | while relxPos < x do ------------Length--------- | ||
- | mine(not lastLayer or (doDigDown and lastLayer), not lastLayer or (doDigUp and lastLayer)) --This will be the idiom that I use for the mine function | ||
- | end ---------------Length End------- | ||
- | if relzPos ~= z then --If not on last row of section | ||
- | local func | ||
- | if rowCheck == true then --Switching to next row | ||
- | func = " | ||
- | eventAdd(" | ||
- | runAllEvents() | ||
- | else break | ||
- | end | ||
- | end ---------------Width End-------- | ||
- | if layersDone % 2 == 0 then --Will only go back to start on non-even layers | ||
- | eventAdd(" | ||
- | else | ||
- | eventAdd(" | ||
- | end | ||
- | if not lastLayer then --If there is another layer | ||
- | for i=1, 2+fromBoolean(not(lastHeight~=0 and secondToLastLayer)) do eventAdd(" | ||
- | end | ||
- | eventAdd(" | ||
- | layersDone = layersDone + 1 | ||
- | restoreFoundSwitch = false --This is done so that rowCheck works properly upon restore | ||
- | runAllEvents() | ||
- | end ---------------Height End------- | ||
- | endingProcedure() --This takes care of getting to start, dropping in chest, and displaying ending screen | ||
- | </ | ||
Search Terms: | Search Terms: |