Advertisement
chaos511

botania_control.lua

Feb 19th, 2020
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. -- https://pastebin.com/i217McUC
  2. -- made by chaos511
  3. local outputmode="clock"
  4. local clockTime=15
  5. local outputs = {
  6.     jadedamaranthus = {
  7.         displayname = "Jaded Amaranthus",
  8.         drops = {
  9.             {displayname = "White",id = "Botania:flower",threshold = 64,dmg = 0},
  10.             {displayname = "Orange",id = "Botania:flower",threshold = 64,dmg = 1},
  11.             {displayname = "Magenta",id = "Botania:flower",threshold = 64,dmg = 2},
  12.             {displayname = "Light Blue",id = "Botania:flower",threshold = 64,dmg = 3},
  13.             {displayname = "Yellow",id = "Botania:flower",threshold = 64,dmg = 4},
  14.             {displayname = "Lime",id = "Botania:flower",threshold = 64,dmg = 5},
  15.             {displayname = "Pink",id = "Botania:flower",threshold = 64,dmg = 6},
  16.             {displayname = "Gray",id = "Botania:flower",threshold = 64,dmg = 7},
  17.             {displayname = "Light Gray",id = "Botania:flower",threshold = 64,dmg = 8},
  18.             {displayname = "Cyan",id = "Botania:flower",threshold = 64,dmg = 9},
  19.             {displayname = "Purple",id = "Botania:flower",threshold = 64,dmg = 10},
  20.             {displayname = "Blue",id = "Botania:flower",threshold = 64,dmg = 11},
  21.             {displayname = "Brown",id = "Botania:flower",threshold = 64,dmg = 12},
  22.             {displayname = "Green",id = "Botania:flower",threshold = 64,dmg = 13},
  23.             {displayname = "Red",id = "Botania:flower",threshold = 64,dmg = 14},
  24.             {displayname = "Black",id = "Botania:flower",threshold = 64,dmg = 15},
  25.  
  26.         },
  27.         bundledcablecolor=colors.yellow,
  28.     }
  29. }
  30.  
  31. function getcolor(inboolean)
  32.     if inboolean then
  33.         return colors.green
  34.     else
  35.         return colors.red
  36.     end
  37. end
  38. displayList={{},{}}
  39. displayListIndex=1;
  40. function displayStatus(name,value,color,mon,x,y)
  41.     displayList[displayListIndex]={
  42.         x1=x,
  43.         y1=y,
  44.         color1=colors.white,
  45.         write1=name,
  46.         color2=color,
  47.         write2=value
  48.     }
  49.     displayListIndex=displayListIndex+1
  50. end
  51.  
  52. function updatedisplay(mon)
  53.     for index, data in ipairs(displayList) do
  54.         mon.setCursorPos(data.x1,data.y1)
  55.         mon.setTextColor(data.color1)
  56.         mon.write(data.write1)
  57.         mon.setTextColor(data.color2)
  58.         mon.write(data.write2)
  59.     end
  60.     displayListIndex=1;
  61. end
  62. outputState=false
  63. clockCount=0
  64.  
  65. while true do  
  66.     local me = peripheral.wrap("right")
  67.     local monitor = peripheral.find("monitor")
  68.     spawnerstates={}
  69.     local bcoutput=0
  70.     if me ~= nil then
  71.         line=0
  72.         for spawnername, spawner in pairs(outputs) do
  73.             spawnerstates[spawnername]=false
  74.             line=line+1
  75.             monitor.setTextColor(colors.white)
  76.             for itemindex, data in ipairs(spawner.drops) do
  77.                 itemstack=me.getItemDetail({id =data.id,dmg=data.dmg})
  78.                 if itemstack ~= nil then
  79.                     if itemstack.all().qty < data.threshold then
  80.                         spawnerstates[spawnername]=true
  81.                     end
  82.                    
  83.                 else
  84.                 end            
  85.             end
  86.            
  87.             displayStatus(spawner.displayname..": ",spawnerstates[spawnername],getcolor(spawnerstates[spawnername]),monitor,1,line)
  88.             line=line+1
  89.             for itemindex, data in ipairs(spawner.drops) do
  90.                 itemstack=me.getItemDetail({id =data.id,dmg=data.dmg})
  91.                 if itemstack ~= nil then
  92.                     displayStatus(data.displayname..": ",itemstack.all().qty,getcolor(itemstack.all().qty>=data.threshold),monitor,1,line)
  93.                 else
  94.                     displayStatus(data.displayname.." :",-1,getcolor(false),monitor,1,line)
  95.                 end    
  96.                 line=line+1
  97.             end
  98.             if spawnerstates[spawnername] then
  99.                 bcoutput=bcoutput+spawner.bundledcablecolor
  100.             end
  101.         end
  102.             displayStatus("Time: ",(os.time() * 1000 + 18000)%24000,colors.red,monitor,1,line+1)   
  103.     else
  104.         monitor.clear()
  105.         displayStatus("me interface: ","nil",colors.red,monitor,1,1)   
  106.     end
  107.     if outputmode == "clock"  then
  108.         if clockCount>=clockTime then
  109.             clockCount=0
  110.             if outputState then
  111.                 redstone.setBundledOutput("left",bcoutput)
  112.                 outputState=false
  113.             else
  114.                 redstone.setBundledOutput("left",0)
  115.                 outputState=true
  116.             end
  117.         end
  118.         clockCount=clockCount+1
  119.     end
  120.  
  121.     if outputmode=="continuous" then
  122.         redstone.setBundledOutput("left",bcoutput)
  123.     end
  124.     monitor.clear()
  125.     updatedisplay(monitor)
  126.     sleep(1)
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement