Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- px=-143
- py=-3
- sx=40
- sy=40
- surface=game.get_surface(1)
- function clear(px,py,sx,sy)
- for k,v in pairs(surface.find_entities_filtered({area = {{px-1, py-1}, {px+sx+1, py+sy+1}}, name= "coal"})) do
- v.destroy()
- end
- for k,v in pairs(surface.find_entities_filtered({area = {{px-1, py-1}, {px+sx+1, py+sy+1}}, name= "quartz"})) do
- v.destroy()
- end
- end
- function put(i,n,x,y)
- surface.create_entity({name=i, amount=n, position={x, y}})
- end
- function check(i,x,y)
- el=#surface.find_entities_filtered({area = {{x, y}, {x+1, y+1}}, name=i})
- return el
- end
- function near(patt,x,y)
- c=0
- for n=-1,1 do
- for m=-1,1 do
- c=c+patt[(y+m+sy-1)%sy+1][(x+n+sx-1)%sx+1]
- end
- end
- c=c-patt[y][x]
- return c
- end
- function cycle(patt,x,y)
- s=patt[y][x]
- n=near(patt,x,y)
- if (s==1 and n==2) or (n==3) then
- return 1
- else
- return 0
- end
- end
- patt={}
- for y=1,sy do
- row={}
- for x=1,sx do
- row[x]=check("quartz",x+px,y+py)
- if check("wooden-chest",x+px,y+py)==1 then
- surface.find_entities_filtered({area = {{x+px, y+py}, {x+px+1, y+py+1}}, name="wooden-chest"})[1].destroy()
- row[x]=1-row[x]
- end
- patt[y]=row
- end
- end
- pattT={}
- for y=1,sy do
- row={}
- for x=1,sx do
- row[x]=cycle(patt,x,y)
- end
- pattT[y]=row
- end
- clear(px,py,sx,sy)
- for y=1,sy do
- for x=1,sx do
- if pattT[y][x]==1 then
- put("quartz",1000,x+px,y+py)
- else
- put("coal",1000,x+px,y+py)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment