Guest User

master.lua

a guest
Jan 9th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local wpp = require("wpp")
  2. local pretty = require("cc.pretty")
  3. local network_name = "network-name"
  4. local remote_pc_id = "8"
  5. wpp.wireless.connect(network_name) -- Starts a loop waiting for wpp rednet messages
  6.  
  7. function getperiph(name)
  8.     return "wpp@"..network_name.."://"..remote_pc_id.."/"..name
  9. end
  10.  
  11. local altar_reader = peripheral.wrap("blockReader_2")
  12. local altar = peripheral.wrap("bloodmagic:altar_0")
  13. local input_barrel = peripheral.wrap("minecraft:barrel_1")
  14. local output_barrel = peripheral.wrap("minecraft:barrel_0")
  15. local lever_reader= peripheral.wrap("blockReader_3")
  16. local switch = peripheral.wrap("redstoneIntegrator_0")
  17. local monitorSide = "top"
  18.  
  19. function getDesiredSlate()
  20.     local slates = { "blank","reinforced","infused","demon","ethereal"}
  21.     local index = lever_reader.getBlockData().State + 1
  22.     if index > 4 then
  23.        index = 1
  24.     end
  25.     return "bloodmagic:"..slates[index].."slate"
  26. end
  27.  
  28. function getAltarData()
  29.     return altar_reader.getBlockData()
  30. end
  31.  
  32. function altarIsFull()
  33.     return getAltarData().bloodAltar.Amount == getAltarData().bloodAltar.capacity
  34. end
  35.  
  36. function pushToAltar()
  37.     input_barrel.pushItems(peripheral.getName(altar),1,1)
  38. end
  39.  
  40. function extractFromAltar()
  41.     local current_item = getAltarData().Items[1].id
  42.     if current_item == getDesiredSlate() then
  43.         altar.pushItems(peripheral.getName(output_barrel),1,1)
  44.     end
  45. end
  46.  
  47. function altarHasItem()
  48.     return #altar.list() > 0
  49. end
  50.  
  51. function systemOn()
  52.     return switch.getInput("right")
  53. end
  54.  
  55. function statusReport()
  56.     local monitor = getperiph(monitorSide)
  57.     local status = systemOn()
  58.     local altar_fill = altarIsFull()
  59.     if status then
  60.        status = "ON"
  61.     else
  62.        status = "OFF"
  63.     end
  64.     if altar_fill then
  65.        altar_fill = "full"
  66.     else
  67.        altar_fill = "not full, waiting for altar to refill ( "..getAltarData().bloodAltar.Amount.." mb )"
  68.     end
  69.     local currentSlate = getDesiredSlate()
  70.     local write = function(text) wpp.peripheral.call(monitor,"write",text) end        
  71.     wpp.peripheral.call(monitor,"clear")
  72.     local phrases = {
  73.         "Blood Altar System",
  74.         "########################################################################",
  75.         "System is : "..status,
  76.         "Currently producing : "..currentSlate,
  77.         "Altar is : "..altar_fill
  78.     }
  79.     for i,text in pairs(phrases) do
  80.         wpp.peripheral.call(monitor,"setCursorPos",1,i)  
  81.         write(text)
  82.     end
  83. end
  84.  
  85. while true do
  86.     if not systemOn() or not altarIsFull() then
  87.         -- simply do nothing
  88.     elseif not altarHasItem() then
  89.         pushToAltar()
  90.     else
  91.         extractFromAltar()
  92.     end
  93.     statusReport()
  94. end
  95.  
  96.  
Add Comment
Please, Sign In to add comment