Advertisement
MagmaLP

Gold to Ironblocks NEW

Nov 1st, 2023 (edited)
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.65 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. sen = sensor.wrap("left")
  3. mon = peripheral.wrap("back")
  4. rs.setOutput("right", false)
  5. term.setBackgroundColor(32768)
  6. term.setCursorPos(1,1)
  7. term.clear()
  8.  
  9. function calc_color(color)
  10.     return math.pow(2, color - 1)
  11. end
  12.  
  13. function msg(gap, line, color, groundb, text)
  14.     mon.setBackgroundColor(calc_color(groundb))
  15.     mon.setCursorPos(gap,line)
  16.     mon.setTextColor(calc_color(color))
  17.     text = mon.write(text)
  18. end
  19.  
  20. local file = fs.open("Shards", "w")
  21. file.write(0)
  22. file.close()
  23. msg(05,03,05,16,"Trade Goldblocks to Ironblocks")
  24. msg(05,04,01,16,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
  25.  
  26. function clear()
  27.     for yPos = 5, 22 do
  28.         msg(01,yPos,16,16,"                                                      ")
  29.     end
  30. end
  31.  
  32. function LangSelect()
  33.     clear()
  34.     for yPos = 7, 11 do
  35.         for xPos = 3, 15 do
  36.             msg(xPos,yPos,01,06," ")
  37.         end
  38.     end
  39.     msg(06,09,01,06,"Deutsch")
  40.     for yPos = 7, 11 do
  41.         for xPos = 24, 36 do
  42.             msg(xPos,yPos,01,06," ")
  43.         end
  44.     end
  45.     msg(27,09,01,06,"English")
  46.    
  47.     event, side, x, y = os.pullEvent("monitor_touch")
  48.     if x >= 03 and x <= 15 and y >= 07 and y <= 11 then
  49.         local file = fs.open("Language", "w")
  50.         file.write("2")
  51.         file.close()
  52.     elseif x >= 24 and x <= 36 and y >= 07 and y <= 11 then
  53.         local file = fs.open("Language", "w")
  54.         file.write("1")
  55.         file.close()
  56.     else
  57.         LangSelect()
  58.     end
  59.     ShardDetection()
  60. end
  61.  
  62. function ShardDetection()
  63.     clear()
  64.     local file = fs.open("Language", "r")
  65.     Lang = file.readLine()
  66.     file.close()
  67.    
  68.     for yPos = 13, 15 do
  69.         for xPos = 3, 15 do
  70.             msg(xPos,yPos,01,06," ")
  71.         end
  72.     end
  73.     for yPos = 13, 15 do
  74.         for xPos = 20, 29 do
  75.             msg(xPos,yPos,01,15," ")
  76.         end
  77.     end
  78.    
  79.     if Lang == "1" then
  80.         msg(02,07,01,16,"Insert all your Shard of Minium")
  81.         msg(02,08,01,16,"and Gold Blocks in the left ME System.")  
  82.         msg(02,11,01,16,"Then confirm with the button below!")
  83.         msg(06,14,01,06,"confirm")
  84.         msg(22,14,01,15," back ")
  85.     elseif Lang == "2" then
  86.         msg(02,07,01,16,"Werfe alle deine Shards und")
  87.         msg(02,08,01,16,"Eisenblöcke in das linke ME-System.")  
  88.         msg(02,11,01,16,"Dann bestätige mit dem grünen Knopf!")
  89.         msg(06,14,01,06," start ")
  90.         msg(22,14,01,15,"zurück")
  91.     end
  92.  
  93.     event, side, x, y = os.pullEvent("monitor_touch")
  94.     if x >= 03 and x <= 15 and y >= 13 and y <= 15 then         --Confirm
  95.         StartCraftingScreen()
  96.     elseif x >= 20 and x <= 29 and y >= 13 and y <= 15 then     --back
  97.         os.reboot()
  98.     else
  99.         ShardDetection()
  100.     end
  101. end
  102.  
  103. function StartCraftingScreen()
  104.     s = sen.getTargets()
  105.     function getS()
  106.         for v, k  in pairs(s) do
  107.             if k.Name == "ME Wireless Access Point" then  
  108.                 target = v
  109.             end
  110.         end
  111.         sleep(0.5)
  112.         return target
  113.     end
  114.  
  115.     f = getS()
  116.     s1 = sen.getTargetDetails(target)
  117.     for v, k in pairs(s1.Items) do
  118.  
  119.         if k.Name == "Shard of Minium" then
  120.             Shard_Of_Minium_Amount = k.Size
  121.             print("Shards Detected: "..Shard_Of_Minium_Amount)
  122.             local file = fs.open("Shards", "w")
  123.             file.write(Shard_Of_Minium_Amount)
  124.             file.close()
  125.         end
  126.     end
  127.  
  128.     local file = fs.open("Shards", "r")
  129.     Shard_Of_Minium_Amount = file.readLine()
  130.     file.close()
  131.     Shard_Of_Minium_Amount = tonumber(Shard_Of_Minium_Amount)
  132.     Insert_Gold_Blocks = Shard_Of_Minium_Amount * 40
  133.  
  134.     clear()
  135.     for yPos = 14, 16 do
  136.         for xPos = 3, 15 do
  137.             msg(xPos,yPos,01,06," ")
  138.         end
  139.     end
  140.     for yPos = 14, 16 do
  141.         for xPos = 20, 31 do
  142.             msg(xPos,yPos,01,15," ")
  143.         end
  144.     end
  145.  
  146.     if Lang == "1" then
  147.         msg(02,07,01,16,"Detected Shards: "..Shard_Of_Minium_Amount)
  148.         msg(02,09,01,16,""..Insert_Gold_Blocks .." Goldblocks can be processed")
  149.         msg(02,10,01,16,"and should be in the left ME-System.")  
  150.         msg(02,12,01,16,"-> confirm with green button to start")
  151.         msg(06,15,01,06,"confirm")
  152.         msg(23,15,01,15,"cancel")
  153.     elseif Lang == "2" then
  154.         msg(02,07,01,16,"Erkannte Shards: "..Shard_Of_Minium_Amount)
  155.         msg(02,09,01,16,""..Insert_Gold_Blocks .." Goldblöcke können vercraftet")
  156.         msg(02,10,01,16,"werden und sollten im linken ME liegen.")  
  157.         msg(02,12,01,16,"-> dann mit Start bestätigen ")
  158.         msg(06,15,01,06," start ")
  159.         msg(23,15,01,15,"zurück")        
  160.     end
  161.    
  162.     event, side, x, y = os.pullEvent("monitor_touch")
  163.     if x >= 03 and x <= 14 and y >= 14 and y <= 16 and Shard_Of_Minium_Amount >= 1 then         --start crafting
  164.         CraftingScreen()
  165.     elseif x >= 20 and x <= 31 and y >= 14 and y <= 16 then     --cancel
  166.         Shard_Of_Minium_Amount = 0
  167.         local file = fs.open("Shards", "w")
  168.         file.write(0)
  169.         file.close()
  170.         ShardDetection()
  171.     else
  172.         StartCraftingScreen()
  173.     end
  174. end
  175.  
  176. function CraftingScreen()
  177.     clear()
  178.     for yPos = 15, 17 do        --Restart
  179.         for xPos = 3, 24 do
  180.             msg(xPos,yPos,01,06," ")
  181.         end
  182.     end
  183.     for yPos = 15, 17 do        --cancel
  184.         for xPos = 28, 37 do
  185.             msg(xPos,yPos,01,15," ")
  186.         end
  187.     end          
  188.    
  189.     if Lang == "1" then
  190.         rs.setOutput("right", true)
  191.         msg(02,07,01,16,"Crafting in process...")
  192.         msg(02,08,01,16,"Iron Block Output in Right ME-System")
  193.         msg(02,10,01,16,"You can stop the Craftingprocess by")  
  194.         msg(02,11,01,16,"pressing the cancel button.")
  195.         msg(02,12,01,16,"You get everything back that")
  196.         msg(02,13,01,16,"hasn't been crafted yet.")
  197.         msg(06,16,01,06,"restart if ready")    
  198.         msg(30,16,01,15,"cancel")
  199.     elseif Lang == "2" then
  200.         rs.setOutput("right", true)
  201.         msg(02,07,01,16,"Craftingprozess läuft...")
  202.         msg(02,08,01,16,"Eisenblock-Ausgabe im rechten ME")
  203.         msg(02,10,01,16,"Du kannst das Crafting stoppen in dem")  
  204.         msg(02,11,01,16,"du den zurück Knopf drückst.")
  205.         msg(02,12,01,16,"Du bekommst alles wieder, das noch")
  206.         msg(02,13,01,16,"nicht vercraftet wurde.")
  207.         msg(04,16,01,06,"Neustart wenn fertig")
  208.         msg(30,16,01,15,"zurück")
  209.     end
  210.                
  211.     event, side, x, y = os.pullEvent("monitor_touch")
  212.     if x >= 03 and x <= 24 and y >= 15 and y <= 17 then
  213.         os.reboot()
  214.     elseif x >= 28 and x <= 37 and y >= 15 and y <= 17 then
  215.         os.reboot()
  216.     else
  217.         CraftingScreen()
  218.     end
  219. end
  220.            
  221. --Program Start
  222. LangSelect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement