KaychenHH

ATM9_Farmcon

Feb 10th, 2025 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.55 KB | Gaming | 0 0
  1.  
  2. --Farmcontrol V5.01
  3. --written in 07/2021 by Kay Michaelsen
  4. --updated in 01/2025
  5. --
  6. --vardef
  7. --
  8. monitor1 = peripheral.wrap("monitor_1")
  9. monitor2 = peripheral.wrap("monitor_4")
  10. --monitor3 = peripheral.wrap("monitor_7")
  11. --monitor4 = peripheral.wrap("monitor_56")
  12. rss = peripheral.wrap("meBridge_0")
  13. --
  14. obergrenze = 30000
  15. aSeeds = 0
  16. aPro = 0
  17. myst = "mysticalagriculture:"
  18. imm = "immersiveengineering:"
  19. automat = true
  20. dPage = 1
  21. dMax = 0
  22.  
  23. seeds = {}
  24. seeds[1] = myst.."inferium_seeds"
  25. seeds[2] = myst.."osmium_seeds"
  26. seeds[3] = myst.."uranium_seeds"
  27. seeds[4] = myst.."nether_star_seeds"
  28. seeds[5] = myst.."nether_quartz_seeds"
  29. seeds[6] = myst.."lead_seeds"
  30. seeds[7] = myst.."glowstone_seeds"
  31. seeds[8] = myst.."enderman_seeds"
  32. seeds[9] = myst.."emerald_seeds"
  33. seeds[10] = myst.."diamond_seeds"
  34. seeds[11] = myst.."redstone_seeds"
  35. seeds[12] = myst.."copper_seeds"
  36. seeds[13] = myst.."wither_skeleton_seeds"
  37. seeds[14] = myst.."netherite_seeds"
  38. seeds[15] = myst.."lapis_lazuli_seeds"
  39. seeds[16] = myst.."ghast_seeds"
  40. seeds[17] = myst.."certus_quartz_seeds"
  41. seeds[18] = myst.."gold_seeds"
  42. seeds[19] = myst.."blaze_seeds"
  43. seeds[20] = myst.."platinum_seeds"
  44. seeds[21] = myst.."dye_seeds"
  45. seeds[22] = myst.."cobalt_seeds"
  46. seeds[23] = myst.."creeper_seeds"
  47. seeds[24] = myst.."nature_seeds"
  48. seeds[25] = imm.."seeds"
  49. seeds[26] = myst.."coal_seeds"
  50. seeds[27] = myst.."chicken_seeds"
  51. seeds[28] = myst.."iron_seeds"
  52. seeds[29] = myst.."silver_seeds"
  53. seeds[30] = myst.."dirt_seeds"
  54. seeds[31] = myst.."honey_seeds"
  55. seeds[32] = myst.."rabbit_seeds"
  56. seeds[33] = myst.."allthemodium_seeds"
  57. seeds[34] = myst.."vibranium_seeds"
  58. seeds[35] = myst.."unobtainium_seeds"
  59.  
  60. aSeeds = 35
  61.  
  62. pName = {}
  63. pDN = {}
  64. pLine = {}
  65. pStat = {}
  66. pByte = {}
  67. pFound = {}
  68. pStored = {}
  69. pSide = {}
  70. pMax = {}
  71. aPro = 22
  72. dMax = math.floor(aPro / 18) +1
  73.  
  74. for zahl = 1, aPro do
  75.     pMax[zahl] = obergrenze
  76. end
  77. for lauf = 1,14 do
  78.     pSide[lauf] = 1
  79. end
  80. for lauf = 1, aPro do
  81.     pStored[lauf] = 0
  82. end
  83.  
  84.  
  85. pName[1] = "minecraft:glowstone_dust"
  86. pDN[1] = "GlowStone"
  87. pLine[1] = "green"
  88. pStat[1] = false
  89. pByte[1] = colors.green
  90. pSide[1] = 1
  91. pMax[1] = 100000
  92.  
  93. pName[2] = "minecraft:white_wool"
  94. pDN[2] = "White Wool"
  95. pLine[2] = "brown"
  96. pStat[2] = false
  97. pByte[2] = colors.brown
  98. pSide[2] = 1
  99. pMax[2] = 50000
  100.  
  101. pName[3] = "minecraft:iron_ingot"
  102. pDN[3] = "Iron"
  103. pLine[3] = "blue"
  104. pStat[3] = false
  105. pByte[3] = colors.blue
  106. pSide[3] = 1
  107. pMax[3] = 100000
  108.  
  109. pName[4] = myst.."inferium_essence"
  110. pDN[4] = "Inferium"
  111. pLine[4] = "purple"
  112. pStat[4] = true
  113. pByte[4] = colors.purple
  114. pSide[4] = 1
  115.  
  116. pName[5] = "minecraft:nether_quartz_crystal"
  117. pDN[5] = "Neth.Quartz"
  118. pLine[5] = "cyan"
  119. pStat[5] = false
  120. pByte[5] = colors.cyan
  121. pSide[5] = 1
  122. pMax[5] = 100000
  123.  
  124. pName[6] = "minecraft:redstone"
  125. pDN[6] = "Redstone"
  126. pLine[6] = "lightGray"
  127. pStat[6] = false
  128. pByte[6] = colors.lightGray
  129. pSide[6] = 1
  130.  
  131. pName[7] = "ae2:certus_quartz_crystal"
  132. pDN[7] = "Certus"
  133. pLine[7] = "gray"
  134. pStat[7] = true
  135. pByte[7] = colors.gray
  136. pSide[7] = 1
  137.  
  138. pName[8] = "minecraft:coal"
  139. pDN[8] = "Coal"
  140. pLine[8] = "pink"
  141. pStat[8] = true
  142. pByte[8] = colors.pink
  143. pSide[8] = 1
  144.  
  145. pName[9] ="minecraft:blaze_rod"
  146. pDN[9] = "Blaze Rod"
  147. pLine[9] = "lime"
  148. pStat[9] = false
  149. pByte[9] = colors.lime
  150. pSide[9] = 1
  151.  
  152. pName[10] = "minecraft:gold_ingot"
  153. pDN[10] = "Gold"
  154. pLine[10] = "lightBlue"
  155. pStat[10] = false
  156. pByte[10] = colors.lightBlue
  157. pSide[10] = 1
  158.  
  159. pName[11] = "minecraft:Bone_meal"
  160. pDN[11] = "Bone meal"
  161. pLine[11] = "orange"
  162. pStat[11] = false
  163. pByte[11] = colors.orange
  164. pSide[11] = 1
  165.  
  166. pName[12] = "minecraft:ender_pearl"
  167. pDN[12] = "Ender Pearl"
  168. pLine[12] = "white"
  169. pStat[12] = false
  170. pByte[12] = colors.white
  171. pSide[12] = 1
  172.  
  173. pName[13] = "allthemodium:vibranium_ingot"
  174. pDN[13] = "Vibranium"
  175. pLine[13] = "green"
  176. pStat[13] = true
  177. pByte[13] = colors.green
  178. pSide[13] = 2
  179.  
  180. pName[14] = "minecraft:ghast_tear"
  181. pDN[14] = "Ghast Tear"
  182. pLine[14] = "black"
  183. pStat[14] = true
  184. pByte[14] = colors.black
  185. pMax[14] = 10000
  186. pSide[14] = 1
  187.  
  188. pName[15] = "allthemodium:unobtanium_ingot"
  189. pDN[15] = "Unobtanium"
  190. pLine[15] = "brown"
  191. pStat[15] = true
  192. pByte[15] = colors.brown
  193. pSide[15] = 2
  194. pMax[15] = 10000
  195.  
  196. pName[16] = "minecraft:netherite_ingot"
  197. pDN[16] = "Netherite"
  198. pLine[16] = "purple"
  199. pStat[16] = true
  200. pByte[16] = colors.purple
  201. pSide[16] = 2
  202. pMax[16] = 10000
  203.  
  204. pName[17] = "minecraft:enderium_ingot"
  205. pDN[17] = "Enderium"
  206. pLine[17] = "cyan"
  207. pStat[17] = true
  208. pByte[17] = colors.cyan
  209. pSide[17] = 2
  210. pMax[17] = 30000
  211.  
  212. pName[18] = "minecraft:nether_star"
  213. pDN[18] = "Nether Star"
  214. pLine[18] = "lightGray"
  215. pStat[18] = true
  216. pByte[18] = colors.lightGray
  217. pSide[18] = 2
  218. pMax[18] = 20000
  219.  
  220. pName[19] = "allthemodium:allthemodium_ingot"
  221. pDN[19] = "Allthemodium"
  222. pLine[19] = "gray"
  223. pStat[19] = true
  224. pByte[19] = colors.gray
  225. pSide[19] = 2
  226. pMax[19] = 20000
  227.  
  228. pName[20] = "minecraft:diamond"
  229. pDN[20] = "Diamond"
  230. pLine[20] = "pink"
  231. pStat[20] = true
  232. pByte[20] = colors.pink
  233. pSide[20] = 2
  234. pMax[20] = 10000
  235.  
  236. pName[21] = "minecraft:emerald"
  237. pDN[21] = "Emerald"
  238. pLine[21] = "lime"
  239. pStat[21] = true
  240. pByte[21] = colors.lime
  241. pSide[21] = 2
  242. pMax[21] = 30000
  243.  
  244. pName[22] = "minecraft:obsidian"
  245. pDN[22] = "Obsidian"
  246. pLine[22] = "yellow"
  247. pStat[22] = true
  248. pByte[22] = colors.yellow
  249. pSide[22] = 2
  250. pMax[22] = 30000
  251.  
  252. pName[23] = "minecraft:rabbit"
  253. pDN[23] = "Raw Rabbit"
  254. pLine[23] = "magenta"
  255. pStat[23] = true
  256. pByte[23] = colors.magenta
  257. pSide[23] = 2
  258. pMax[23] = 30000
  259.  
  260. pName[24] = "minecraft:honeycomb"
  261. pDN[24] = "Honeycomb"
  262. pLine[24] = "green"
  263. pStat[24] = true
  264. pByte[24] = colors.green
  265. pSide[24] = 2
  266. pMax[24] = 30000
  267.  
  268. pName[25] = "mysticalagriculture:nature_essence"
  269. pDN[25] = "Nature-Ess."
  270. pLine[25] = "white"
  271. pStat[25] = true
  272. pByte[25] = colors.white
  273. pSide[25] = 2
  274. pMax[25] = 50000
  275.  
  276. pName[26] = imm.."hemp_fiber"
  277. pDN[26] = "Hemp-Fiber"
  278. pLine[26] = "lime"
  279. pStat[26] = true
  280. pByte[26] = colors.lime
  281. pSide[26] = 2
  282. pMax[26] = 10000
  283.  
  284. pName[27] = "minecraft:coal"
  285. pDN[27] = "Coal"
  286. pLine[27] = "pink"
  287. pStat[27] = true
  288. pByte[27] = colors.pink
  289. pSide[27] = 2
  290. pMax[27] = 30000
  291.  
  292. pName[28] = "minecraft:chicken"
  293. pDN[28] = "Raw Chicken"
  294. pLine[28] = "brown"
  295. pStat[28] = true
  296. pByte[28] = colors.brown
  297. pSide[28] = 2
  298. pMax[28] = 2000
  299.  
  300. pName[29] = "minecraft:iron_ingot"
  301. pDN[29] = "Iron"
  302. pLine[29] = "gray"
  303. pStat[29] = true
  304. pByte[29] = colors.gray
  305. pSide[29] = 2
  306. pMax[29] = 30000
  307.  
  308. pName[30] = "alltheores:silver_ingot"
  309. pDN[30] = "Silver"
  310. pLine[30] = "orange"
  311. pStat[30] = true
  312. pByte[30] = colors.orange
  313. pSide[30] = 2
  314. pMax[30] = 20000
  315.  
  316.  
  317.  
  318. function UserCommand( xpos, ypos)
  319.  
  320.     local bunt = {}
  321.  
  322.     print("UC" ,xpos ,ypos)
  323.     if ypos == 23 then
  324.         if (xpos>42) and (xpos<54) then
  325.             if automat == true then
  326.                 automat = false
  327.             else
  328.                 automat = true
  329.             end
  330.         end
  331.     elseif ypos == 1 then
  332.         if (xpos<6) then
  333.             --prev page
  334.             if dPage > 1 then
  335.                 dPage = dPage -1
  336.             end
  337.         elseif (xpos>52) then
  338.             if dPage < dMax then
  339.                 dPage = dPage +1
  340.             end
  341.         end
  342.     elseif (ypos == 4) or (ypos == 7) or (ypos == 10) or (ypos == 13) or (ypos == 16) or (ypos == 19) then
  343.         npos = (ypos-1) / 3 - 1
  344.         mpos = 0
  345.         if (xpos>9) and (xpos<16) then
  346.             mpos = 1
  347.         elseif (xpos>28) and (xpos<35) then
  348.             mpos = 2
  349.         elseif (xpos>47) and (xpos<54) then
  350.             mpos = 3
  351.         end
  352.         if not(mpos == 0) then
  353.             proNr = (dPage - 1) * 18 + npos * 3 + mpos
  354.             print(proNr)
  355.             if pStat[proNr] == false then
  356.                 pStat[proNr] = true
  357.             else
  358.                 pStat[proNr] = false
  359.             end
  360.             bunt[1] = 0
  361.             bunt[2] = 0
  362.             for mpos = 1, aPro do
  363.                 if pStat[mpos] == true then
  364.                     bunt[pSide[mpos]] = bunt[pSide[mpos]] + pByte[mpos]
  365.                 end
  366.             end
  367.  
  368.             redstone.setBundledOutput("back", bunt[1])
  369.             redstone.setBundledOutput("right", bunt[2])
  370.             print(bunt[1], bunt[2])
  371.         end
  372.     end
  373. end
  374.  
  375.  
  376. function CheckInferiumReihe(lesen)
  377.  
  378.  
  379.     for i = 1,aPro do
  380.         pFound[i] = false
  381.     end
  382.  
  383.     such = {}
  384.     such.name = "mysticalagriculture"
  385.  
  386.     rs = rss.listItems()
  387.  
  388.     if not(rs == nil) then
  389.         for slot, item in pairs(rs) do
  390.             if not(string.find(item.name,"mysticalagriculture") == nil) then
  391.  
  392.                 if item.name == "mysticalagriculture:inferium_essence" then
  393.                     diff = item.amount - 1000
  394.                     if diff > 0 then
  395.                         such.name = item.name
  396.                         --rss.extractItem(such, diff, "east")
  397.                     end
  398.                 elseif item.name == "mysticalagriculture:prudentium_essence" then
  399.                     diff = item.amount - 1000
  400.                     if diff > 0 then
  401.                         such.name = item.name
  402.                         --rss.extractItem(such, diff, "east")
  403.                     end
  404.                 elseif item.name == "mysticalagriculture:tertium_essence" then
  405.                     diff = item.amount - 1000
  406.                     if diff > 0 then
  407.                         such.name = item.name
  408.                         --rss.extractItem(such, diff, "east")
  409.                     end
  410.                 elseif item.name == "mysticalagriculture:imperium_essence" then
  411.                     diff = item.amount - 1000
  412.                     if diff > 0 then
  413.                         such.name = item.name
  414.                         --rss.extractItem(such, diff, "east")
  415.                     end
  416.                 elseif item.name =="mysticalagriculture:supremium_essence" then
  417.                     diff = item.amount - 1000
  418.                     if diff > 0 then
  419.                         such.name = item.name
  420.                         --rss.extractItem(such, diff, "east")
  421.                     end
  422.                 else
  423.                     found = false
  424.                     for i = 1, aSeeds do
  425.                         if item.name == seeds[i] then
  426.                             diff = item.amount - 500
  427.                             if diff > 0 then
  428.                                 such.name = item.name
  429.                                 --rss.extractItem(such, diff, "north")
  430.                                 found = true
  431.                             end
  432.                         end
  433.                         if found == true then
  434.                             break
  435.                         end
  436.                     end
  437.                 end
  438.             end
  439.  
  440.             for i = 1, aPro do
  441.                 if item.name == pName[i] then
  442.                     found = true
  443.                     pStored[i] = item.amount
  444.                     pFound[i] = true
  445.                     if automat == true then
  446.                         if item.amount > pMax[i] then
  447.                             pStat[i] = false
  448.                         else
  449.                             pStat[i] = true
  450.                         end
  451.                     end
  452.                 end
  453.  
  454.             end
  455.         end
  456.  
  457.         for I = 1, aPro do
  458.             if pFound[i] == false then
  459.                 print(pName[i].." not found!")
  460.             end
  461.         end
  462.     end
  463.  
  464.     local bunt = {}
  465.     bunt[1] = 0
  466.     bunt[2] = 0
  467.     for i = 1, aPro do
  468.         if pStat[i] == false then
  469.             bunt[pSide[i]] = bunt[pSide[i]] + pByte[i]
  470.         end
  471.     end
  472.     redstone.setBundledOutput("left", bunt[1])
  473.     redstone.setBundledOutput("right", bunt[2])
  474.  
  475. end
  476.  
  477. function MonAufbau(moni)
  478.  
  479.     if not(moni == nil) then
  480.         moni.setTextScale(0.5)
  481.         moni.setBackgroundColor(colors.black)
  482.         moni.clear()
  483.         moni.setBackgroundColor(colors.green)
  484.         moni.setTextColor(colors.black)
  485.         moni.setCursorPos(10,1)
  486.         moni.write(" *** Wuffelz Ressource Farm Control *** ")
  487.  
  488.         moni.setCursorPos(2,1)
  489.         if dPage > 1 then
  490.             moni.setBackgroundColor(colors.orange)
  491.         else
  492.             moni.setBackgroundColor(colors.black)
  493.             moni.setTextColor(colors.orange)
  494.         end
  495.         moni.write(" << ")
  496.  
  497.         moni.setCursorPos(7,1)
  498.         moni.setBackgroundColor(colors.black)
  499.         moni.setTextColor(colors.orange)
  500.         moni.write(string.format("%1d", dPage))
  501.  
  502.         moni.setCursorPos(53,1)
  503.         if dPage < dMax then
  504.             moni.setBackgroundColor(colors.orange)
  505.             moni.setTextColor(colors.black)
  506.         else
  507.             moni.setBackgroundColor(colors.black)
  508.             moni.setTextColor(colors.orange)
  509.         end
  510.         moni.write(" >> ")
  511.  
  512.         for i = 1,6 do
  513.             k = (i-1) * 3 + 1
  514.             for j = 0,2 do
  515.                 moni.setBackgroundColor(colors.black)
  516.                 moni.setTextColor(colors.blue)
  517.                 if j == 1 then
  518.                     moni.setTextColor(colors.orange)
  519.                 end
  520.                 px = j * 19
  521.                 py = (i-1) * 3 + 3
  522.                 moni.setCursorPos(px + 1, py)
  523.                 pr = k + j + ((dPage - 1) * 18)
  524.                 if pr <= aPro then
  525.                     moni.write(pDN[pr])
  526.                     moni.setCursorPos(px+13, py)
  527.                     moni.write(string.format("%6d", pStored[pr]))
  528.                     moni.setCursorPos(px + 1, py + 1)
  529.                     if pStat[pr] == true then
  530.                         moni.setTextColor(colors.lime)
  531.                         moni.write("online")
  532.                         moni.setTextColor(colors.white)
  533.                         moni.setBackgroundColor(colors.red)
  534.                         moni.setCursorPos(px + 10, py + 1)
  535.                         moni.write("-> off")
  536.                     else
  537.                         moni.setTextColor(colors.red)
  538.                         moni.write("offline")
  539.                         moni.setTextColor(colors.white)
  540.                         moni.setBackgroundColor(colors.lime)
  541.                         moni.setCursorPos(px + 10, py + 1)
  542.                         moni.write("-> on ")
  543.                     end
  544.                 end
  545.             end
  546.         end
  547.         moni.setBackgroundColor(colors.black)
  548.         moni.setTextColor(colors.blue)
  549.         moni.setCursorPos(5,23)
  550.         moni.write("Automatic limit control is ")
  551.         moni.setCursorPos(33,23)
  552.         if automat then
  553.             moni.setTextColor(colors.lime)
  554.             moni.write("enabled ")
  555.             moni.setCursorPos(43,23)
  556.             moni.setBackgroundColor(colors.red)
  557.             moni.setTextColor(colors.white)
  558.             moni.write("-> disable ")
  559.         else
  560.             moni.setTextColor(colors.red)
  561.             moni.write("disabled ")
  562.             moni.setCursorPos(43,23)
  563.             moni.setBackgroundColor(colors.lime)
  564.             moni.setTextColor(colors.white)
  565.             moni.write("-> enable ")
  566.         end
  567.  
  568.  
  569.     end
  570.  
  571. end
  572.  
  573.  
  574. while true do
  575.  
  576.     CheckInferiumReihe(lesen)
  577.  
  578.     MonAufbau(monitor1)
  579.     MonAufbau(monitor2)
  580.     --MonAufbau(monitor3)
  581.     --MonAufbau(monitor4)
  582.  
  583.     event, button, x, y = os.pullEventRaw()
  584.  
  585.     if event == "terminate" then
  586.         break
  587.     elseif event == "redstone" then
  588.         --neuer Durchlauf
  589.     elseif (event == "monitor_touch") and (button == "monitor_4") then
  590.         UserCommand( x, y)
  591.     elseif (event == "monitor_touch") and (button == "monitor_1") then
  592.         UserCommand( x, y)
  593.     elseif (event == "monitor_touch") and (button == "monitor_2") then
  594.         UserCommand( x, y)
  595.     elseif (event == "monitor_touch") and (button == "monitor_3") then
  596.         UserCommand( x, y)
  597.     else
  598.         print(event, button, x, y)
  599.     end
  600.  
  601. end
  602.  
  603.      
  604.  
Advertisement
Add Comment
Please, Sign In to add comment