update wall tool

master
cora 2021-08-30 16:59:44 +02:00
parent 585e755e23
commit 5210cd17af
1 changed files with 170 additions and 1 deletions

View File

@ -64,6 +64,78 @@ local function in_wall(pos)
return false
end
local function iwall_node(pos)
if pos.y>80 or pos.y < -2 then return false end
local dir=ws.getdir()
if dir == "north" then
if pos.z == 973 then
if pos.y % 2 == 0 then
if pos .x % 2 == 0 then
return "mcl_core:obsidian"
else
return "mcl_core:stonebrick"
end
else
if pos .x % 2 == 0 then
return "mcl_core:stonebrick"
else
return "mcl_core:obsidian"
end
end
end
elseif dir == "east" then
if pos.x == -1264 then
if pos.y % 2 == 0 then
if pos .z % 2 == 0 then
return "mcl_core:stonebrick"
else
return "mcl_core:obsidian"
end
else
if pos .z % 2 == 0 then
return "mcl_core:obsidian"
else
return "mcl_core:stonebrick"
end
end
end
elseif dir == "south" then
if pos.z == 801 then
if pos.y % 2 == 0 then
if pos .x % 2 == 0 then
return "mcl_core:obsidian"
else
return "mcl_core:stonebrick"
end
else
if pos .x % 2 == 0 then
return "mcl_core:stonebrick"
else
return "mcl_core:obsidian"
end
end
end
elseif dir == "west" then
if pos.x == -1444 then
if pos.y % 2 == 0 then
if pos .z % 2 == 0 then
return "mcl_core:stonebrick"
else
return "mcl_core:obsidian"
end
else
if pos.z % 2 == 0 then
return "mcl_core:obsidian"
else
return "mcl_core:stonebrick"
end
end
end
end
return false
end
local lwltime=0
scaffold.register_template_scaffold("WallTool", "scaffold_walltool", function(pos)
@ -80,6 +152,7 @@ scaffold.register_template_scaffold("WallTool", "scaffold_walltool", function(po
local i=1
local nds=minetest.find_nodes_near(lp,10,{'air'})
for k,vv in pairs(nds) do
local iwn=iwall_node(vv)
if vv and in_wall(vv) then
if i > 8 then return end
i = i + 1
@ -89,7 +162,103 @@ scaffold.register_template_scaffold("WallTool", "scaffold_walltool", function(po
else
ws.place(vv,{cobble})
end
elseif vv and iwn then
if i > 8 then return end
i = i + 1
if nd and nd.name ~= iwn and nd.name ~= 'air' then
ws.dig(vv)
else
ws.place(vv,iwn)
end
end
end
end)
ws.rg('AWalltool','Bots','scaffold_awalltool',function()
--local nds=minetest.find_nodes_near_except(ws.dircoord(0,0,0),6,{'mcl_core:cobble'})
local nds=minetest.find_nodes_near(ws.dircoord(0,0,0),7,{'air'})
local rt=true
for k,v in ipairs(nds) do
if in_wall(v) then
rt=false
end
end
minetest.settings:set_bool('continuous_forward',rt)
end,function() end, function()end, {'scaffold_walltool','afly_snap'})
local function find_closest_safe(pos)
local odst=500
local res=pos
local poss=minetest.find_nodes_near(pos,10,{'air'})
for k,v in ipairs(poss) do
local dst=vector.distance(pos,v)
if not in_wall(v) and dst < odst then
odst=dst
res=vector.add(v,vector.new(0,-1,0))
end
end
return res
end
local function wallbot_find(range)
local lp=ws.dircoord(0,0,0)
local nds=minetest.find_nodes_near_except(lp,range,{'mcl_core:cobble'})
local odst=500
local tg=nil
res=nil
for k,v in ipairs(nds) do
if in_wall(v) then
local dst=vector.distance(lp,v)
if odst > dst then odst=dst res=v end
end
end
if res then find_closest_safe(res)
else return false end
end
local function random_iwall()
math.randomseed(os.clock())
local x=math.random(0,90)
local y=math.random(10,70)
local z=math.random(0,90)
local rpos={x=-1254 - x,y=y,z=791 + z}
end
local wallbot_state=0
local wallbot_target=nil
ws.rg('WallBot','Bots','scaffold_wallbot',function()
local nds=nil
if not wallbot_target then wallbot_state=0 end
if wallbot_state == 0 then --searching
wallbot_target=wallbot_find(79)
if wallbot_target then
wallbot_state=2
else
wallbot_target=random_iwall()
wallbot_state=1
end
elseif wallbot_state == 1 then --flying - searching
if incremental_tp.tpactive then return end
if vector.distance(ws.dircoord(0,0,0),wallbot_target) < 10 then
minetest.after(5,function() wallbot_state=0 end)
return
end
incremental_tp.tp(wallbot_target,1,1)
elseif wallbot_state == 2 then --flying - target
if incremental_tp.tpactive then return end
if vector.distance(ws.dircoord(0,0,0),wallbot_target) < 10 then
wallbot_state=3
return
end
incremental_tp.tp(wallbot_target,1,1)
elseif wallbot_state == 3 then --filling
if not wallbot_find(10) then
wallbot_state=0
return
end
else
wallbot_state=0
end
end,function() wallbot_state=0 end,function() end,{'scaffold_walltool'})