Last active
November 26, 2023 05:37
-
-
Save MacChuck/66cab5abcd19fc2dd10e8ebe7bf3c855 to your computer and use it in GitHub Desktop.
Refined Storage ComputerCraft Display
This file contains hidden or 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
mon = peripheral.find("monitor") | |
bridge = peripheral.find("rsBridge") | |
os.startTimer(1) | |
mon.setTextScale(.5) | |
mon.clear() | |
monW,monH = mon.getSize() | |
displayItems = {"iron_ingot","gold_ingot","diamond","quartz","glowstone_dust","ars_nouveau:source_gem"} | |
stockItems = {} | |
stockItems["oak_planks"] = 64 | |
stockItems["stick"] = 32 | |
stockItems["redstone_torch"] = 32 | |
function drawStock() | |
line = 1 | |
for _, item in pairs(displayItems) do | |
itemDetail = bridge.getItem({name=item}) | |
cleanName = itemDetail.displayName:sub(5,-2) -- Trim leading spaces and [] from the display name. | |
if cleanName == "Air" then -- If the item is valid but missing, the peripheral returns Air | |
cleanName = item | |
end | |
mon.setCursorPos(1,line) | |
mon.write(cleanName) | |
mon.setCursorPos(monW/2,line) | |
mon.write(tostring(itemDetail.amount)) | |
line = line + 1 | |
end | |
end | |
function drawCraftables() | |
line = #displayItems+1 | |
for item,count in pairs(stockItems) do | |
itemDetail = bridge.getItem({name=item}) | |
cleanName = itemDetail.displayName:sub(5,-2) -- Trim leading spaces and [] from the display name. | |
if cleanName == "Air" then -- If the item is valid but missing, the peripheral returns Air | |
cleanName = item | |
end | |
if bridge.isItemCraftable({name=item}) then | |
mon.setCursorPos(1,line) | |
mon.write(cleanName) | |
mon.setCursorPos(monW/2,line) | |
mon.write(tostring(itemDetail.amount).." / "..count) | |
if bridge.isItemCrafting({name=item}) then | |
mon.setCursorPos(monW*.75,line) | |
mon.setTextColor(colors.green) | |
mon.write("Crafting") | |
mon.setTextColor(colors.white) | |
end | |
else | |
mon.setCursorPos(1,line) | |
mon.write(cleanName) | |
mon.setCursorPos(monW/2,line) | |
mon.setTextColor(colors.red) | |
mon.write("No Recipe") | |
mon.setTextColor(colors.white) | |
end | |
line = line + 1 | |
end | |
end | |
function craftItem(itemName,qty) | |
if bridge.isItemCrafting({name=itemName}) then --crafting job already going, no need to queue another | |
return | |
else | |
bridge.craftItem({name=itemName,count=qty}) | |
end | |
end | |
function checkStock() | |
for item,count in pairs(stockItems) do | |
itemDetail = bridge.getItem({name=item}) | |
if itemDetail.amount < count/3 then --craft more if at a 3rd of the stock threshold | |
craftItem(item,(count-itemDetail.amount)) | |
end | |
end | |
end | |
while true do | |
local evt,sid,msg,proto = os.pullEvent() | |
if evt == "timer" then | |
mon.clear() | |
drawStock() | |
checkStock() | |
drawCraftables() | |
os.startTimer(60) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment