Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = require("blib")
- local map = {x = 1, y = 0, z = 1, xf = 0, yf = 1}
- local Length
- local Width
- local Height
- local data
- 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 MapBackward()
- turtle.back()
- 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"
- -- }
- function PlaceBlock()
- 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)
- local blockName = data[key]
- if blockName ~= nil then
- if m.SelectItem(blockName) then
- turtle.place()
- end
- else
- return
- end
- end
- function PlaceBlockDown()
- local fx = map.x
- local fy = map.y
- local fz = map.z - 1
- local key = tostring(fx) .. "," .. tostring(fy) .. "," .. tostring(fz)
- local blockName = data[key]
- if blockName ~= nil then
- if m.SelectItem(blockName) then
- turtle.placeDown()
- end
- else
- return
- end
- end
- --- Building Process ---
- function Start()
- MapTurnRight()
- MapTurnRight() -- The turtle starts outside the square, as such, it enters at the start, and the Y index
- MapBackward() -- 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
- MapBackward()
- PlaceBlock()
- 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()
- MapBackward()
- PlaceBlock()
- MapTurnLeft()
- lastTurn = "Left"
- else -- odd columns (start is 1 btw) turn right!
- MapTurnRight()
- MapBackward()
- PlaceBlock()
- MapTurnRight()
- lastTurn = "Right"
- end
- end
- end
- MapUp()
- PlaceBlockDown()
- MapTurnRight()
- MapTurnRight()
- end
- return 1
- end
- function Main()
- local response
- print("Welcome to the Minecraft file building program")
- print("please enter file you would like to build from")
- local FileName = read()
- local f = fs.open(FileName, "r") -- add nil safety
- local serializedData = f.readAll()
- data = textutils.unserialize(serializedData)
- Length = data.Y
- Width = data.X
- Height = data.Z
- Start()
- print("Finished!")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement