Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local NAME
- --local NAME = "SillyPutty"
- --local NAME = "NetherJedi"
- local ORES =
- {
- diamond = "diamond_ore",
- gold = "gold_ore",
- emerald = "emerald_ore",
- coal = "coal_ore",
- iron_ingot = "iron_ore",
- lapis = "lapis_ore",
- redstone = "redstone_ore",
- quartz = "quartz_ore",
- glowstone_dust = "glowstone"
- }
- local COLOR = "0xFF00FF"
- local TRANS = "10"
- local SCALE = 1
- User = function()
- local p = peripheral.wrap("back")
- local s = p.sense()
- for i=1,#s do
- if s[i].x == 0 and
- s[i].y == 0 and
- s[i].z == 0 then
- return s[i].id,s[i].name
- end
- end
- end
- Held = function()
- local p = peripheral.wrap("back")
- local meta = p.getMetaByName(NAME)
- if meta.heldItem then
- return meta.heldItem.getMetadata().name
- else
- return nil
- end
- end
- LoadOreList = function(oreListFile)
- oreList = {}
- f = fs.open(oreListFile,"r")
- if f then
- oreList = textutils.unserialise(
- f.readAll())
- else
- print("Warning: Ore list not found")
- end
- return oreList
- end
- Colormap = function(oreList,item)
- map = {}
- for i=1,#oreList do
- if oreList[i].active then
- map[oreList[i].blockname] =
- {color = oreList[i].color,
- name = oreList[i].name}
- -- tonumber(oreList[i].color .. TRANS)}
- if oreList[i].metadata then
- map[oreList[i].blockname].metadata =
- oreList[i].metadata
- --print(textutils.serialise(oreList[i]))
- --sleep(1)
- end
- end
- end
- --held item
- if item then
- local nickname = item
- local colon = string.find(item,":")
- if colon then
- nickname = string.sub(item,colon+1,-1)
- else
- item = "minecraft:" .. nickname
- end
- local ore = ORES[nickname]
- if ore then
- nickname = ore
- item = "minecraft:" .. ore
- end
- --print(item)
- map[item] =
- {
- color = COLOR,
- name = nickname
- }
- --tonumber(COLOR .. "00")}
- end
- return map
- end
- DoScan = function(colorMap)
- local p = peripheral.wrap("back")
- local data = p.scan()
- local results = {}
- --local nickname = item
- --local colon = string.find(item,":")
- --if colon then
- -- nickname = string.sub(item,colon+1,-1)
- --else
- -- item = "minecraft:" .. nickname
- --end
- --local ore = ORES[nickname]
- --if ore then
- -- nickname = ore
- -- item = "minecraft:" .. ore
- --end
- ----print(item)
- for i=1,#data do
- local v = vector.new(data[i].x,data[i].y,data[i].z)
- data[i].dist = v:length()
- --if data[i].name == "minecraft:lava" then
- -- print(textutils.serialise(data[i]))
- --end
- local x = colorMap[data[i].name]
- if x then
- if x.metadata == nil or
- data[i].state.level == x.metadata then
- results[#results+1] = data[i]
- results[#results].color =
- x.color
- results[#results].name =
- x.name
- end
- --else if x then
- -- print(textutils.serialise(colorMap))
- end
- end
- return results
- end
- --FaceBlock = function(b)
- -- if b and b.x and b.y and b.z then
- -- local x,y,z = b.x,b.y,b.z
- -- local rho = math.sqrt(x*x + z*z)
- -- local pitch = math.atan2(-y,rho)
- -- local yaw = math.atan2(-x,z)
- -- p.look(math.deg(yaw),math.deg(pitch))
- -- end
- --end
- --FindNearest = function(data)
- -- if type(data) ~= "table" or not #data then
- -- return nil
- -- end
- --
- -- local nearest = data[1]
- -- for i=2,#data do
- -- if data[i].dist < nearest.dist then
- -- nearest = data[i]
- -- end
- -- end
- -- return nearest
- --end
- DrawBlocks = function(data,canvas,offset)
- if not offset then
- offset = {x=0,y=0,z=0}
- end
- --local p = peripheral.wrap("back")
- --local glasses3D = p.canvas3d()
- --glasses3D.clear()
- --canvas.clear()
- if type(data) ~= "table" or not #data then
- return nil
- end
- --local offset = player.withinBlock
- --local canvas = glasses3D.create(
- -- {-offset.x,-offset.y,-offset.z})
- for i=1,#data do
- local b1 = canvas.addBox(
- data[i].x + offset.x,
- data[i].y + offset.y,
- data[i].z + offset.z,
- 1,1,1,
- tonumber(data[i].color .. TRANS))
- --0x00FF0010)
- b1.setDepthTested(false)
- end
- return canvas
- end
- --local function IsMoving(metadata)
- -- if metadata and metadata.motionX and
- -- metadata.motionX == 0 and
- -- metadata.motionZ == 0 and
- -- metadata.motionY > -0.08 and
- -- metadata.motionY <= 0.01 then
- -- print("not moving")
- -- print(metadata.motionX)
- -- return false
- -- else
- -- print("moving")
- -- return true
- -- end
- --end
- DrawSummary = function(data)
- local p = peripheral.wrap("back")
- local canvas = p.canvas()
- canvas.clear()
- if type(data) ~= "table" or not #data then
- return nil
- end
- local x = {}
- for i=1,#data do
- if x[data[i].name] then
- x[data[i].name].num =
- x[data[i].name].num + 1
- else --make new table entry
- x[data[i].name] =
- {
- num = 1,
- color = data[i].color
- }
- end
- end
- y = 1
- for k,v in pairs(x) do
- --k is the block name
- --v is table with color and num
- canvas.addText(
- {x=1,y=y},
- "" .. v.num .. " " .. k,
- --tonumber("0xFFFFFF" .. "FF"),
- tonumber(v.color .. "FF"),
- size)
- y = y + 8*SCALE
- end
- end
- --Program starts here
- ID,NAME = User()
- local oreList = LoadOreList("OreList.txt")
- local p = peripheral.wrap("back")
- local glasses3D = p.canvas3d()
- glasses3D.clear()
- local home --origin of canvas
- local offset = {} --used to make canvas
- local canvas --the canvas
- local oldCanvas --canvas to be cleared
- local pos --gps position
- local lastPos --previous gps position
- while true do
- pos = gps.locate()
- if (pos-lastPos):dist() < 0.001 then
- end
- if not canvas or not IsMoving(meta) then
- print("New Canvas")
- home = vector.new(gps.locate())
- offset.x = home.x - math.floor(home.x)
- offset.y = home.y - math.floor(home.y)
- offset.z = home.z - math.floor(home.z)
- home.x = math.floor(home.x)
- home.y = math.floor(home.y)
- home.z = math.floor(home.z)
- canvas = glasses3D.create(
- {-offset.x,
- -offset.y,
- -offset.z})
- end
- --obtain scan results
- colorMap = Colormap(oreList,Held())
- local results = DoScan(colorMap)
- --get corresponding gps data
- pos = vector.new(gps.locate())
- lastPos = vector.new(pos.x,pos.y,pos.z)
- pos.x = math.floor(pos.x) - home.x
- pos.y = math.floor(pos.y) - home.y
- pos.z = math.floor(pos.z) - home.z
- --local results = DoScan(colorMap)
- if lastCanvas then
- pcall(lastCanvas.clear)
- end
- suc = pcall(DrawBlocks,results,canvas,pos)
- lastCanvas = canvas
- if suc then
- DrawSummary(results)
- elseif not suc then
- pcall(canvas.clear)
- canvas = nil
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement