Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modules = peripheral.find("neuralInterface")
- local hasLaser = false
- local hasIntrospection = false
- local hasGlasses = false
- local hasScanner = false
- local hasKinetic = false
- local hasSensor = false
- local playerData = nil
- local canvas3d = nil
- local canvas = nil
- local blocksMap = {}
- local TARGET_ORES = {}
- local keyMappings = {}
- local acceptedFoods = {}
- local laserStrength = 5 -- min:0.5 | max:5
- local hover = false
- local spacebar = false
- local w = false
- local seeOres = false
- local windowWidth, windowHeight = 0,0
- local function load()
- if (modules) then
- hasLaser = modules.hasModule("plethora:laser")
- hasIntrospection = modules.hasModule("plethora:introspection")
- hasGlasses = modules.hasModule("plethora:glasses")
- hasScanner = modules.hasModule("plethora:scanner")
- hasKinetic = modules.hasModule("plethora:kinetic")
- hasSensor = modules.hasModule("plethora:sensor")
- playerData = modules.getMetaOwner()
- canvas3d = modules.canvas3d()
- canvas = modules.canvas()
- windowWidth, windowHeight = canvas.getSize()
- end
- TARGET_ORES = {
- ["minecraft:coal_ore"] = 0x00FAE0FF, -- black
- ["minecraft:deepslate_coal_ore"] = 0x00FAE0FF,
- ["minecraft:diamond_ore"] = 0x00FFFFFF, -- Cyan
- ["minecraft:deepslate_diamond_ore"] = 0x00FFFFFF,
- ["minecraft:ancient_debris"] = 0xFF8000FF, -- Orange
- ["minecraft:iron_ore"] = 0xD8AF93FF, -- Beige/Brown
- ["minecraft:deepslate_iron_ore"] = 0xD8AF93FF,
- ["minecraft:gold_ore"] = 0xFFD700FF, -- Gold
- ["minecraft:deepslate_gold_ore"] = 0xFFD700FF,
- ["minecraft:emerald_ore"] = 0x00FF00FF, -- Green
- ["minecraft:deepslate_emerald_ore"] = 0x00FF00FF,
- }
- -- The value assigned is not used for anything, but I need so the script does not freak out
- acceptedFoods = {
- ["minecraft:cooked_beef"] = 1,
- ["minecraft:bread"] = 1,
- ["minecraft:cooked_porkchop"] = 1,
- ["minecraft:cooked_chicken"] = 1,
- ["minecraft:baked_potato"] = 1,
- ["minecraft:pumpkin_pie"] = 1,
- ["minecraft:cooked_rabbit"] = 1,
- ["minecraft:rabbit_stew"] = 1,
- ["minecraft:cooked_mutton"] = 1,
- ["minecraft:beetroot_soup"] = 1
- }
- --TODO: Add field "icon" to display peripheral control
- keyMappings = {
- ["grave"] = { -- º
- display="º",
- fun=function()
- if (hasLaser and hasIntrospection) then -- Shoots laser
- playerData = modules.getMetaOwner()
- modules.fire(playerData.yaw, playerData.pitch, laserStrength)
- end
- end
- },
- ["rightAlt"] = { -- <
- display="R-Alt",
- fun=function()
- if (hasLaser) then -- Adjusts laser strength
- laserStrength = laserStrength + 1
- if (laserStrength > 5) then
- laserStrength = 1
- end
- end
- end
- },
- ["leftAlt"] = {
- display="L-Alt",
- fun=function()
- if (hasKinetic) then
- hover = not hover
- end
- end
- },
- ["space"] = {
- display="space",
- fun=function()
- spacebar = true
- end
- },
- ["rightCtrl"] = {
- display="R-Ctr",
- fun=function()
- seeOres = not seeOres
- end
- },
- ["w"] = {
- display="R-Ctr",
- fun=function()
- w = true
- end
- }
- }
- end
- local function update()
- while (true) do
- if (hasIntrospection) then
- playerData = modules.getMetaOwner()
- end
- -- ore scanner
- if (hasScanner and seeOres) then
- local blocks = modules.scan()
- for i=#blocks, 1, -1 do
- local block = blocks[i]
- if (TARGET_ORES[block.name] == nil) then
- table.remove(blocks, i)
- end
- end
- blocksMap = blocks
- end
- --Auto feed
- if (hasIntrospection and playerData.food.hungry and false) then -- Very broken
- local inv = modules.getInventory()
- for slot, meta in pairs(inv.list()) do
- local slotItem = inv.getItem(slot)
- if slotItem and acceptedFoods[meta.name] then
- slotItem.consume()
- break
- end
- end
- end
- spacebar = false
- sleep(0.1)
- end
- end
- local function draw()
- while (true)do
- if (hasGlasses) then
- canvas3d.clear()
- canvas.clear()
- -- Ore location
- if (hasScanner) then
- if (seeOres) then
- canvas.addText({ x = 10, y = 45 }, "Ores: ON")
- local group = canvas3d.create()
- for _, block in ipairs(blocksMap) do
- local color = TARGET_ORES[block.name]
- local box = group.addBox(block.x, block.y, block.z, 1, 1, 1, color)
- box.setDepthTested(false) -- See thru walls
- end
- else
- canvas.addText({ x = 10, y = 45 }, "Ores: OFF")
- end
- end
- if (hasKinetic) then
- if (hover) then
- canvas.addText({ x = 10, y = 55 }, "Hover: ON")
- else
- canvas.addText({ x = 10, y = 55 }, "Hover: OFF")
- end
- end
- if (hasLaser) then
- canvas.addText({ x = 10, y = 25 }, "Laser: " .. tostring(laserStrength))
- end
- -- Compass N/S/E/W
- if (hasIntrospection) then
- --local textYaw = canvas.addText({ x = 10, y = 5 }, tostring(playerData.yaw))
- local NLocation = ((-playerData.yaw/90) * (windowWidth/2)) - windowWidth/2
- local SLocation = ((-playerData.yaw/90) * (windowWidth/2)) + windowWidth/2
- local ELocation = (-playerData.yaw/90) * (windowWidth/2)
- local WLocation = (-playerData.yaw/90) * (windowWidth/2) + windowWidth
- canvas.addText({ x = NLocation, y = 15 }, "N")
- canvas.addText({ x = SLocation, y = 15 }, "S")
- canvas.addText({ x = WLocation, y = 15 }, "W")
- canvas.addText({ x = ELocation, y = 15 }, "E")
- end
- end
- sleep(0.1)
- end
- end
- local function fly()
- while (true) do
- if (hover and hasKinetic) then
- playerData = modules.getMetaOwner()
- if (w) then
- modules.launch(playerData.yaw, playerData.pitch, 1)
- w=false
- else
- local force = 0.25
- if (playerData.motionY < 0) then
- force = 0.4
- end
- if (playerData.isSneaking) then
- force = force/2
- elseif(spacebar) then
- force = force*2
- end
- modules.launch(0, -90, math.min(4, math.abs(force)))
- end
- --sleep(0.1)
- else
- sleep(1)
- end
- end
- end
- local function keyPress()
- while (true) do
- local event, key, is_held = os.pullEvent("key")
- key = keys.getName(key) -- transform key number to word
- --print(key)
- local keyObj = keyMappings[key]
- if (keyObj) then
- keyObj.fun()
- end
- end
- end
- load()
- parallel.waitForAny(update, draw, keyPress, fly)
Advertisement
Add Comment
Please, Sign In to add comment