View difference between Paste ID: MFtApsZ2 and PpKs50m3
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("libstruct")
2
b=libstruct
3
a=aware
4
args = {...}
5
6
if #args < 1 then
7
	error("Arguments: <name>")
8
end
9
10
t=b.load(args[1]..".3d")
11
height=t["height"]
12
width=t["width"]
13
depth=t["depth"]
14
15
height=((height+1)*2)-1
16
width=((width+1)*2)-1
17
depth=((depth+1)*2)-1
18
19
endblock=t["endblock"]
20
parwidth=(width %2 == 0) -- width er partall
21
moveleft=true
22
a.setposition("start")
23
24
function refill(r)
25
	if r == nil  then 
26
		print("refill got r == nil")
27
		return
28
	end
29
	if r == 0  then return end
30
	if turtle.getItemCount(r) > 5 then return end
31
	if not (endblock==16) then
32
	        turtle.select(r)
33-
         print("Looking for " .. r .. " from " .. endblock+1 .. " to 16")
33+
         	print("Looking for " .. r .. " from " .. endblock+1 .. " to 16")
34
	        for i=endblock+1,16 do
35
	                if turtle.compareTo(i) then
36
                         print("Found in " .. i)
37
	                        turtle.select(i)
38
	                        turtle.transferTo(r)
39
	                        free=turtle.getItemSpace(r)
40
				turtle.select(r)
41-
	                turtle.select(r)
41+
		                if free == 0 then
42-
	                if free == 0 then
42+
        	                	print("free == 0 ")
43-
                        print("free == 0 ")
43+
	                	        break
44-
	                        break
44+
	        	        end
45
			else
46
				print(r .. " was not in " .. i)	
47
	                end
48-
        if turtle.getItemCount(r) < 2 then
48+
49
	        end
50-
		while (turtle.getItemCount(r) < 2) do
50+
51
        if turtle.getItemCount(r) <= 5 then
52
		print("--Sleeping while waiting for refill for slot " .. r)	
53
		while (turtle.getItemCount(r) <= 5) do
54
	        	os.sleep(15)
55
	        end
56
	end
57
end
58
59
function line()
60
        print("Building line")
61
        for d=0,depth do
62
                pos = a.getposition("current")
63
                print("Pos: h" .. pos[3]*-1 .. "-w" .. pos[1] .. "-d" .. pos[2])
64
		block = t[math.floor((pos[3]*-1)/2)][math.floor(pos[1]/2)][math.floor(pos[2]/2)]
65
		refill(block)
66
		b.place(block)
67
                if(d<depth) then
68
                        a.df()
69
                end
70
        end
71
end
72
73
 
74
function turn()
75
        if(moveleft) then
76
                print("Moving left")
77
                a.l()
78
                a.df()
79
                a.l()
80
        else
81
                print("Moving right")
82
                a.r()
83
                a.df()
84
                a.r()
85
        end
86
        moveleft = not moveleft
87
end
88
89
function layer()
90
	print("Building layer")
91
	for w=0,width do
92
		line()
93
	        if(w<width) then
94
		        turn()
95
	        end
96
	end
97
end
98
99
-- we build from the bottom up
100
for h=0,height-1 do
101
	a.dd()
102
end
103
104
for h=0,height do
105
	layer()
106
	if not (h == height) then
107
		a.du()
108
		b.t180()
109
		if parwidth then
110
			if h%2 == 0 then
111
				turnleft=false
112
			else
113
				turnleft=true  
114
			end
115
		else
116
			turnleft=true
117
		end
118
	end 
119
end
120
121
print("Finised, going home")
122
a.goto(a.getposition("start"))
123
b.awarecleanup()