SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --[[ORE COLLECTING MINER V2.6 by BrunoZockt |
| 1 | + | |
| 2 | local SETTINGS_FILE = "pull.settings" | |
| 3 | - | MIT License |
| 3 | + | |
| 4 | local SETTINGS = {"orgname", "reponame", "clobber"}
| |
| 5 | - | Copyright (c) 2018 Bruno Heberle |
| 5 | + | local SETTING_DEFAULTS = {"", "", true}
|
| 6 | ||
| 7 | - | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + | function error(str) |
| 8 | - | of this software and associated documentation files (the "Software"), to deal |
| 8 | + | term.setTextColor(colors.red) |
| 9 | - | in the Software without restriction, including without limitation the rights |
| 9 | + | print(str) |
| 10 | - | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + | term.setTextColor(colors.white) |
| 11 | - | copies of the Software, and to permit persons to whom the Software is |
| 11 | + | |
| 12 | - | furnished to do so, subject to the following conditions: |
| 12 | + | |
| 13 | function newline(win) | |
| 14 | - | The above copyright notice and this permission notice shall be included in all |
| 14 | + | local _,cY = win.getCursorPos() |
| 15 | - | copies or substantial portions of the Software. |
| 15 | + | win.setCursorPos(1, cY+1) |
| 16 | end | |
| 17 | - | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + | |
| 18 | - | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + | function config_init() |
| 19 | - | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + | settings.clear() |
| 20 | - | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + | for i=1,#SETTINGS do |
| 21 | - | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + | settings.set(SETTINGS[i], SETTING_DEFAULTS[i]) |
| 22 | - | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + | |
| 23 | - | SOFTWARE. |
| 23 | + | settings.save(SETTINGS_FILE) |
| 24 | end | |
| 25 | ||
| 26 | - | V1.0 released 22.07.2016 17kb |
| 26 | + | function print_config_item(win, selected, name) |
| 27 | - | V1.1 released 16.08.2016 17kb |
| 27 | + | local val = settings.get(name) |
| 28 | - | V2.0 released 07.10.2017 35kb |
| 28 | + | if selected then |
| 29 | - | V2.1 released 15.12.2017 40kb |
| 29 | + | win.write("> ")
|
| 30 | - | V2.2 released 17.12.2017 42kb |
| 30 | + | |
| 31 | - | V2.3 released 11.02.2018 46kb |
| 31 | + | win.write(" ")
|
| 32 | - | V2.4 released 19.06.2018 57kb |
| 32 | + | |
| 33 | - | V2.5 released 15.07.2018 68kb |
| 33 | + | win.write(name .. ": ") |
| 34 | - | V2.5.1 released 19.08.2018 78kb |
| 34 | + | win.setTextColor(colors.yellow) |
| 35 | - | V2.6 released 16.09.2018 90kb |
| 35 | + | win.write(tostring(val)) |
| 36 | - | This program is a work in progress and |
| 36 | + | win.setTextColor(colors.white) |
| 37 | - | will automatically update itself. |
| 37 | + | newline(win) |
| 38 | - | If you have any problems, questions or |
| 38 | + | |
| 39 | - | suggestions I'd be happy if you wrote |
| 39 | + | |
| 40 | - | an e-mail to [email protected]. |
| 40 | + | function print_config_menu(win, selected) |
| 41 | - | Feel free to use this program whenever |
| 41 | + | win.clear() |
| 42 | - | you want. If you want to use parts of |
| 42 | + | win.setCursorPos(1, 1) |
| 43 | - | my program for developing, do so but |
| 43 | + | win.setTextColor(colors.green) |
| 44 | - | don't say it's yours - a sidenote |
| 44 | + | win.write("up/down to select, space to edit")
|
| 45 | - | e.g. "by BrunoZockt" would be nice :) |
| 45 | + | newline(win) |
| 46 | - | If you want to understand this program |
| 46 | + | win.write("enter to save changes")
|
| 47 | - | I recommend to read the variables first |
| 47 | + | newline(win) |
| 48 | - | and then the rest of the code from the |
| 48 | + | win.setTextColor(colors.white) |
| 49 | - | bottom to the top! Maybe I will add |
| 49 | + | for i=1,#SETTINGS do |
| 50 | - | some comments for better understanding |
| 50 | + | print_config_item(win, selected == i, SETTINGS[i]) |
| 51 | - | soon! The names of my functions and |
| 51 | + | |
| 52 | - | variables may sound strange because |
| 52 | + | |
| 53 | - | some are german and others are not |
| 53 | + | |
| 54 | - | really creative, but I hope you |
| 54 | + | function config_menu() |
| 55 | - | understand it anyways ;) ]]-- |
| 55 | + | local w, h = term.getSize() |
| 56 | local win = window.create(term.current(), 1, 1, w - 2, h - 2) | |
| 57 | - | local HOST_ENV = _ENV or getfenv() |
| 57 | + | selected = 1 |
| 58 | - | local OUR_ENV = {}
|
| 58 | + | local done = false |
| 59 | while not done do | |
| 60 | - | setmetatable(OUR_ENV, {__index = HOST_ENV, OUR_ENV = OUR_ENV})
|
| 60 | + | print_config_menu(win, selected) |
| 61 | - | setfenv(1, OUR_ENV) |
| 61 | + | local event, key, isHeld = os.pullEvent("key")
|
| 62 | if key == keys.up then | |
| 63 | - | -----###-----configurable variables-----###----- |
| 63 | + | selected = (selected - 1) % #SETTINGS |
| 64 | elseif key == keys.down then | |
| 65 | - | settings = {
|
| 65 | + | selected = (selected + 1) % #SETTINGS |
| 66 | - | ["language"] = "en", |
| 66 | + | elseif key == keys.enter then |
| 67 | - | ["tunnelspace"] = 4, |
| 67 | + | done = true |
| 68 | - | ["quantity"] = 10, |
| 68 | + | elseif key == keys.space then |
| 69 | - | ["length"] = 8, |
| 69 | + | newline(win) |
| 70 | - | ["ignor"] = {"minecraft:stone", "minecraft:cobblestone", "minecraft:dirt", "minecraft:lava", "minecraft:flowing_lava", "minecraft:water", "minecraft:flowing_water", "minecraft:torch"},
|
| 70 | + | win.setTextColor(colors.green) |
| 71 | - | ["chestSelect"] = 3, |
| 71 | + | win.write(SETTINGS[selected] .. ": ") |
| 72 | - | ["torches"] = true, |
| 72 | + | local val = read() |
| 73 | - | ["mainTorches"] = true, |
| 73 | + | val = val:gsub("^%s*(.-)%s*$", "%1")
|
| 74 | - | ["lateralTorches"] = 1, |
| 74 | + | settings.set(SETTINGS[selected], val) |
| 75 | - | ["Autofuel"] = true, |
| 75 | + | |
| 76 | - | ["floor"] = true, |
| 76 | + | done = true |
| 77 | - | ["trash"] = false, |
| 77 | + | print("ERROR bad key " .. key)
|
| 78 | - | ["walls"] = false |
| 78 | + | |
| 79 | - | } |
| 79 | + | if selected == 0 then |
| 80 | selected = #SETTINGS | |
| 81 | - | -----###-----constants-----###----- |
| 81 | + | |
| 82 | end | |
| 83 | - | local programName = shell.getRunningProgram() |
| 83 | + | settings.save(SETTINGS_FILE) |
| 84 | - | local label = os.getComputerLabel() or "the turtle" |
| 84 | + | |
| 85 | - | local chestSlot = 16 |
| 85 | + | |
| 86 | - | local fuelLevel = turtle.getFuelLevel() |
| 86 | + | function configure() |
| 87 | - | local w, h = term.getSize() |
| 87 | + | if not settings.load(SETTINGS_FILE) then |
| 88 | - | local kill = false |
| 88 | + | config_init() |
| 89 | - | chestList = {"minecraft:chest", "IronChest:BlockIronChest", "IronChest:BlockIronChest:1", "IronChest:BlockIronChest:2", "IronChest:BlockIronChest:3", "IronChest:BlockIronChest:4", "IronChest:BlockIronChest:5", "IronChest:BlockIronChest:6"}
|
| 89 | + | |
| 90 | - | enderChestList = {"EnderStorage:enderChest", "enderstorage:ender_storage", "ThermalExpansion:Strongbox", "ThermalExpansion:Tesseract"}
|
| 90 | + | config_menu() |
| 91 | - | cardinal = {"North", "West", "South", "East"}
|
| 91 | + | print("goodbye")
|
| 92 | end | |
| 93 | - | -----###-----mining variables-----###----- |
| 93 | + | |
| 94 | function pull(file) | |
| 95 | - | variables = {
|
| 95 | + | local url = "https://raw.githubusercontent.com/" .. settings.get("orgname") .. "/" .. settings.get("reponame") .. "/master/" .. file .. ".lua"
|
| 96 | - | ["searching"] = false, |
| 96 | + | print("Fetching from " .. url)
|
| 97 | - | ["level"] = 0, |
| 97 | + | local dataHandle = http.get(url) |
| 98 | - | ["direction"] = 1, |
| 98 | + | local outHandle = fs.open(file, "w") |
| 99 | - | ["cache"] = {},
|
| 99 | + | outHandle.write(dataHandle.readAll()) |
| 100 | - | ["maxSpace"] = false, |
| 100 | + | outHandle.close() |
| 101 | - | ["setup"] = false, |
| 101 | + | dataHandle.close() |
| 102 | - | ["index"] = 2, |
| 102 | + | print("Wrote " .. file)
|
| 103 | - | ["slots"] = {"_","_","_","_","_","_","_","_","_","_","_","_","_","_","_","_"},
|
| 103 | + | |
| 104 | - | ["torchPositions"] = {},
|
| 104 | + | |
| 105 | - | ["stats"] = {
|
| 105 | + | |
| 106 | - | ["dug"] = 0, |
| 106 | + | if #arg == 1 then |
| 107 | - | ["ores"] = 0, |
| 107 | + | |
| 108 | - | ["time"] = 0, |
| 108 | + | return error("Usage: pull ( name | --config )")
|
| 109 | - | ["moves"] = 0 |
| 109 | + | |
| 110 | - | }, |
| 110 | + | if arg[1] == "--config" then |
| 111 | - | ["TorchDemand"] = 0, |
| 111 | + | configure() |
| 112 | - | ["orientation"] = {},
|
| 112 | + | |
| 113 | - | ["CrosswayAmount"] = 0, |
| 113 | + | pull(arg[1]) |
| 114 | - | ["FuelDemand"] = 0, |
| 114 | + | |
| 115 | - | ["startDay"] = 0, |
| 115 | + | |
| 116 | - | ["startTime"] = 0 |
| 116 | + | |
| 117 | - | } |
| 117 | + |