Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- direction = "^" -- Arrow pointing towards direction.
- positions = {curX = 0, curZ = 0, curY = 0} -- Positions
- tMap = {} -- Map
- blockTable = {
- {name = "minecraft:stone", color = colors.lightGray, isOre = false, oreColor = colors.black},
- {name = "minecraft:planks", color = colors.brown, isOre = false, oreColor = colors.black},
- {name = "minecraft:grass", color = colors.green, isOre = false, oreColor = colors.black},
- {name = "minecraft:dirt", color = colors.brown, isOre = false, oreColor = colors.black},
- {name = "minecraft:cobblestone", color = colors.lightGray, isOre = false, oreColor = colors.black},
- {name = "minecraft:water", color = colors.blue, isOre = false, oreColor = colors.black},
- {name = "minecraft:flowing_water", color = colors.blue, isOre = false, oreColor = colors.black},
- {name = "minecraft:lava", color = colors.orange, isOre = false, oreColor = colors.black},
- {name = "minecraft:flowing_lava", color = colors.lightGray, isOre = false, oreColor = colors.black},
- {name = "minecraft:sand", color = colors.yellow, isOre = false, oreColor = colors.black},
- {name = "minecraft:gravel", color = colors.pink, isOre = false, oreColor = colors.black},
- {name = "minecraft:gold_ore", color = colors.lightGray, isOre = true, oreColor = colors.yellow},
- {name = "minecraft:iron_ore", color = colors.lightGray, isOre = true, oreColor = colors.white},
- {name = "minecraft:coal_ore", color = colors.lightGray, isOre = true, oreColor = colors.black},
- {name = "minecraft:lapis_ore", color = colors.lightGray, isOre = true, oreColor = colors.blue},
- {name = "minecraft:diamond_ore", color = colors.lightGray, isOre = true, oreColor = colors.lightBlue},
- {name = "minecraft:emerald_ore", color = colors.lightGray, isOre = true, oreColor = colors.lime},
- {name = "minecraft:redstone_ore", color = colors.lightGray, isOre = true, oreColor = colors.red},
- {name = "minecraft:lit_redstone_ore", color = colors.lightGray, isOre = true, oreColor = colors.red}} -- Table for all blocks
- lookingAt = "Unable to discern"
- rednet.open("top") -- Opens rednet
- map = window.create(term.native(),1,1,27,19) -- Creates seperate window
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- function right() -- Turns the arrow right
- if direction == "^" then
- direction = ">"
- elseif direction == ">" then
- direction = "v"
- elseif direction == "v" then
- direction = "<"
- elseif direction == "<" then
- direction = "^"
- end
- end
- function left() -- Turns the arrow left
- if direction == "^" then
- direction = "<"
- elseif direction == "<" then
- direction = "v"
- elseif direction == "v" then
- direction = ">"
- elseif direction == ">" then
- direction = "^"
- end
- end
- function discernDir() -- Finds direction to move
- if direction == "^" then
- positions.curZ = positions.curZ - 1
- elseif direction == ">" then
- positions.curX = positions.curX + 1
- elseif direction == "v" then
- positions.curZ = positions.curZ + 1
- elseif direction == "<" then
- positions.curX = positions.curX - 1
- end
- end
- function lookingZ() -- Finds direction to move
- if direction == "^" then
- local a = positions.curZ + 1
- return positions.curZ - a
- elseif direction == "v" then
- local a = positions.curZ - 1
- return positions.curZ - a
- else
- return 0
- end
- end
- function lookingX() -- Finds direction to move
- if direction == ">" then
- local a = positions.curZ - 1
- return positions.curZ - a
- elseif direction == "<" then
- local a = positions.curX + 1
- return positions.curX - a
- else
- return 0
- end
- end
- function newBlock(X,Y,Color,Layer,isOre,oreColor) -- Creates or overides a block on the map
- for i,v in pairs(tMap) do
- if v.x == X and v.y == Y and v.layer == Layer and v.color ~= Color then
- local template = {
- x = X,
- y = Y,
- color = Color,
- layer = Layer,
- ore = isOre}
- if isOre then
- template.oreColor = oreColor
- end
- table.insert(tMap,template)
- elseif v.x == X and v.y == Y and v.layer == Layer and v.color == Color then
- marked = true
- end
- end
- if not marked then
- local template = {
- x = X,
- y = Y,
- color = Color,
- layer = Layer,
- ore = isOre}
- if isOre then
- template.oreColor = oreColor
- end
- table.insert(tMap,template)
- end
- end
- function redrawMap() -- Redraws the map
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(28,1)
- term.write("X : "..positions.curX)
- term.setCursorPos(28,2)
- term.write("Z : "..positions.curZ)
- term.setCursorPos(28,3)
- term.write("Y : "..positions.curY)
- term.setCursorPos(28,4)
- term.write("Looking at : ")
- term.setCursorPos(29,5)
- term.write(lookingAt)
- map.setBackgroundColor(colors.gray)
- map.clear()
- term.redirect(map)
- for i,v in pairs(tMap) do
- if v.x - positions.curX > -14 and v.x - positions.curX < 28 and v.y - positions.curZ > -10 and v.y - positions.curZ < 20 and positions.curY == v.layer + 1 then
- paintutils.drawPixel(v.x - positions.curX + 14, v.y - positions.curZ + 10, colors.black)
- end
- if v.x - positions.curX > -14 and v.x - positions.curX < 28 and v.y - positions.curZ > -10 and v.y - positions.curZ < 20 and positions.curY == v.layer then
- paintutils.drawPixel(v.x - positions.curX + 14, v.y - positions.curZ + 10, v.color)
- if v.ore == true then
- map.setCursorPos(v.x - positions.curX + 14, v.y - positions.curZ + 10)
- map.setTextColor(v.oreColor)
- map.write("#")
- end
- end
- end
- term.setCursorPos(14,10)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- term.write(direction)
- term.redirect(term.native())
- end
- function turtleError() -- Creates an error screen for the map
- map.setBackgroundColor(colors.blue)
- map.clear()
- local text = "Turtle disconnected"
- local w,h = map.getSize()
- map.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5)) -- Positions text in the middle of the map
- map.setTextColor(colors.white)
- map.write(text)
- end
- function logBlock() -- Logs found block into the database
- local id, msg = rednet.receive("gladius")
- if msg ~= "Nothing" then
- lookingAt = msg
- for i,v in pairs(blockTable) do
- if msg == v.name then
- newBlock(positions.curX + lookingX(), positions.curZ + lookingZ(), v.color, positions.curY, v.isOre, v.oreColor)
- end
- end
- else
- lookingAt = "Nothing"
- end
- redrawMap()
- end
- redrawMap()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.up then
- rednet.broadcast("forward","gladius")
- discernDir()
- logBlock()
- elseif key == keys.down then
- rednet.broadcast("backward","gladius")
- right()
- right()
- logBlock()
- elseif key == keys.left then
- rednet.broadcast("left","gladius")
- left()
- logBlock()
- elseif key == keys.right then
- rednet.broadcast("right","gladius")
- right()
- logBlock()
- elseif key == keys.leftShift then
- rednet.broadcast("down","gladius")
- positions.curY = positions.curY - 1
- logBlock()
- elseif key == keys.space then
- rednet.broadcast("up","gladius")
- positions.curY = positions.curY + 1
- logBlock()
- end
- redrawMap()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement