Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- clearScreen()
- -- textutils.slowPrint("Welcome to JDowe Ore Scanner and Feeder")
- function feedTime(message)
- local fName = 'feeding.log'
- if fs.exists(fName) then
- file = fs.open(fName, 'a')
- file.write("Time is " .. textutils.formatTime(os.time()) .. "\n")
- file.write(tostring(message) .. "\n")
- file.write(string.rep("-", 30) .. "\n")
- file.close()
- else
- file = fs.open(fName, 'w')
- file.write("Starting you MC Feeding Log\n")
- file.write(string.rep("*", 30) .. "\n")
- file.close()
- end
- end
- -- textutils.slowPrint("Please Keep Food In Your Pockets")
- function feedPlayer()
- -- textutils.slowPrint("Starting Feed Player System!", 15)
- local modules = peripheral.find("manipulator") or peripheral.find("neuralInterface")
- if not modules then
- error("Must have neural interface or manipulator", 0)
- end
- if not modules.hasModule("plethora:sensor") then
- error("The entity sensor is missing", 0)
- end
- if not modules.hasModule("plethora:introspection") then
- error("The introspection module is missing", 0)
- end
- local inv = modules.getInventory()
- local cachedSlot = false
- while true do
- local data = modules.getMetaOwner()
- while data.food.hungry do
- local item
- if cachedSlot then
- local slotItem = inv.getItem(cachedSlot)
- if slotItem and slotItem.consume then
- item = slotItem
- else
- cachedSlot = nil
- end
- end
- if not item then
- for slot, meta in pairs(inv.list()) do
- local slotItem = inv.getItem(slot)
- local meta = slotItem.getMetadata()
- local itemName = meta.displayName
- if slotItem and slotItem.consume then
- local feedAction = "Eating some ".. itemName .. " in pocket " .. slot
- print(feedAction)
- feedTime(feedAction)
- item = slotItem
- cachedSlot = slot
- break
- end
- end
- end
- if item then
- item.consume()
- else
- print("Cannot find food")
- break
- end
- data = modules.getMetaOwner()
- end
- sleep(5)
- end
- end
- -- textutils.slowPrint("Initializing Ore Scanner Systems!", 15)
- -- sleep(10)
- clearScreen()
- function oreScanner()
- -- textutils.slowPrint("Initializing Ore Scanner Systems!", 15)
- local scanInterval = 0.2
- local renderInterval = 0.05
- local scannerRange = 8
- local scannerWidth = scannerRange * 2 + 1
- local size = 0.5
- local cellSize = 16
- local offsetX = 75
- local offsetY = 75
- -- while true do
- -- local event, dir, x, y = os.pullEvent("mouse_scroll")
- -- print(("The mouse was scrolled in direction %s at %d, %d"):format(dir, x, y))
- -- end
- local ores = {
- ["minecraft:diamond_ore"] = 10,
- ["minecraft:emerald_ore"] = 10,
- ["minecraft:lava"] = 9,
- ["minecraft:gold_ore"] = 8,
- ["minecraft:redstone_ore"] = 5,
- ["minecraft:lapis_ore"] = 5,
- ["minecraft:iron_ore"] = 2,
- ["appliedenergistics2:sky_stone_block"] = 1,
- -- ["minecraft:coal_ore"] = 1
- }
- local colours = {
- -- ["minecraft:coal_ore"] = { 76, 76, 76 }, -- Grey
- ["minecraft:iron_ore"] = { 255, 150, 50 }, -- Orange
- ["minecraft:lava"] = { 178, 102, 204 }, -- Purple
- ["minecraft:gold_ore"] = { 222, 222, 108 }, -- Yellow
- ["minecraft:diamond_ore"] = { 76, 153, 178 }, --Cyan
- ["minecraft:redstone_ore"] = { 204, 76, 76 }, -- Red
- ["minecraft:lapis_ore"] = { 51, 102, 204 }, -- Blue
- ["minecraft:emerald_ore"] = { 87, 166, 78 }, -- Green
- ["appliedenergistics2:sky_stone_block"] = { 17, 17, 17 }, --Black
- }
- local oreNames = {
- "Coal",
- "Iron",
- "lava",
- "Gold",
- "diamond",
- "redstone",
- "lapis",
- "emerald",
- "Sky Stones",
- }
- local oreColors = {
- 'gray',
- 'Orange',
- 'Purple',
- 'Gold',
- 'Cyan',
- 'Red',
- 'Blue',
- 'Green',
- 'black',
- }
- local colorNumbers = {
- '128',
- '2',
- '1024',
- '16',
- '512',
- '16384',
- '2048',
- '8192',
- '32768',
- }
- term.setCursorBlink(true)
- term.setBackgroundColor(colors.red)
- -- while true do
- -- local event, dir, x, y = os.pullEvent("mouse_scroll")
- print("Ore Legend and Colors\n")
- term.setBackgroundColor(colors.black)
- local w, h = term.getSize()
- print(string.rep("-", w) .. "\n")
- local start = 0
- local stop = #oreNames
- term.setTextColor(colors.white)
- for i=1, stop do
- local sNames = oreNames[i]
- local sColors = oreColors[i]
- if sNames == 'Sky Stones' then
- term.setTextColor(colors.white)
- else
- term.setTextColor(tonumber(colorNumbers[i]))
- end
- local oName = nil
- if sNames == 'lava' then
- oName = 'Source'
- elseif sNames == 'Sky Stones' then
- oName = ''
- else
- oName = 'Ores'
- end
- local sNames = sNames .. " " .. oName
- local countNames = string.len(sNames)
- local countColors = string.len(sColors)
- local charCount = (countNames + countColors + 15)
- -- print(sNames:upper() .. " ".. oName:upper() .. string.rep(".", w - charCount) .. sColors:upper() .. "\n")
- textutils.tabulate({sNames:upper(), string.rep(".", w - charCount), sColors:upper()})
- -- pretty.print(pretty.group( pretty.text(sNames:upper()), pretty.text(string.rep(".", w - charCount)) , pretty.text(sColors:upper() )) )
- end
- term.setTextColor(colors.white)
- print(string.rep("-", w) .. "\n")
- textutils.slowPrint("You can scroll wheel this screen\n", 10)
- local modules = peripheral.find("neuralInterface")
- if not modules then error("Must have a neural interface", 0) end
- if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end
- if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end
- local canvas = modules.canvas()
- canvas.clear()
- local block_text = {}
- local blocks = {}
- for x = -scannerRange, scannerRange, 1 do
- block_text[x] = {}
- blocks[x] = {}
- for z = -scannerRange, scannerRange, 1 do
- block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)
- blocks[x][z] = { y = nil, block = nil }
- end
- end
- canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)
- local function scan()
- while true do
- local scanned_blocks = modules.scan()
- for x = -scannerRange, scannerRange do
- for z = -scannerRange, scannerRange do
- local best_score, best_block, best_y = -1
- for y = -scannerRange, scannerRange do
- local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
- if scanned then
- local new_score = ores[scanned.name]
- if new_score and new_score > best_score then
- best_block = scanned.name
- best_score = new_score
- best_y = y
- end
- end
- end
- -- Update our block table with this information.
- blocks[x][z].block = best_block
- blocks[x][z].y = best_y
- end
- end
- sleep(scanInterval)
- end
- end
- local function render()
- while true do
- local meta = modules.getMetaOwner and modules.getMetaOwner()
- local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
- for x = -scannerRange, scannerRange do
- for z = -scannerRange, scannerRange do
- local text = block_text[x][z]
- local block = blocks[x][z]
- if block.block then
- local px = math.cos(angle) * -x - math.sin(angle) * -z
- local py = math.sin(angle) * -x + math.cos(angle) * -z
- local sx = math.floor(px * size * cellSize)
- local sy = math.floor(py * size * cellSize)
- text.setPosition(offsetX + sx, offsetY + sy)
- text.setText(tostring(block.y))
- text.setColor(table.unpack(colours[block.block]))
- else
- text.setText(" ")
- end
- end
- end
- sleep(renderInterval)
- end
- end
- parallel.waitForAll(render, scan)
- end
- parallel.waitForAll(feedPlayer, oreScanner)
Advertisement
Add Comment
Please, Sign In to add comment