Skip to content

Instantly share code, notes, and snippets.

@TvL2386
Last active March 4, 2018 17:03
Show Gist options
  • Save TvL2386/41d076b7710547ab8090625c0353e4a1 to your computer and use it in GitHub Desktop.
Save TvL2386/41d076b7710547ab8090625c0353e4a1 to your computer and use it in GitHub Desktop.
keeping botania pool stocked
component = require("component")
sides = require("sides")
colors = require("colors")
rs = component.proxy("66f08be3-347e-4828-9aa4-b7ef47826227")
pool = component.proxy("f4743c6f-128d-4fe7-903f-9450cf82f10a")
pres = component.proxy("f393c3c2-5f9d-4504-b552-f097cf5a5e8d")
dropper = component.proxy("2734b56a-e57f-4485-b731-4bf2e7ba79b4")
sdropper = sides.south -- the side where the dropper is located
-- array containing craftables that I want to keep stocked
stock = {
{ label = "Obsidian", keep_stocked = 128, name = "minecraft:obsidian", damage = 0 },
{ label = "Charcoal", keep_stocked = 128, name = "minecraft:coal", damage = 1 },
{ label = "Oak Wood Planks", keep_stocked = 512, name = "minecraft:planks", damage = 0 },
{ label = "Redstone", keep_stocked = 1024, name = "minecraft:redstone", damage = 0 },
{ label = "Redstone Block", keep_stocked = 32, name = "minecraft:redstone_block", damage = 0 },
{ label = "Glowstone Dust", keep_stocked = 1024, name = "minecraft:glowstone_dust", damage = 0 },
{ label = "Nether Quartz", keep_stocked = 1024, name = "minecraft:quartz", damage = 0 },
{ label = "Comparator", keep_stocked = 6, name = "minecraft:comparator", damage = 0 },
{ label = "Redstone Torch", keep_stocked = 64, name = "minecraft:redstone_torch", damage = 0 },
{ label = "Cable", keep_stocked = 64, name = "refinedstorage:cable", damage = 0 },
{ label = "Crafter", keep_stocked = 4, name = "refinedstorage:crafter", damage = 0 },
{ label = "Exporter", keep_stocked = 4, name = "refinedstorage:exporter", damage = 0 },
{ label = "Importer", keep_stocked = 4, name = "refinedstorage:importer", damage = 0 },
{ label = "Pattern", keep_stocked = 20, name = "refinedstorage:pattern", damage = 0 },
{ label = "Speed Upgrade", keep_stocked = 10, name = "refinedstorage:upgrade", damage = 2 },
{ label = "Osmium Dust", keep_stocked = 32, name = "mekanism:dust", damage = 2 },
{ label = "Enriched Alloy", keep_stocked = 64, name = "mekanism:enrichedalloy", damage = 0 },
{ label = "Basic Control Circuit", keep_stocked = 64, name = "mekanism:controlcircuit", damage = 0 },
{ label = "Draconium Ingot", keep_stocked = 2048, name = "draconicevolution:draconium_ingot", damage = 0 },
}
-- item is a table and must have name and damage keys
function crafting_quantity(item)
local q,n,d,s
for index,job in ipairs(rs.getTasks()) do
q = job["quantity"]
n = job["stack"]["name"]
d = job["stack"]["damage"]
s = job["stack"]["size"]
if n == item["name"] and d == item["damage"] then
return(q*s)
end
end
return 0
end
function keep_stock()
local result, missing, currently_crafting
for _,craftable in ipairs(stock) do
result = rs.getItem(craftable)
if result == nil then result = 0 else result = result["size"] end
missing = craftable["keep_stocked"] - result
currently_crafting = crafting_quantity(craftable)
has_pattern = rs.hasPattern(craftable)
if missing > 0 and currently_crafting == 0 then
if has_pattern then
print("Starting to craft ".. missing .." ".. craftable["label"])
rs.scheduleTask(craftable, missing)
else
print("Cannot craft ".. missing .." ".. craftable["label"] .. " because pattern missing")
end
elseif currently_crafting > 0 then
print("Currently crafting ".. currently_crafting .." ".. craftable["label"])
else
-- print("We have enough ".. craftable["label"])
end
end
end
function drop_charcoal()
local pool_strength = pool.getComparatorInput(sides.top)
local pres_strength = pres.getInput(sides.top)
if pool_strength < 14 and pres_strength == 0 then
print("Signaling dropper")
dropper.setOutput(sdropper, 15)
dropper.setOutput(sdropper, 0)
end
end
while true do
keep_stock()
for i=0,10 do
drop_charcoal()
os.sleep(1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment