dadragon84

Scanner/Feeder

Mar 8th, 2025 (edited)
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.70 KB | None | 0 0
  1. function clearScreen()
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4. end
  5. clearScreen()
  6. -- textutils.slowPrint("Welcome to JDowe Ore Scanner and Feeder")
  7. function feedTime(message)
  8.  
  9.     local fName = 'feeding.log'
  10.     if fs.exists(fName) then
  11.         file = fs.open(fName, 'a')
  12.         file.write("Time is " .. textutils.formatTime(os.time()) .. "\n")
  13.         file.write(tostring(message) .. "\n")
  14.         file.write(string.rep("-", 30) .. "\n")
  15.         file.close()
  16.     else
  17.         file = fs.open(fName, 'w')
  18.         file.write("Starting you MC Feeding Log\n")
  19.         file.write(string.rep("*", 30) .. "\n")
  20.         file.close()
  21.     end
  22. end
  23.  
  24. -- textutils.slowPrint("Please Keep Food In Your Pockets")
  25.  
  26. function feedPlayer()
  27.    
  28.     -- textutils.slowPrint("Starting Feed Player System!", 15)
  29.     local modules = peripheral.find("manipulator") or peripheral.find("neuralInterface")
  30.    
  31.    
  32.     if not modules then
  33.         error("Must have neural interface or manipulator", 0)
  34.     end
  35.     if not modules.hasModule("plethora:sensor") then
  36.         error("The entity sensor is missing", 0)
  37.     end
  38.     if not modules.hasModule("plethora:introspection") then
  39.         error("The introspection module is missing", 0)
  40.     end
  41.  
  42.     local inv = modules.getInventory()
  43.     local cachedSlot = false
  44.     while true do
  45.         local data = modules.getMetaOwner()
  46.         while data.food.hungry do
  47.             local item
  48.             if cachedSlot then
  49.                 local slotItem = inv.getItem(cachedSlot)
  50.                 if slotItem and slotItem.consume then
  51.                     item = slotItem
  52.                 else
  53.                     cachedSlot = nil
  54.                 end
  55.             end
  56.             if not item then
  57.                 for slot, meta in pairs(inv.list()) do
  58.                     local slotItem = inv.getItem(slot)
  59.                     local meta = slotItem.getMetadata()
  60.                     local itemName = meta.displayName
  61.                     if slotItem and slotItem.consume then
  62.                         local feedAction = "Eating some ".. itemName .. " in pocket " .. slot
  63.                         print(feedAction)
  64.                         feedTime(feedAction)
  65.                         item = slotItem
  66.                         cachedSlot = slot
  67.                         break
  68.                     end
  69.                 end
  70.             end
  71.             if item then
  72.                 item.consume()
  73.             else
  74.                 print("Cannot find food")
  75.                 break
  76.             end
  77.             data = modules.getMetaOwner()
  78.         end
  79.         sleep(5)
  80.     end
  81. end
  82.  
  83. -- textutils.slowPrint("Initializing Ore Scanner Systems!", 15)
  84. -- sleep(10)
  85. clearScreen()
  86. function oreScanner()
  87.     -- textutils.slowPrint("Initializing Ore Scanner Systems!", 15)
  88.     local scanInterval = 0.2
  89.     local renderInterval = 0.05
  90.     local scannerRange = 8
  91.     local scannerWidth = scannerRange * 2 + 1
  92.    
  93.     local size = 0.5
  94.     local cellSize = 16
  95.     local offsetX = 75
  96.     local offsetY = 75
  97.    
  98.     -- while true do
  99.     --  local event, dir, x, y = os.pullEvent("mouse_scroll")
  100.     --  print(("The mouse was scrolled in direction %s at %d, %d"):format(dir, x, y))
  101.     -- end
  102.    
  103.     local ores = {
  104.         ["minecraft:diamond_ore"] = 10,
  105.         ["minecraft:emerald_ore"] = 10,
  106.         ["minecraft:lava"] = 9,
  107.         ["minecraft:gold_ore"] = 8,
  108.         ["minecraft:redstone_ore"] = 5,
  109.         ["minecraft:lapis_ore"] = 5,
  110.         ["minecraft:iron_ore"] = 2,
  111.         ["appliedenergistics2:sky_stone_block"] = 1,
  112.         -- ["minecraft:coal_ore"] = 1
  113.     }
  114.  
  115.     local colours = {
  116.         -- ["minecraft:coal_ore"] = { 76, 76, 76 }, -- Grey
  117.         ["minecraft:iron_ore"] = { 255, 150, 50 }, -- Orange
  118.         ["minecraft:lava"] = { 178, 102, 204 },  -- Purple
  119.         ["minecraft:gold_ore"] = { 222, 222, 108 },  -- Yellow
  120.         ["minecraft:diamond_ore"] = { 76, 153, 178 },  --Cyan
  121.         ["minecraft:redstone_ore"] = { 204, 76, 76 },  -- Red
  122.         ["minecraft:lapis_ore"] = { 51, 102, 204 }, -- Blue
  123.         ["minecraft:emerald_ore"] = { 87, 166, 78 }, -- Green
  124.         ["appliedenergistics2:sky_stone_block"] = { 17, 17, 17 }, --Black
  125.     }
  126.     local oreNames = {
  127.         "Coal",
  128.         "Iron",
  129.         "lava",
  130.         "Gold",
  131.         "diamond",
  132.         "redstone",
  133.         "lapis",
  134.         "emerald",
  135.         "Sky Stones",
  136.  
  137.        
  138.     }
  139.  
  140.     local oreColors = {
  141.         'gray',
  142.         'Orange',
  143.         'Purple',
  144.         'Gold',
  145.         'Cyan',
  146.         'Red',
  147.         'Blue',
  148.         'Green',
  149.         'black',
  150.     }
  151.  
  152.     local colorNumbers = {
  153.         '128',
  154.         '2',
  155.         '1024',
  156.         '16',
  157.         '512',
  158.         '16384',
  159.         '2048',
  160.         '8192',
  161.         '32768',
  162.     }
  163.     term.setCursorBlink(true)
  164.     term.setBackgroundColor(colors.red)
  165.     -- while true do
  166.     --  local event, dir, x, y = os.pullEvent("mouse_scroll")
  167.     print("Ore Legend and Colors\n")
  168.     term.setBackgroundColor(colors.black)
  169.     local w, h = term.getSize()
  170.     print(string.rep("-", w) .. "\n")
  171.  
  172.     local start = 0
  173.     local stop = #oreNames
  174.     term.setTextColor(colors.white)
  175.     for i=1, stop do
  176.         local sNames = oreNames[i]
  177.         local sColors = oreColors[i]
  178.         if sNames == 'Sky Stones' then
  179.             term.setTextColor(colors.white)
  180.         else
  181.             term.setTextColor(tonumber(colorNumbers[i]))
  182.         end
  183.         local oName = nil
  184.         if sNames == 'lava' then
  185.             oName = 'Source'
  186.         elseif sNames == 'Sky Stones' then
  187.             oName = ''
  188.         else
  189.             oName = 'Ores'
  190.         end
  191.  
  192.        
  193.         local sNames = sNames .. " " .. oName
  194.         local countNames = string.len(sNames)
  195.         local countColors = string.len(sColors)
  196.         local charCount = (countNames + countColors + 15)
  197.         -- print(sNames:upper() .. " ".. oName:upper() .. string.rep(".", w - charCount) .. sColors:upper() .. "\n")
  198.         textutils.tabulate({sNames:upper(), string.rep(".", w - charCount), sColors:upper()})
  199.         -- pretty.print(pretty.group( pretty.text(sNames:upper()),  pretty.text(string.rep(".", w - charCount)) , pretty.text(sColors:upper() )) )
  200.     end
  201.    
  202.     term.setTextColor(colors.white)
  203.     print(string.rep("-", w) .. "\n")
  204.     textutils.slowPrint("You can scroll wheel this screen\n", 10)
  205.     local modules = peripheral.find("neuralInterface")
  206.     if not modules then error("Must have a neural interface", 0) end
  207.     if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end
  208.     if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end
  209.    
  210.     local canvas = modules.canvas()
  211.     canvas.clear()
  212.    
  213.     local block_text = {}
  214.     local blocks = {}
  215.     for x = -scannerRange, scannerRange, 1 do
  216.         block_text[x] = {}
  217.         blocks[x] = {}
  218.  
  219.         for z = -scannerRange, scannerRange, 1 do
  220.             block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)
  221.             blocks[x][z] = { y = nil, block = nil }
  222.         end
  223.     end
  224.    
  225.     canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)
  226.    
  227.     local function scan()
  228.         while true do
  229.             local scanned_blocks = modules.scan()
  230.             for x = -scannerRange, scannerRange do
  231.                 for z = -scannerRange, scannerRange do
  232.                     local best_score, best_block, best_y = -1
  233.                     for y = -scannerRange, scannerRange do
  234.                         local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
  235.                         if scanned then
  236.                             local new_score = ores[scanned.name]
  237.                             if new_score and new_score > best_score then
  238.                                 best_block = scanned.name
  239.                                 best_score = new_score
  240.                                 best_y = y
  241.                             end
  242.                         end
  243.                     end
  244.  
  245.                     -- Update our block table with this information.
  246.                     blocks[x][z].block = best_block
  247.                     blocks[x][z].y = best_y
  248.                 end
  249.             end
  250.            
  251.             sleep(scanInterval)
  252.         end
  253.     end
  254.    
  255.    
  256.     local function render()
  257.         while true do
  258.             local meta = modules.getMetaOwner and modules.getMetaOwner()
  259.             local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
  260.             for x = -scannerRange, scannerRange do
  261.                 for z = -scannerRange, scannerRange do
  262.                     local text = block_text[x][z]
  263.                     local block = blocks[x][z]
  264.  
  265.                     if block.block then
  266.                         local px = math.cos(angle) * -x - math.sin(angle) * -z
  267.                         local py = math.sin(angle) * -x + math.cos(angle) * -z
  268.  
  269.                         local sx = math.floor(px * size * cellSize)
  270.                         local sy = math.floor(py * size * cellSize)
  271.                         text.setPosition(offsetX + sx, offsetY + sy)
  272.                         text.setText(tostring(block.y))
  273.                         text.setColor(table.unpack(colours[block.block]))
  274.                     else
  275.                         text.setText(" ")
  276.                     end
  277.                 end
  278.             end
  279.  
  280.                 sleep(renderInterval)
  281.         end
  282.     end
  283.  
  284.    parallel.waitForAll(render, scan)
  285. end
  286.  
  287. parallel.waitForAll(feedPlayer, oreScanner)
  288.  
  289.  
Advertisement
Add Comment
Please, Sign In to add comment