Skip to content

Instantly share code, notes, and snippets.

@fnuecke
Created November 30, 2014 15:15
Show Gist options
  • Save fnuecke/ca97e87ae06d4bc72999 to your computer and use it in GitHub Desktop.
Save fnuecke/ca97e87ae06d4bc72999 to your computer and use it in GitHub Desktop.
AE utils for OC
local component = require("component")
local controller = component.appeng_blocks_controller
local modem = component.modem
local items = dofile("/me/items.dat")
local config = dofile("/me/level.cfg")
local function sendRequest(color, count)
modem.broadcast(45555, color, count)
end
while true do
for name, settings in pairs(config) do
local data = items[name]
if data then
local have = controller.countOfItemType(data.id, data.damage)
local want = settings.level
if type(want) == "function" then
want = want(have)
else
want = have > want
end
if want then
print("[" .. os.date() .. "] Requesting some " .. name)
sendRequest(settings.color, 3)
end
end
end
os.sleep(10)
end
local component = require("component")
local event = require("event")
local serialization = require("serialization")
local sides = require("sides")
local modem = component.modem
modem.open(45555)
local function pulse(color)
local redstone = component.redstone
redstone.setBundledOutput(sides.bottom, color, 255)
redstone.setBundledOutput(sides.bottom, color, 0)
end
local function processCommand(color, count)
for i = 1, count do
pulse(color)
end
end
local function log(msg)
local f = io.open("/tmp/log.log", "a")
if f then
f:write(tostring(msg).."\n")
f:close()
end
end
while true do
local _, _, remote, _, _, color, count = event.pull("modem_message")
if remote:sub(1, 5) == "a321a" then
local result, reason = pcall(processCommand, color, count)
if not result then
log(reason)
end
end
end
local component = require("component")
local event = require("event")
local shell = require("shell")
local args = shell.parse(...)
local items = dofile("/me/items.dat")
local filtered = {}
for name in pairs(items) do
if string.match(name:lower(), args[1]:lower()) then
table.insert(filtered, name)
end
end
table.sort(filtered)
local _, h = component.gpu.getResolution()
local line = 1
os.sleep(0)
for _, name in ipairs(filtered) do
print(name .. ": id = " .. items[name].id .. ", damage = " .. items[name].damage)
line = line + 1
if line % h == 0 then
event.pull("key")
end
end
local component = require("component")
local event = require("event")
local shell = require("shell")
local me = component.appeng_blocks_controller
local modem = component.modem
local args = shell.parse(...)
local function send()
modem.broadcast(25313, me.freeBytes()/me.totalBytes())
end
local function stop()
if _G.me_timer then
return event.cancel(_G.me_timer)
end
end
local function start()
stop()
_G.me_timer = event.timer(0.9, send, math.huge)
end
if args[1] == "stop" then
if stop() then
print("ME fill state daemon stopped.")
else
print("ME fill state daemon wasn't running.")
end
else
start()
print("ME fill state daemon (re)started.")
print("Run `me-status stop` to stop it")
end
local component = require("component")
local serialization = require("serialization")
local controller = component.appeng_blocks_controller
local items = {}
for _, item in ipairs(controller.getAvailableItems()) do
-- damage, id, name
items[item.name] = {id=item.id, damage=item.damage}
end
local data = serialization.serialize(items)
local f = io.open("/me/items.dat", "w")
f:write("return ")
f:write(data)
f:close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment