Last active
December 8, 2021 19:57
-
-
Save Hackerjef/82284a0b00bb4a2d4ef54df3aa388de4 to your computer and use it in GitHub Desktop.
Computercraft script to control some things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("installing") | |
local g_api_url = "https://api.github.com/gists/82284a0b00bb4a2d4ef54df3aa388de4" | |
local g_file = "soulautomation.lua" | |
local file = "startup.lua" | |
local resp = http.get(g_api_url) | |
if resp ~= nil then | |
local sresp = resp.readAll() | |
resp.close() | |
local gdata = textutils.unserialiseJSON(sresp) | |
local gupdate = http.get(gdata["files"][g_file]["raw_url"]) | |
local download = gupdate.readAll() | |
gupdate.close() | |
local file = fs.open(file, "w") | |
file.write(download) | |
file.close() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Init everything") | |
-- config | |
local g_api_url = "https://api.github.com/gists/82284a0b00bb4a2d4ef54df3aa388de4" | |
local g_file = "soulautomation.lua" | |
local p_smeltery = peripheral.wrap("bottom") | |
local p_drain = peripheral.wrap("tconstruct:drain_1") | |
local p_fint = peripheral.wrap("appliedenergistics2:fluid_interface_2") | |
local p_redstone_start = "right" | |
local r_ls = 432 | |
local r_bb = 432 | |
local l_soul_lava = "tconstruct:soul_lava" | |
local l_blazing_blood = "tconstruct:blazing_blood" | |
local l_liquid_soul = "tconstruct:liquid_soul" | |
-- conf end | |
-- update script | |
if (g_api_url ~= nil and g_file ~= nil) then | |
print("Downloading last version") | |
local resp = http.get(g_api_url) | |
if resp ~= nil then | |
local sresp = resp.readAll() | |
resp.close() | |
local gdata = textutils.unserialiseJSON(sresp) | |
local gupdate = http.get(gdata["files"][g_file]["raw_url"]) | |
local new_file = gupdate.readAll() | |
gupdate.close() | |
-- read current file and compare it as a string | |
local current_file = io.open(shell.getRunningProgram(), "rb") | |
local old_file = current_file:read("a") | |
current_file:close() | |
if (old_file ~= new_file) then | |
print("Downloading and restarting application") | |
shell.run( "rm", shell.getRunningProgram() ) | |
local file = fs.open(shell.getRunningProgram(), "w") | |
file.write( new_file ) | |
file.close() | |
shell.run( shell.getRunningProgram() ) | |
error() | |
else | |
print("No update found.. Continue") | |
end | |
else | |
print("Could not download gist.. Continuing") | |
end | |
end | |
-- check if cfg values are nun | |
if (p_drain == nil and p_drain == nil and p_flint == nil) then | |
error("one of the things is null, yeet") | |
end | |
-- vars | |
local allowed_liquid_smelt = { l_soul_lava, l_blazing_blood, l_liquid_soul } | |
-- functions | |
function has (item, name) | |
for v in item do | |
if v == name then | |
return true | |
end | |
end | |
return false | |
end | |
function GetLiquidamount (container, fluid) | |
for k,v in pairs( container.tanks() ) do | |
if (v['name'] == fluid) then | |
return v['amount'] | |
end | |
end | |
return 0 | |
end | |
-- looks ugly due to goto not being available | |
-- Main application loop () | |
print("Starting loop") | |
while true do | |
local next_loop = false | |
local cme_bb = GetLiquidamount(p_fint, l_blazing_blood) | |
local cme_ls = GetLiquidamount(p_fint, l_liquid_soul) | |
local cdrain_bb = GetLiquidamount(p_drain, l_blazing_blood) | |
local cdrain_ls = GetLiquidamount(p_drain, l_liquid_soul) | |
if (redstone.getInput(p_redstone_start) ~= true) then | |
next_loop = true | |
print("Sleeping for 10s because of no redstone sig") | |
sleep(10) | |
end | |
-- Move all soul lava to ME and if we have req blazing and soul wait 3s and redo loop (if we have any other liquid yeet) | |
if (next_loop == false) then | |
if (cdrain_bb >= r_bb and cdrain_ls >= r_ls) then | |
print("Sleeping due to smetlery still making soul lava") | |
sleep(5) | |
next_loop = true | |
end | |
end | |
-- Flush out smeltry | |
if (next_loop == false) then | |
for k,v in pairs( p_drain.tanks() ) do | |
-- -- move liquid if it is soul_lava | |
if v['name'] == l_soul_lava then | |
p_drain.pushFluid(p_fint.getName(), v['amount'], l_soul_lava) | |
end | |
-- move liquid if it is below required amount | |
if (v['name'] == l_blazing_blood and v['amount'] < r_bb) then | |
p_drain.pushFluid(p_fint.getName(), v['amount'], l_blazing_blood) | |
end | |
if (v['name'] == l_liquid_soul and v['amount'] < r_ls) then | |
p_drain.pushFluid(p_fint.getName(), v['amount'], l_liquid_soul) | |
end | |
-- check if liquid is allowed if not just yeet it | |
if (has(allowed_liquid_smelt, v['name']) ~= true) then | |
p_drain.pushFluid(p_fint.getName(), v['amount'], v['name']) | |
end | |
end | |
end | |
-- check if we both have the required liquids in ME | |
if (next_loop == false) then | |
if (r_ls > cme_ls or r_bb > cme_bb) then | |
print("sleeping for 60s, missing required liquids - unless disabled during waiting period") | |
sleep(60) | |
next_loop = true | |
end | |
end | |
-- add liquid ;) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment