Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = require("blib")
- local lastTurn = "Left"
- local FileName = ""
- local Length
- local Width
- local Height
- local map = {x = 1, y = 0, z = 1, xf = 0, yf = 1}
- function MapTurnRight()
- turtle.turnRight()
- if map.xf == 1 then
- map.xf = 0
- map.yf = -1
- elseif map.xf == -1 then
- map.xf = 0
- map.yf = 1
- elseif map.yf == 1 then
- map.yf = 0
- map.xf = 1
- elseif map.yf == -1 then
- map.yf = 0
- map.xf = -1
- end
- end
- function MapTurnLeft()
- turtle.turnLeft()
- if map.xf == 1 then
- map.xf = 0
- map.yf = 1
- elseif map.xf == -1 then
- map.xf = 0
- map.yf = -1
- elseif map.yf == 1 then
- map.yf = 0
- map.xf = -1
- elseif map.yf == -1 then
- map.yf = 0
- map.xf = 1
- end
- end
- function MapForward()
- turtle.forward()
- if map.xf == 1 then
- map.x = map.x + 1
- elseif map.xf == -1 then
- map.x = map.x - 1
- elseif map.yf == 1 then
- map.y = map.y + 1
- elseif map.yf == -1 then
- map.y = map.y - 1
- end
- end
- function MapUp()
- turtle.up()
- map.z = map.z + 1
- end
- -- Example ANY File
- -- {
- -- Dimensions
- -- "X" : 2
- -- "Y" : 2
- -- "Z" : 2
- -- List of blocks needed
- -- "list" : {"name" : 1, "cobblestone" : 5, "name again" : 7} etc. for k, v in pairs(list) or whatever
- -- "1,1,1" : "minecraft:cobblestone"
- -- "2,1,1" : "Something else blockname idk"
- -- }
- local scan = {}
- function PlaceBlock()
- local success, data = turtle.inspect()
- local fx = map.x
- local fy = map.y
- local fz = map.z
- if(map.xf ~= 0) then
- fx = fx + map.xf
- else
- fy = fy + map.yf
- end
- local key = tostring(fx) .. "," .. tostring(fy) .. "," .. tostring(fz)
- print("key: " .. key)
- if success then
- scan[key] = data.name
- print("val: " .. data.name)
- else
- scan[key] = nil
- print("val: nil")
- end
- turtle.dig()
- end
- function ScanAndDigUp()
- local success, data = turtle.inspectUp()
- local fx = map.x
- local fy = map.y
- local fz = map.z + 1
- local key = tostring(fx) .. "," .. tostring(fy) .. "," .. tostring(fz)
- print("key: " .. key)
- if success then
- scan[key] = data.name
- print("val: " .. data.name)
- else
- scan[key] = nil
- print("val: nil")
- end
- turtle.digUp()
- end
- function dump(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. dump(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
- end
- --- Scanning Process ---
- function Start()
- PlaceBlock() -- The turtle starts outside the square, as such, it enters at the start, and the Y index
- MapForward() -- is actually decremented by one, since mining on the x axis will manage one block off each
- -- level change
- for z = 1, Height do
- for x = 1, Width do -- starting length cuts one turn off, but not one column off. see below
- for y = 1, Length - 1 do -- width cuts one length down off the next
- -- check for fuel
- if(not m.CheckFuel(10)) then
- return Shutdown("Out of Fuel!")
- end
- -- check if inventory is full
- if(reqChests == true) then
- if(m.InventoryFull() == true) then
- if(m.DumpItemsChest() == false) then
- return Shutdown("Out of chests!")
- end
- end
- end
- PlaceBlock()
- MapForward()
- end
- if( Width - x ~= 0) then -- Technically on the last column, we want to continue forward so we can't do 'Width - 1', but don't turn into the next column
- if(lastTurn == "Right") then -- if we're on an even column, turn left
- MapTurnLeft()
- PlaceBlock()
- MapForward()
- MapTurnLeft()
- lastTurn = "Left"
- else -- odd columns (start is 1 btw) turn right!
- MapTurnRight()
- PlaceBlock()
- MapForward()
- MapTurnRight()
- lastTurn = "Right"
- end
- end
- end
- if( Height - z ~= 0 ) then
- ScanAndDigUp()
- MapUp()
- MapTurnRight()
- MapTurnRight()
- end
- end
- return 1
- end
- function Main()
- local response
- print("Welcome to the Minecraft file scanning program")
- print("please enter the X, Y, and Z lengths of the area you'd like to scan")
- print("Length: ")
- Length = read()
- scan.Y = Length
- print("Width: ")
- Width = read()
- scan.X = Width
- print("Height: ")
- Height = read()
- scan.Z = Height
- print("What do you want to call this build file? (e.g. Sand_Castle, Cool-Cannon)")
- print("(Careful! it will overwrite existing files!)")
- FileName = read()
- Start()
- local data = textutils.serialize(scan)
- print(data)
- print("Data written!")
- local f = fs.open(FileName .. ".b", "w")
- f.write(data)
- f.close()
- print("Finished!")
- end
- Main() -- testing post request lol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement