MagmaLP

Plethora Mod Ores

Sep 11th, 2022
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.60 KB | None | 0 0
  1. --[[
  2. Author: iikk_a (https://github.com/iikk-a/)
  3. Latest Edit: 20.01.2021
  4. This code is absolutely not perfect, but it should be usable.
  5. No bugs have been found as of late. If you find a bug with this code,
  6. please leave an issue ticket on GitHub, so I can get to fixing it.
  7. Start up the application and select ores you want to track by clicking
  8. on them with your mouse cursor. You can deselect ores by clicking them again.
  9. If you have old tracers stuck mid air, just start this application again
  10. without picking ores and quit to clear the old tracers.
  11. Thank you.
  12. ]]--
  13.  
  14.  
  15. -- Instantly quits if you don't have a neural interface
  16. local modules = peripheral.find("neuralInterface")
  17. if not modules then error("must have a neural interface", 0) end
  18.  
  19. -- List so we can display all missing modules at once
  20. local missingModules = {}
  21.  
  22. -- Checks the existence of necessary modules
  23. if not modules.hasModule("plethora:scanner") then table.insert(missingModules, "Block Scanner") end
  24. if not modules.hasModule("plethora:glasses") then table.insert(missingModules, "Overlay Glasses") end
  25.  
  26. -- If one or more modules are missing, error out
  27. if (#missingModules > 0) then error("Missing modules:\n - " .. table.concat(missingModules, "\n - "), 0) end
  28.  
  29. -- Wrap neural link as a peripheral, clear the old canvas and create a new one
  30. local link = peripheral.wrap("back")
  31. link.canvas3d().clear()
  32. local canvas = link.canvas3d().create()
  33.  
  34. -- How many seconds there are between scans
  35. local TIME_BETWEEN_SCANS = 0
  36.  
  37. -- Set to true if you want to disable configuration screen and always use all ores
  38. local NO_CONFIGURATION_UI = false
  39.  
  40. -- The color values used in the background colors, can be found here: http://computercraft.info/wiki/Colors_(API)
  41. -- CHANGE THESE IF YOU HAVE DEUTERANOPIA AND CANNOT EASILY DIFFERENTIATE RED AND GREEN
  42. local COLOR_BLACK = 32768
  43. local COLOR_RED = 16384
  44. local COLOR_GREEN = 32
  45.  
  46. -- Get screen size to draw UI properly
  47. local x = term.getSize()
  48.  
  49. -- List of ores that are tracked, will be all if NO_CONFIGURATION_UI is set to true
  50. local ores = {}
  51.  
  52. -- List of all ores this tracker can track with current settings in current modpack
  53. local completeOreList = {
  54. "minecraft:coal_ore",
  55. "minecraft:iron_ore",
  56. "minecraft:redstone_ore",
  57. "minecraft:gold_ore",
  58. "minecraft:lapis_ore",
  59. "minecraft:diamond_ore",
  60. "minecraft:emerald_ore",
  61. "ic2:resource",
  62. "appliedenergistics2:quartz_ore",
  63. "thermalfoundation:ore_fluid"
  64. }
  65.  
  66. -- This table hold selected ores
  67. local _UI_CONFIG = {}
  68.  
  69. -- Colors for ore tracers, colors use HEX with alpha, these can be changed
  70. local colors = {
  71. ["minecraft:coal_ore"] = 0x000000ff,
  72. ["minecraft:iron_ore"] = 0xff9632ff,
  73. ["minecraft:redstone_ore"] = 0xff0000ff,
  74. ["minecraft:gold_ore"] = 0xffff00ff,
  75. ["minecraft:lapis_ore"] = 0x0032ffff,
  76. ["minecraft:diamond_ore"] = 0x00ffffff,
  77. ["minecraft:emerald_ore"] = 0x00ff00ff,
  78. ["ic2:resource"] = 0x005a00ff,
  79. ["appliedenergistics2:quartz_ore"] = 0xe3fcfaff,
  80. ["thermalfoundation:ore_fluid"] = 0x781725ff
  81. }
  82.  
  83. -- This function renders a line for all given blocks with given attributes
  84. function renderLines(vectorList)
  85. -- Clear the 3D canvas so lines don't stack up
  86. link.canvas3d().clear()
  87.  
  88. -- Create a new canvas, since link.canvas3d().clear() dereferences it
  89. local canvas = link.canvas3d().create()
  90.  
  91. -- Loop through all given objects and draw lines to all of them with given thickness and color
  92. for i = 1, #vectorList, 1 do
  93. canvas.addLine({ 0, -1, 0 }, { vectorList[i].x, vectorList[i].y, vectorList[i].z }, vectorList[i].thickness, vectorList[i].color)
  94. end
  95. end
  96.  
  97. -- Starting UI to select wanted ores
  98. while not NO_CONFIGURATION_UI do
  99. -- Clear the screen and write ores onto it
  100. term.setBackgroundColor(COLOR_BLACK)
  101. term.clear()
  102.  
  103. -- Loop through all the available ores to write them to screen in a specific order
  104. for i = 1, #completeOreList, 1 do
  105. -- Variable for checking if ore exists in list of selected ores
  106. local isSelected = false
  107.  
  108. -- Move the cursor to the appropriate line
  109. term.setCursorPos(1, i)
  110.  
  111. -- Calculate how many spaces are needed to center the text in the window
  112. local spaces = string.rep(" ", math.floor((x - (#completeOreList[i] + 2)) / 2))
  113.  
  114. -- Make the string to print on the screen
  115. local str = "[" .. spaces .. completeOreList[i] .. spaces
  116.  
  117. if (#str + 1 < x) then str = str .. " ]"
  118. else str = str .. "]" end
  119.  
  120. -- If the ore can be found from the list of selected, make isSelected true, otherwise false
  121. for j = 1, #_UI_CONFIG, 1 do
  122. if (_UI_CONFIG[j] == completeOreList[i]) then isSelected = true end
  123. end
  124.  
  125. -- If the ore is selected, make its background green, otherwise background is red
  126. if (isSelected) then
  127. term.setBackgroundColor(COLOR_GREEN)
  128. else
  129. term.setBackgroundColor(COLOR_RED)
  130. end
  131.  
  132. -- Prints the ore name in the correct position
  133. print(str)
  134. end
  135.  
  136. -- Set the cursor for second line below the ore block and set the text background to green
  137. term.setCursorPos(1, #completeOreList + 2)
  138. term.setBackgroundColor(COLOR_GREEN)
  139.  
  140. -- Make string [ Start Application ] and center it on the line
  141. local str = "Start Application"
  142.  
  143. -- This function replicates spaces until we get enough that the text is centered
  144. local spaces = string.rep(" ", math.floor((x - (#str + 2)) / 2))
  145. local toPrint = "[" .. spaces .. str .. spaces
  146.  
  147. -- If the amount of spaces is one too few, add one to the end
  148. if (#toPrint + 1 < x) then toPrint = toPrint .. " ]"
  149. else toPrint = toPrint .. "]" end
  150.  
  151. -- Write the new string to the screen and turn the background back to black
  152. write(toPrint)
  153. term.setBackgroundColor(COLOR_BLACK)
  154.  
  155. -- Check for mouse clicks
  156. local event, button, x, y = os.pullEvent("mouse_click")
  157.  
  158. -- If the mouse click is inside the area designated for ores, then log which ore was clicked
  159. if (y <= #completeOreList) then
  160. -- Variable for checking if ore already exists in table
  161. local isInTable = false
  162.  
  163. -- Loop through all the selected ores to check if the clicked one is already selected
  164. for i = 1, #_UI_CONFIG, 1 do
  165. -- If ore is already selected, make isInTable its index, otherwise it stays false
  166. if (_UI_CONFIG[i] == completeOreList[y]) then isInTable = i end
  167. end
  168.  
  169. -- If not false (AKA has an index) then remove that index from the table
  170. -- Otherwise insert value into the table
  171. if (isInTable ~= false) then
  172. table.remove(_UI_CONFIG, isInTable)
  173. else
  174. table.insert(_UI_CONFIG, completeOreList[y])
  175. end
  176. else
  177. -- If the mouse click is outside of the ore selection area, then break and start the main application
  178. break
  179. end
  180. end
  181.  
  182.  
  183. -- Track all ores if NO_CONFIGURATION_UI is true and only selected if false
  184. if (NO_CONFIGURATION_UI) then
  185. ores = completeOreList
  186. else
  187. ores = _UI_CONFIG
  188. end
  189.  
  190. -- Clear the canvas and set background color to black when starting
  191. -- Please ignore this code block, it looks terrible, but making it better is not worth the effort
  192. term.setBackgroundColor(COLOR_BLACK)
  193. canvas.clear()
  194. term.clear()
  195. term.setCursorPos(1,1)
  196. print("Hold CTRL + T to stop execution")
  197. term.setCursorPos(1,2)
  198. print("Hold CTRL + R to reconfigure ores")
  199. term.setCursorPos(1,4)
  200. print("Ores selected: " .. #ores)
  201. term.setCursorPos(1,6)
  202. print("Code running...")
  203.  
  204.  
  205. -- Main execution block where ore tracking and rendering happens
  206. while true do
  207. local oreList = {}
  208. -- Block scanning
  209. for _, block in pairs(link.scan()) do
  210. -- Loop through all the ores that are being tracked
  211. for i = 1, #ores, 1 do
  212. -- If a matching ore is found, execute the following code
  213. if (block.name == ores[i]) then
  214. -- Create an object with all necessary parameters
  215. local toAdd = {
  216. ["x"] = block.x,
  217. ["y"] = block.y,
  218. ["z"] = block.z,
  219. ["thickness"] = 3.0,
  220. ["color"] = colors[block.name]
  221. }
  222. -- Insert made object into a table before being sent to the renderer
  223. table.insert(oreList, toAdd)
  224. end
  225. end
  226. end
  227.  
  228. -- Render lines with correct colors for all blocks and sleep (if time is set)
  229. renderLines(oreList)
  230. os.sleep(TIME_BETWEEN_SCANS)
  231. end
Add Comment
Please, Sign In to add comment