View difference between Paste ID: QKpyWq06 and c9Y1nDY2
SHOW: | | - or go back to the newest paste.
1
local ccCoord = {}
2
ccCoord["x"], ccCoord["y"], ccCoord["z"] = commands.getBlockPosition()
3
local blockData = {}
4
local facing = ""
5
local fx = 0
6
local fz = 0
7
local swapxz = false
8
9
function getFacing()
10
	local directions = {"unknown", "north", "south", "west", "east"}
11
	local blockInfo = commands.getBlockInfo( commands.getBlockPosition() )
12
	print( "My facing is ", directions[ blockInfo.metadata ], "." )
13
	facing = directions[ blockInfo.metadata ]
14
	--print(facing)
15
end
16
17
function setModifiers()
18
	if facing == "west" then
19
		fx = 1
20
		fz = 1
21
		swapxz = true
22
	elseif facing == "east" then
23
		fx = -1
24
		fz = -1
25
		swapxz = true
26
	elseif facing == "north" then
27
		fx = -1
28
		fz = 1
29
		swapxz = false
30
	elseif facing == "south" then
31
		fx = 1
32
		fz = -1
33
		swapxz = false
34
	end
35
end
36
37
38
function saveBlock(x,y,z)
39
	local data = commands.getBlockInfo(x,y,z)
40
	if not blockData[x] then
41
		blockData[x] = {}
42
	end
43
	if not blockData[x][y] then
44
		blockData[x][y] = {}
45
	end
46
	if not blockData[x][y][z] then
47
		blockData[x][y][z] = {}
48
	end
49
	blockData[x][y][z]["name"] = data["name"]
50
	blockData[x][y][z]["metadata"] = data["metadata"]
51
end 
52
53
function writeBlocks()
54
	file = io.open("blocks", "w")
55
	file:write(textutils.serialize(blockData))
56
	file:close()
57
end
58
59
function saveSpace(xStart, xEnd, yStart, yEnd, zStart, zEnd)
60
	--print(xStart..xEnd..yStart..yEnd..zStart..zEnd)
61
	for x = xStart, xEnd,fx do
62
		for y = yStart, yEnd do
63
			for z = zStart, zEnd,fz do
64
				saveBlock(x,y,z)
65
			end
66
		end
67
	end
68
	writeBlocks()
69
end
70
71
function relXYZnoswap(x,y,z)
72
	--print("NoSwap: "..ccCoord["x"]+(x+1)*fx..":"..ccCoord["y"]+(y)..":"..ccCoord["z"]+(z+1)*fz)
73
	return ccCoord["x"]+(x+1)*fx, ccCoord["y"]+(y), ccCoord["z"]+(z+1)*fz
74
end
75
76
function relXYZ(x,y,z)
77
	if not swapxz then
78
		return ccCoord["x"]+(x+1)*fx, ccCoord["y"]+(y), ccCoord["z"]+(z+1)*fz
79
	else
80
		return ccCoord["x"]+(z+1)*fz, ccCoord["y"]+(y), ccCoord["z"]+(x+1)*fx
81
	end
82
end
83
84
function saveBoardArea()
85
	print("Saving board area, this may take a moment....")
86
	local x,y,z,x2,y2,z2
87
	x,y,z = relXYZnoswap(0,-1,0)
88
	x2,y2,z2 = relXYZnoswap(9,5,9)
89
	print("Save: "..x..":"..x2..", "..y..":"..y2..", "..z..":"..z2)
90
	saveSpace(x,x2,y,y2,z,z2)
91
	print("Saving board area complete.")
92
end
93
94
getFacing()
95
setModifiers()
96
saveBoardArea()