SkyFlash21

ToolBox

Jul 25th, 2021 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. ------ToolBox------
  2. function file_exists(name)
  3. local f=io.open(name,"r")
  4. if f~=nil then io.close(f) return true else return false end
  5. end
  6.  
  7. function AnitaRead(var_name)
  8. if not file_exists("Anita/Anitas.last") then
  9. InitializeAnitaLast()
  10. end
  11. local fileHandle = fs.open ("Anita/Anitas.last", 'r')
  12. _table = textutils.unserialize (fileHandle.readAll())
  13. fileHandle.close()
  14. if var_name == nil then
  15. return _table
  16. else
  17. return _table[var_name]
  18. end
  19. end
  20.  
  21. function AnitaWrite(Var_name,Var)
  22. if not file_exists("Anita/Anitas.last") then
  23. InitializeAnitaLast()
  24. end
  25.  
  26. local fileHandle = fs.open ("Anita/Anitas.last", 'r')
  27. _table = textutils.unserialize (fileHandle.readAll())
  28. fileHandle.close()
  29.  
  30. _table[Var_name] = Var
  31.  
  32. local fileHandle = fs.open ("Anita/Anitas.last", 'w')
  33. fileHandle.write (textutils.serialize (_table))
  34. fileHandle.close()
  35. end
  36.  
  37. function InitializeAnitaLast()
  38. local QuarryData = {
  39. ["Rednet"] = false,
  40. ["Check Fuel"] = true,
  41. ["EnderChest"] = 0,
  42. ["Original Day"] = 0,
  43. ["Original Time"] = 0,
  44. ["Position"] = {0,0,0},
  45. ["Orientation"] = 1,
  46. ["Size"] = {0,0,0},
  47. ["Type de minage"] = "Quarry",
  48. ["Block miné"] = 0,
  49. ["Pierre miné"] = 0,
  50. ["Charbon miné"] = 0,
  51. ["Couche miné"] = 0,
  52. ["Progression"] = 0,
  53. ["Mouvement"] = 0,
  54. ["Total Fuel"] = 0,
  55. ["Fuel Level"] = 0,
  56. ["Last turn"] = false
  57. }
  58.  
  59. local fileHandle = fs.open ("Anita/Anitas.last", 'w')
  60. fileHandle.write (textutils.serialize (QuarryData))
  61. fileHandle.close()
  62. end
  63.  
  64. function round(x)
  65. return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
  66. end
  67.  
  68. function Draw(ActiveItemList)
  69. for k,Button in pairs(ActiveItemList) do
  70. fill(Button["text"],Button["backcolor"],Button["textcolor"],Button)
  71. end
  72. end
  73.  
  74. function WriteText(ColorList, TextList)
  75. for key,value in pairs(TextList) do
  76. term.setTextColor(ColorList[key])
  77. term.write(value)
  78. end
  79. end
  80. function fill(text, color,textcolor, bData)
  81.  
  82. term.setTextColor(textcolor)
  83. term.setBackgroundColor(color)
  84. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  85. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  86. for j = bData["ymin"], bData["ymax"] do
  87. term.setCursorPos(bData["xmin"], j)
  88. if j == yspot then
  89. for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  90. if k == xspot then
  91. term.write(text)
  92. else
  93. term.write(" ")
  94. end
  95. end
  96. else
  97. for i = bData["xmin"], bData["xmax"] do
  98. term.write(" ")
  99. end
  100. end
  101. end
  102.  
  103. term.setTextColor(colors.black)
  104. term.setBackgroundColor(colors.black)
  105. end
  106.  
  107. function MoveRight()
  108. local dir = AnitaRead("Orientation")
  109. turtle.turnRight()
  110. dir = math.mod(dir + 1,5)
  111. if dir == 0 then
  112. dir = 1
  113. end
  114. AnitaWrite("Orientation",dir)
  115. end
  116.  
  117. function MoveLeft()
  118. local dir = AnitaRead("Orientation")
  119. turtle.turnLeft()
  120. dir = math.mod(dir- 1,5)
  121. if dir == 0 then
  122. dir = 1
  123. end
  124. AnitaWrite("Orientation",dir)
  125. end
  126.  
  127. function MoveDown()
  128. local pos = AnitaRead("Position")
  129. while turtle.down() == false do
  130. turtle.digDown()
  131. end
  132. pos[3] = pos[3] - 1
  133. AnitaWrite("Position",pos)
  134. end
  135.  
  136. function MoveUp()
  137. local pos = AnitaRead("Position")
  138. while turtle.up() == false do
  139. turtle.digUp()
  140. end
  141. pos[3] = pos[3] + 1
  142. AnitaWrite("Position",pos)
  143. end
  144.  
  145. function MoveForward()
  146. local pos = AnitaRead("Position")
  147. local dir = AnitaRead("Orientation")
  148. while turtle.forward() == false do
  149. turtle.dig()
  150. end
  151.  
  152. if dir == 1 then
  153. pos[1] = pos[1] + 1
  154. elseif dir == 2 then
  155. pos[2] = pos[2] + 1
  156. elseif dir == 3 then
  157. pos[1] = pos[1] - 1
  158. else
  159. pos[2] = pos[2] - 1
  160. end
  161. AnitaWrite("Position",pos)
  162. end
  163.  
  164.  
  165. function MoveBack()
  166. local pos = AnitaRead("Position")
  167. local dir = AnitaRead("Orientation")
  168.  
  169. while turtle.back() == false do
  170. turtle.turnLeft()
  171. turtle.turnLeft()
  172. turtle.dig()
  173. turtle.turnLeft()
  174. turtle.turnLeft()
  175. end
  176.  
  177. if dir == 1 then
  178. pos[1] = pos[1] - 1
  179. elseif dir == 2 then
  180. pos[2] = pos[2] - 1
  181. elseif dir == 3 then
  182. pos[1] = pos[1] + 1
  183. else
  184. pos[2] = pos[2] + 1
  185. end
  186. AnitaWrite("Position",pos)
  187. end
Add Comment
Please, Sign In to add comment