Compare commits
17 Commits
af9db97486
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 97d1d509d6 | |||
| 63782a6236 | |||
| 606822f872 | |||
| 3efc247f84 | |||
| 8ee6789265 | |||
| ebf8643e1e | |||
| f925f67aca | |||
| cbfe091437 | |||
| a8e614186a | |||
| 6e37457ecd | |||
| 1ff72434b0 | |||
| aa2b9ee4b8 | |||
| bb0860c8b3 | |||
| 1eb5780814 | |||
| fb1cb95722 | |||
| c351c7419c | |||
| 1995f58b12 |
154
computer/swass/bin/swass.lua
Normal file
154
computer/swass/bin/swass.lua
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
local OUTPUT_NAME = "minecraft:barrel_15"
|
||||||
|
local LESS_COUNT = 20
|
||||||
|
|
||||||
|
local output = peripheral.wrap(OUTPUT_NAME)
|
||||||
|
|
||||||
|
local containers = { peripheral.find("minecraft:barrel") }
|
||||||
|
|
||||||
|
local args = {...}
|
||||||
|
|
||||||
|
function searchInv(inv, targetName)
|
||||||
|
for slot, item in pairs(inv.list()) do
|
||||||
|
if item.name == targetName then
|
||||||
|
return slot
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function findItem(targetName, count)
|
||||||
|
if count == nil then count = 64 end
|
||||||
|
|
||||||
|
for _, container in pairs(containers) do
|
||||||
|
if peripheral.getName(container) ~= OUTPUT_NAME then
|
||||||
|
local slot = searchInv(container ,targetName)
|
||||||
|
if slot ~= nil then
|
||||||
|
local moveCount = output.pullItems(peripheral.getName(container), slot, count)
|
||||||
|
count = count - moveCount
|
||||||
|
print("Took " .. moveCount .. " from " .. peripheral.getName(container))
|
||||||
|
if count <= 0 then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print("Could not find the remaining " .. count)
|
||||||
|
end
|
||||||
|
|
||||||
|
function store()
|
||||||
|
for slot, item in pairs(output.list()) do
|
||||||
|
print("Storing " .. item.name)
|
||||||
|
for _, container in pairs(containers) do
|
||||||
|
if peripheral.getName(container) ~= OUTPUT_NAME then
|
||||||
|
output.pushItems(peripheral.getName(container), slot)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function listStorage()
|
||||||
|
local lineCount = 0
|
||||||
|
|
||||||
|
for _, storage in pairs(containers) do
|
||||||
|
print(peripheral.getName(storage))
|
||||||
|
lineCount = lineCount + 1
|
||||||
|
|
||||||
|
if lineCount >= LESS_COUNT then
|
||||||
|
print("Press ENTER to continue...")
|
||||||
|
read()
|
||||||
|
lineCount = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function listItems()
|
||||||
|
local lineCount = 0
|
||||||
|
|
||||||
|
for _, container in pairs(containers) do
|
||||||
|
|
||||||
|
for _, item in pairs(container.list()) do
|
||||||
|
print(item.name .. " x " .. item.count)
|
||||||
|
lineCount = lineCount + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if lineCount >= LESS_COUNT then
|
||||||
|
print("Press ENTER to continue...")
|
||||||
|
read()
|
||||||
|
lineCount = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function listFull()
|
||||||
|
for _, container in pairs(containers) do
|
||||||
|
print(peripheral.getName(container))
|
||||||
|
print("---------------------------------------------")
|
||||||
|
local lineCount = 0
|
||||||
|
for _, item in pairs(container.list()) do
|
||||||
|
print("\t" .. item.name .. " x " .. item.count)
|
||||||
|
lineCount = lineCount + 1
|
||||||
|
if lineCount >= LESS_COUNT then
|
||||||
|
print("Press ENTER to continue...")
|
||||||
|
read()
|
||||||
|
lineCount = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("Press ENTER to continue...")
|
||||||
|
read()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function list(args)
|
||||||
|
local target = args[2]
|
||||||
|
|
||||||
|
if target == nil then
|
||||||
|
listFull()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local targets = {
|
||||||
|
storage = function()
|
||||||
|
listStorage()
|
||||||
|
end,
|
||||||
|
|
||||||
|
items = function()
|
||||||
|
listItems()
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
targets[target]()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HANDLERS
|
||||||
|
local handlers = {
|
||||||
|
get = function(args)
|
||||||
|
local targetName = args[2]
|
||||||
|
local count = tonumber(args[3])
|
||||||
|
findItem(targetName, count)
|
||||||
|
end,
|
||||||
|
|
||||||
|
store = function(args)
|
||||||
|
store(args)
|
||||||
|
end,
|
||||||
|
|
||||||
|
list = function(args)
|
||||||
|
list(args)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
function argParser(args)
|
||||||
|
local op = args[1]
|
||||||
|
local handler = handlers[op]
|
||||||
|
|
||||||
|
if handler == nil then
|
||||||
|
print("Invalid operation.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
handler(args)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function main()
|
||||||
|
argParser(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
main()
|
||||||
12
computer/swass/packageinfo.ccpt
Normal file
12
computer/swass/packageinfo.ccpt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
name = "SWASS",
|
||||||
|
comment = "Self Whitewashing Advanced Storage System",
|
||||||
|
author = "Hion-V",
|
||||||
|
website = "https://git.subsonics.nl/pootercraft/programs/computer/swass/",
|
||||||
|
newestversion = "1.0",
|
||||||
|
install = {
|
||||||
|
scripturl = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/computer/swass/packageinstall.lua",
|
||||||
|
type = "script",
|
||||||
|
},
|
||||||
|
dependencies = {},
|
||||||
|
}
|
||||||
142
computer/swass/packageinstall.lua
Normal file
142
computer/swass/packageinstall.lua
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
--[[
|
||||||
|
LumberJack Program Installer
|
||||||
|
Author: Hion-V
|
||||||
|
Version: 1.0
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- INSTALL PACKAGE INFO
|
||||||
|
packageName = "SWASS"
|
||||||
|
packageURL = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/computer/swass/bin/swass.lua"
|
||||||
|
packageFilename = "swass"
|
||||||
|
packageBinPath = "/bin/"
|
||||||
|
|
||||||
|
-- Read arguments
|
||||||
|
args = {...}
|
||||||
|
|
||||||
|
-- FILE MANIPULATION FUNCTIONS --
|
||||||
|
--[[ Checks if file exists
|
||||||
|
@param String filepath: Filepath to check
|
||||||
|
@return boolean: Does the file exist?
|
||||||
|
--]]
|
||||||
|
function file_exists(filepath)
|
||||||
|
local f=io.open(filepath,"r")
|
||||||
|
if f~=nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a file in a desired location
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String content: Content to store in file
|
||||||
|
--]]
|
||||||
|
function storeFile(filepath,content)
|
||||||
|
writefile = fs.open(filepath,"w")
|
||||||
|
writefile.write(content)
|
||||||
|
writefile.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a file from a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param String createnew: (Optional) Content to store in new file and return if file does not exist. Can be nil.
|
||||||
|
@return String|boolean content|error: Content of the file; If createnew is nil and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readFile(filepath,createnew)
|
||||||
|
readfile = fs.open(filepath,"r")
|
||||||
|
if readfile == nil then
|
||||||
|
if not (createnew==nil) then
|
||||||
|
storeFile(filepath,createnew)
|
||||||
|
return createnew
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
content = readfile.readAll()
|
||||||
|
readfile.close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a table in a file
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param Table data: Table to store in file
|
||||||
|
--]]
|
||||||
|
function storeData(filepath,data)
|
||||||
|
storeFile(filepath,textutils.serialize(data):gsub("\n",""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a table from a file in a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param boolean createnew: If true, an empty table is stored in new file and returned if file does not exist.
|
||||||
|
@return Table|boolean content|error: Table thats stored in the file; If createnew is false and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readData(filepath,createnew)
|
||||||
|
if createnew then
|
||||||
|
return textutils.unserialize(readFile(filepath,textutils.serialize({}):gsub("\n","")))
|
||||||
|
else
|
||||||
|
return textutils.unserialize(readFile(filepath,nil))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HTTP FETCH FUNCTIONS --
|
||||||
|
--[[ Gets result of HTTP URL
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return Table|boolean result|error: The result of the request; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function gethttpresult(url)
|
||||||
|
if not http.checkURL(url) then
|
||||||
|
print("ERROR: Url '" .. url .. "' is blocked in config. Unable to fetch data.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
result = http.get(url)
|
||||||
|
if result == nil then
|
||||||
|
print("ERROR: Unable to reach '" .. url .. "'")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Download file HTTP URL
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return nil|boolean nil|error: nil; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function downloadfile(filepath,url)
|
||||||
|
result = gethttpresult(url)
|
||||||
|
if result == false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
storeFile(filepath,result.readAll())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MISC HELPER FUNCTIONS --
|
||||||
|
--[[ Checks wether a String starts with another one
|
||||||
|
@param String haystack: String to check wether is starts with another one
|
||||||
|
@param String needle: String to check wether another one starts with it
|
||||||
|
@return boolean result: Wether the firest String starts with the second one
|
||||||
|
]]--
|
||||||
|
function startsWith(haystack,needle)
|
||||||
|
return string.sub(haystack,1,string.len(needle))==needle
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MAIN PROGRAMM --
|
||||||
|
if (args[1]=="install") or (args[1]==nil) then
|
||||||
|
print("[Installer] Installing",packageName)
|
||||||
|
if downloadfile(packageBinPath..packageFilename,packageURL)==false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
print("[Installer] Successfully installed '"..packageName.."'!")
|
||||||
|
elseif args[1]=="update" then
|
||||||
|
print("[Installer] Updating "..packageName.."...")
|
||||||
|
if downloadfile("bin/dig",packageURL)==false then
|
||||||
|
fs.move()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif args[1]=="remove" then
|
||||||
|
print("[Installer] Uninstalling '"..packageName.."'...")
|
||||||
|
fs.delete("/bin/dig")
|
||||||
|
print("[Installer] So long, and thanks for all the fish!")
|
||||||
|
else
|
||||||
|
print("[Installer] Invalid argument: " .. args[1])
|
||||||
|
end
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
name = "dig",
|
|
||||||
comment = "Turtle Tunnel Digging Program",
|
|
||||||
author = "Hion-V",
|
|
||||||
website = "https://git.subsonics.nl/pootercraft/dig",
|
|
||||||
newestversion = "1.0",
|
|
||||||
install = {
|
|
||||||
scripturl = "https://git.subsonics.nl/pootercraft/dig/raw/branch/master/dig.lua",
|
|
||||||
filename = "dig",
|
|
||||||
type = "script",
|
|
||||||
},
|
|
||||||
dependencies = {},
|
|
||||||
}
|
|
||||||
12
turtle/dig/packageinfo.ccpt
Normal file
12
turtle/dig/packageinfo.ccpt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
name = "dig",
|
||||||
|
comment = "Turtle Tunnel Digging Program",
|
||||||
|
author = "Hion-V",
|
||||||
|
website = "https://git.subsonics.nl/pootercraft/programs/turtle/dig/",
|
||||||
|
newestversion = "1.0",
|
||||||
|
install = {
|
||||||
|
scripturl = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/turtle/dig/packageinstall.lua",
|
||||||
|
type = "script",
|
||||||
|
},
|
||||||
|
dependencies = {},
|
||||||
|
}
|
||||||
143
turtle/dig/packageinstall.lua
Normal file
143
turtle/dig/packageinstall.lua
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
--[[
|
||||||
|
Dig Program Installer
|
||||||
|
Author: Hion-V
|
||||||
|
Version: 1.0
|
||||||
|
Lines of Code: 161; Characters: 5541
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- INSTALL PACKAGE INFO
|
||||||
|
packageName = "dig"
|
||||||
|
packageURL = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/turtle/dig/bin/dig"
|
||||||
|
packageBinPath = "/bin/"
|
||||||
|
packageFilename = "dig"
|
||||||
|
|
||||||
|
-- Read arguments
|
||||||
|
args = {...}
|
||||||
|
|
||||||
|
-- FILE MANIPULATION FUNCTIONS --
|
||||||
|
--[[ Checks if file exists
|
||||||
|
@param String filepath: Filepath to check
|
||||||
|
@return boolean: Does the file exist?
|
||||||
|
--]]
|
||||||
|
function file_exists(filepath)
|
||||||
|
local f=io.open(filepath,"r")
|
||||||
|
if f~=nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a file in a desired location
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String content: Content to store in file
|
||||||
|
--]]
|
||||||
|
function storeFile(filepath,content)
|
||||||
|
writefile = fs.open(filepath,"w")
|
||||||
|
writefile.write(content)
|
||||||
|
writefile.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a file from a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param String createnew: (Optional) Content to store in new file and return if file does not exist. Can be nil.
|
||||||
|
@return String|boolean content|error: Content of the file; If createnew is nil and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readFile(filepath,createnew)
|
||||||
|
readfile = fs.open(filepath,"r")
|
||||||
|
if readfile == nil then
|
||||||
|
if not (createnew==nil) then
|
||||||
|
storeFile(filepath,createnew)
|
||||||
|
return createnew
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
content = readfile.readAll()
|
||||||
|
readfile.close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a table in a file
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param Table data: Table to store in file
|
||||||
|
--]]
|
||||||
|
function storeData(filepath,data)
|
||||||
|
storeFile(filepath,textutils.serialize(data):gsub("\n",""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a table from a file in a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param boolean createnew: If true, an empty table is stored in new file and returned if file does not exist.
|
||||||
|
@return Table|boolean content|error: Table thats stored in the file; If createnew is false and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readData(filepath,createnew)
|
||||||
|
if createnew then
|
||||||
|
return textutils.unserialize(readFile(filepath,textutils.serialize({}):gsub("\n","")))
|
||||||
|
else
|
||||||
|
return textutils.unserialize(readFile(filepath,nil))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HTTP FETCH FUNCTIONS --
|
||||||
|
--[[ Gets result of HTTP URL
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return Table|boolean result|error: The result of the request; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function gethttpresult(url)
|
||||||
|
if not http.checkURL(url) then
|
||||||
|
print("ERROR: Url '" .. url .. "' is blocked in config. Unable to fetch data.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
result = http.get(url)
|
||||||
|
if result == nil then
|
||||||
|
print("ERROR: Unable to reach '" .. url .. "'")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Download file HTTP URL
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return nil|boolean nil|error: nil; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function downloadfile(filepath,url)
|
||||||
|
result = gethttpresult(url)
|
||||||
|
if result == false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
storeFile(filepath,result.readAll())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MISC HELPER FUNCTIONS --
|
||||||
|
--[[ Checks wether a String starts with another one
|
||||||
|
@param String haystack: String to check wether is starts with another one
|
||||||
|
@param String needle: String to check wether another one starts with it
|
||||||
|
@return boolean result: Wether the firest String starts with the second one
|
||||||
|
]]--
|
||||||
|
function startsWith(haystack,needle)
|
||||||
|
return string.sub(haystack,1,string.len(needle))==needle
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MAIN PROGRAMM --
|
||||||
|
if (args[1]=="install") or (args[1]==nil) then
|
||||||
|
print("[Installer] Installing",packageName)
|
||||||
|
if downloadfile(packageBinPath..packageFilename,packageURL)==false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
print("[Installer] Successfully installed '"..packageName.."'!")
|
||||||
|
elseif args[1]=="update" then
|
||||||
|
print("[Installer] Updating "..packageName.."...")
|
||||||
|
if downloadfile("bin/dig",packageURL)==false then
|
||||||
|
fs.move()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif args[1]=="remove" then
|
||||||
|
print("[Installer] Uninstalling '"..packageName.."'...")
|
||||||
|
fs.delete("/bin/dig")
|
||||||
|
print("[Installer] So long, and thanks for all the fish!")
|
||||||
|
else
|
||||||
|
print("[Installer] Invalid argument: " .. args[1])
|
||||||
|
end
|
||||||
116
turtle/lumberjack/bin/lumberjack
Normal file
116
turtle/lumberjack/bin/lumberjack
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
starttime = os.epoch("local")
|
||||||
|
|
||||||
|
function printf(data)
|
||||||
|
print(textutils.serialize(data))
|
||||||
|
end
|
||||||
|
|
||||||
|
function step()
|
||||||
|
turtle.digUp()
|
||||||
|
turtle.up()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.turnRight()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.turnRight()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.turnRight()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.turnRight()
|
||||||
|
end
|
||||||
|
|
||||||
|
function chop()
|
||||||
|
turtle.dig()
|
||||||
|
turtle.forward()
|
||||||
|
while turtle.detectUp() do
|
||||||
|
step()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function descend()
|
||||||
|
while not turtle.detectDown() do
|
||||||
|
turtle.down()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function takeItemOutOfChestSlot(chestSlot,turtleSlot,chestDir)
|
||||||
|
local SLOT_TURTLE_EMPTY_CHEST = 16
|
||||||
|
local chest = peripheral.wrap(chestDir)
|
||||||
|
turtle.select(SLOT_TURTLE_EMPTY_CHEST)
|
||||||
|
turtle.placeUp()
|
||||||
|
sleep(.2)
|
||||||
|
local topchest = peripheral.wrap("top");
|
||||||
|
chest.pushItems(peripheral.getName(topchest),chestSlot)
|
||||||
|
turtle.select(turtleSlot)
|
||||||
|
turtle.suckUp()
|
||||||
|
turtle.select(SLOT_TURTLE_EMPTY_CHEST)
|
||||||
|
turtle.digUp()
|
||||||
|
turtle.select(turtleSlot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function dumpItems()
|
||||||
|
turtle.turnLeft();turtle.turnLeft()
|
||||||
|
for i=1,15 do
|
||||||
|
turtle.select(i)
|
||||||
|
turtle.drop()
|
||||||
|
end
|
||||||
|
turtle.turnLeft();turtle.turnLeft()
|
||||||
|
end
|
||||||
|
|
||||||
|
function replant()
|
||||||
|
local chestDir = "back"
|
||||||
|
local chest = peripheral.wrap(chestDir)
|
||||||
|
local itemlist = chest.list()
|
||||||
|
local saplingIndex = 0
|
||||||
|
for _ in pairs(itemlist) do
|
||||||
|
print(textutils.serialise(_))
|
||||||
|
if itemlist[_].name == "minecraft:oak_sapling" then
|
||||||
|
saplingIndex = _
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if saplingIndex > 0 then
|
||||||
|
-- peripheral.call(chest, "pullitems", )
|
||||||
|
printf(saplingIndex)
|
||||||
|
takeItemOutOfChestSlot(saplingIndex,15,"back")
|
||||||
|
end
|
||||||
|
turtle.select(15)
|
||||||
|
turtle.place()
|
||||||
|
turtle.turnLeft();turtle.turnLeft()
|
||||||
|
turtle.drop()
|
||||||
|
turtle.turnLeft();turtle.turnLeft()
|
||||||
|
turtle.select(1)
|
||||||
|
-- peripheral.getMethods()
|
||||||
|
end
|
||||||
|
|
||||||
|
function chestTest(chestSlot)
|
||||||
|
local chest = peripheral.wrap("back");
|
||||||
|
turtle.select(17)
|
||||||
|
turtle.placeUp()
|
||||||
|
local topchest = peripheral.wrap("top");
|
||||||
|
chest.pushItems(peripheral.getName(topchest),chestSlot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function waitForTree()
|
||||||
|
while true do
|
||||||
|
turtle.suck()
|
||||||
|
has_block, data = turtle.inspect()
|
||||||
|
if has_block then
|
||||||
|
if(data) then
|
||||||
|
if data.tags["minecraft:mineable/axe"] == true then
|
||||||
|
print((os.epoch("local")-starttime)/1000,"choppable")
|
||||||
|
if(data.name ~= "minecraft:oak_sapling") then
|
||||||
|
chop()
|
||||||
|
descend()
|
||||||
|
turtle.back()
|
||||||
|
dumpItems()
|
||||||
|
replant()
|
||||||
|
end
|
||||||
|
print(data.name)
|
||||||
|
else
|
||||||
|
print((os.epoch("local")-starttime)/1000,"not choppable")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sleep(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
waitForTree()
|
||||||
12
turtle/lumberjack/packageinfo.ccpt
Normal file
12
turtle/lumberjack/packageinfo.ccpt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
name = "LumberJack",
|
||||||
|
comment = "Turtle Tree ChippyChoppy Program",
|
||||||
|
author = "Hion-V",
|
||||||
|
website = "https://git.subsonics.nl/pootercraft/programs/turtle/lumberjack/",
|
||||||
|
newestversion = "1.0",
|
||||||
|
install = {
|
||||||
|
scripturl = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/turtle/lumberjack/packageinstall.lua",
|
||||||
|
type = "script",
|
||||||
|
},
|
||||||
|
dependencies = {},
|
||||||
|
}
|
||||||
143
turtle/lumberjack/packageinstall.lua
Normal file
143
turtle/lumberjack/packageinstall.lua
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
--[[
|
||||||
|
LumberJack Program Installer
|
||||||
|
Author: Hion-V
|
||||||
|
Version: 1.0
|
||||||
|
Lines of Code: 161; Characters: 5541
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- INSTALL PACKAGE INFO
|
||||||
|
packageName = "LumberJack"
|
||||||
|
packageURL = "https://git.subsonics.nl/pootercraft/programs/raw/branch/master/turtle/lumberjack/bin/lumberjack"
|
||||||
|
packageBinPath = "/bin/"
|
||||||
|
packageFilename = "lumberjack"
|
||||||
|
|
||||||
|
-- Read arguments
|
||||||
|
args = {...}
|
||||||
|
|
||||||
|
-- FILE MANIPULATION FUNCTIONS --
|
||||||
|
--[[ Checks if file exists
|
||||||
|
@param String filepath: Filepath to check
|
||||||
|
@return boolean: Does the file exist?
|
||||||
|
--]]
|
||||||
|
function file_exists(filepath)
|
||||||
|
local f=io.open(filepath,"r")
|
||||||
|
if f~=nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a file in a desired location
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String content: Content to store in file
|
||||||
|
--]]
|
||||||
|
function storeFile(filepath,content)
|
||||||
|
writefile = fs.open(filepath,"w")
|
||||||
|
writefile.write(content)
|
||||||
|
writefile.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a file from a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param String createnew: (Optional) Content to store in new file and return if file does not exist. Can be nil.
|
||||||
|
@return String|boolean content|error: Content of the file; If createnew is nil and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readFile(filepath,createnew)
|
||||||
|
readfile = fs.open(filepath,"r")
|
||||||
|
if readfile == nil then
|
||||||
|
if not (createnew==nil) then
|
||||||
|
storeFile(filepath,createnew)
|
||||||
|
return createnew
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
content = readfile.readAll()
|
||||||
|
readfile.close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Stores a table in a file
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param Table data: Table to store in file
|
||||||
|
--]]
|
||||||
|
function storeData(filepath,data)
|
||||||
|
storeFile(filepath,textutils.serialize(data):gsub("\n",""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Reads a table from a file in a desired location
|
||||||
|
@param String filepath: Filepath to the file to read
|
||||||
|
@param boolean createnew: If true, an empty table is stored in new file and returned if file does not exist.
|
||||||
|
@return Table|boolean content|error: Table thats stored in the file; If createnew is false and file doesn't exist boolean false is returned
|
||||||
|
--]]
|
||||||
|
function readData(filepath,createnew)
|
||||||
|
if createnew then
|
||||||
|
return textutils.unserialize(readFile(filepath,textutils.serialize({}):gsub("\n","")))
|
||||||
|
else
|
||||||
|
return textutils.unserialize(readFile(filepath,nil))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HTTP FETCH FUNCTIONS --
|
||||||
|
--[[ Gets result of HTTP URL
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return Table|boolean result|error: The result of the request; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function gethttpresult(url)
|
||||||
|
if not http.checkURL(url) then
|
||||||
|
print("ERROR: Url '" .. url .. "' is blocked in config. Unable to fetch data.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
result = http.get(url)
|
||||||
|
if result == nil then
|
||||||
|
print("ERROR: Unable to reach '" .. url .. "'")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ Download file HTTP URL
|
||||||
|
@param String filepath: Filepath where to create file (if file already exists, it gets overwritten)
|
||||||
|
@param String url: The desired URL
|
||||||
|
@return nil|boolean nil|error: nil; If the URL is not reachable, an error is printed in the terminal and boolean false is returned
|
||||||
|
--]]
|
||||||
|
function downloadfile(filepath,url)
|
||||||
|
result = gethttpresult(url)
|
||||||
|
if result == false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
storeFile(filepath,result.readAll())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MISC HELPER FUNCTIONS --
|
||||||
|
--[[ Checks wether a String starts with another one
|
||||||
|
@param String haystack: String to check wether is starts with another one
|
||||||
|
@param String needle: String to check wether another one starts with it
|
||||||
|
@return boolean result: Wether the firest String starts with the second one
|
||||||
|
]]--
|
||||||
|
function startsWith(haystack,needle)
|
||||||
|
return string.sub(haystack,1,string.len(needle))==needle
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MAIN PROGRAMM --
|
||||||
|
if (args[1]=="install") or (args[1]==nil) then
|
||||||
|
print("[Installer] Installing",packageName)
|
||||||
|
if downloadfile(packageBinPath..packageFilename,packageURL)==false then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
print("[Installer] Successfully installed '"..packageName.."'!")
|
||||||
|
elseif args[1]=="update" then
|
||||||
|
print("[Installer] Updating "..packageName.."...")
|
||||||
|
if downloadfile("bin/dig",packageURL)==false then
|
||||||
|
fs.move()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif args[1]=="remove" then
|
||||||
|
print("[Installer] Uninstalling '"..packageName.."'...")
|
||||||
|
fs.delete("/bin/dig")
|
||||||
|
print("[Installer] So long, and thanks for all the fish!")
|
||||||
|
else
|
||||||
|
print("[Installer] Invalid argument: " .. args[1])
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user