add wallTool
[df_scaffold.git] / wallbot.lua
blob98588de9b9dd326e725f34f97c8e58ff8af4553d
1 local wall_pos1={x=-1254,y=-4,z=791} --not the exact ones rn
2 local wall_pos2={x=-1454,y=80,z=983}
3 local iwall_pos1={x=-1264,y=-4,z=801}
4 local iwall_pos2={x=-1444,y=80,z=973}
8 local function between(x, y, z) -- x is between y and z (inclusive)
9 return y <= x and x <= z
10 end
13 local function in_cube(tpos,wpos1,wpos2)
14 local xmax=wpos2.x
15 local xmin=wpos1.x
17 local ymax=wpos2.y
18 local ymin=wpos1.y
20 local zmax=wpos2.z
21 local zmin=wpos1.z
22 if wpos1.x > wpos2.x then
23 xmax=wpos1.x
24 xmin=wpos2.x
25 end
26 if wpos1.y > wpos2.y then
27 ymax=wpos1.y
28 ymin=wpos2.y
29 end
30 if wpos1.z > wpos2.z then
31 zmax=wpos1.z
32 zmin=wpos2.z
33 end
34 if between(tpos.x,xmin,xmax) and between(tpos.y,ymin,ymax) and between(tpos.z,zmin,zmax) then
35 return true
36 end
37 return false
38 end
40 local function in_wall(pos)
41 if in_cube(pos,wall_pos1,wall_pos2) and not in_cube(pos,iwall_pos1,iwall_pos2) then
42 return true end
43 return false
44 end
46 scaffold.register_template_scaffold("WallTool", "scaffold_walltool", function(pos)
47 local lp=minetest.localplayer:get_pos()
48 local p1=vector.add(lp,{x=5,y=5,z=5})
49 local p2=vector.add(lp,{x=-5,y=-5,z=-5})
50 local nn=nlist.get_mclnodes()
51 table.insert(nn,'air')
52 local nds,cnt=minetest.find_nodes_in_area(p1,p2,nn,true)
53 for k,v in pairs(nds) do for kk,vv in pairs(v) do
54 if vv and in_wall(vv) then
55 scaffold.place_if_needed({'mcl_core:cobble'},vv)
56 local nd=minetest.get_node_or_nil(vv)
57 if nd and nd.name ~= 'mcl_core:cobble' then
58 scaffold.dig(vv)
59 end
60 end
61 end end
62 end)