[mineclone5] Put mob flow code at its right place, fix unloaded player spawn rechech

This commit is contained in:
kay27 2021-06-25 03:53:58 +04:00
parent 7cf49c2cfd
commit 35f07a8b66
5 changed files with 100 additions and 107 deletions

View File

@ -10,7 +10,6 @@ local minetest_get_node = minetest.get_node
local minetest_line_of_sight = minetest.line_of_sight local minetest_line_of_sight = minetest.line_of_sight
local minetest_get_node_light = minetest.get_node_light local minetest_get_node_light = minetest.get_node_light
local minetest_registered_nodes = minetest.registered_nodes local minetest_registered_nodes = minetest.registered_nodes
local flow = mobs.get_flowing_dir
local DOUBLE_PI = math.pi * 2 local DOUBLE_PI = math.pi * 2
local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125 local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125
@ -1013,19 +1012,6 @@ function mobs.mob_step(self, dtime)
end end
end end
--mobs flow from Crafter
local pos = self.object:get_pos()
if pos then
local flow_dir = flow(pos)
if flow_dir then
flow_dir = vector.multiply(flow_dir,10)
local vel = self.object:get_velocity()
local acceleration = vector.new(flow_dir.x-vel.x,flow_dir.y-vel.y,flow_dir.z-vel.z)
acceleration = vector.multiply(acceleration, 0.01)
self.object:add_velocity(acceleration)
end
end
--mob is stunned after being hit --mob is stunned after being hit
if self.pause_timer > 0 then if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime self.pause_timer = self.pause_timer - dtime

View File

@ -1,78 +1,77 @@
--this is from https://github.com/HybridDog/builtin_item/blob/e6dfd9dce86503b3cbd1474257eca5f6f6ca71c2/init.lua#L50 --this is from https://github.com/HybridDog/builtin_item/blob/e6dfd9dce86503b3cbd1474257eca5f6f6ca71c2/init.lua#L50
local local
minetest,vector,math,pairs,minetest_get_node,vector_subtract,minetest_registered_nodes pairs, minetest_get_node, vector_subtract, minetest_registered_nodes
= =
minetest,vector,math,pairs,minetest.get_node,vector.subtract,minetest.registered_nodes pairs, minetest.get_node, vector.subtract, minetest.registered_nodes
local tab local function get_nodes(pos)
local n local x, y, z = pos.x, pos.y, pos.z
local function get_nodes(pos) local node1, node2, node3, node4 =
tab,n = {},1 {x = x - 1, y = y, z = z },
for i = -1,1,2 do {x = x, y = y, z = z - 1},
for _,p in pairs({ {x = x + 1, y = y, z = z },
{x=pos.x+i, y=pos.y, z=pos.z}, {x = x, y = y, z = z + 1}
{x=pos.x, y=pos.y, z=pos.z+i} local nodes = {
}) do {node1, minetest_get_node(node1)},
tab[n] = {p, minetest_get_node(p)} {node2, minetest_get_node(node2)},
n = n+1 {node3, minetest_get_node(node3)},
end {node4, minetest_get_node(node4)}
end }
return tab return nodes
end end
local data
local data local param2
local param2 local nd
local nd local par2
local par2 local name
local name local tmp
local tmp local c_node
local c_node function mobs.get_flowing_dir(pos)
function mobs.get_flowing_dir(pos) c_node = minetest_get_node(pos).name
c_node = minetest_get_node(pos).name if c_node ~= "mcl_core:water_flowing" and c_node ~= "mcl_core:water" then
if c_node ~= "mcl_core:water_flowing" and c_node ~= "mcl_core:water" then return nil
return nil end
end data = get_nodes(pos)
data = get_nodes(pos) param2 = minetest_get_node(pos).param2
param2 = minetest_get_node(pos).param2 if param2 > 7 then
if param2 > 7 then return nil
return nil end
end if c_node == "mcl_core:water" then
if c_node == "mcl_core:water" then for _,i in pairs(data) do
for _,i in pairs(data) do nd = i[2]
nd = i[2] name = nd.name
name = nd.name par2 = nd.param2
par2 = nd.param2 if name == "mcl_core:water_flowing" and par2 == 7 then
if name == "mcl_core:water_flowing" and par2 == 7 then return(vector_subtract(i[1],pos))
return(vector_subtract(i[1],pos)) end
end end
end end
end for _,i in pairs(data) do
for _,i in pairs(data) do nd = i[2]
nd = i[2] name = nd.name
name = nd.name par2 = nd.param2
par2 = nd.param2 if name == "mcl_core:water_flowing" and par2 < param2 then
if name == "mcl_core:water_flowing" and par2 < param2 then return(vector_subtract(i[1],pos))
return(vector_subtract(i[1],pos)) end
end end
end for _,i in pairs(data) do
for _,i in pairs(data) do nd = i[2]
nd = i[2] name = nd.name
name = nd.name par2 = nd.param2
par2 = nd.param2 if name == "mcl_core:water_flowing" and par2 >= 11 then
if name == "mcl_core:water_flowing" and par2 >= 11 then return(vector_subtract(i[1],pos))
return(vector_subtract(i[1],pos)) end
end end
end for _,i in pairs(data) do
for _,i in pairs(data) do nd = i[2]
nd = i[2] name = nd.name
name = nd.name par2 = nd.param2
par2 = nd.param2 tmp = minetest_registered_nodes[name]
tmp = minetest_registered_nodes[name] if tmp and not tmp.walkable and name ~= "mcl_core:water_flowing" and name ~= "mcl_core:water" then
if tmp and not tmp.walkable and name ~= "mcl_core:water_flowing" and name ~= "mcl_core:water" then return(vector_subtract(i[1],pos))
return(vector_subtract(i[1],pos)) end
end end
end
return nil
return nil end
end

View File

@ -13,6 +13,8 @@ local DEFAULT_JUMP_HEIGHT = 5
local DEFAULT_FLOAT_SPEED = 4 local DEFAULT_FLOAT_SPEED = 4
local DEFAULT_CLIMB_SPEED = 3 local DEFAULT_CLIMB_SPEED = 3
local flow = mobs.get_flowing_dir
mobs.stick_in_cobweb = function(self) mobs.stick_in_cobweb = function(self)
local current_velocity = self.object:get_velocity() local current_velocity = self.object:get_velocity()
@ -43,20 +45,24 @@ mobs.float = function(self)
local current_velocity = self.object:get_velocity() local current_velocity = self.object:get_velocity()
local goal_velocity = { local new_velocity_addition = DEFAULT_FLOAT_SPEED - current_velocity.y
x = 0,
y = DEFAULT_FLOAT_SPEED,
z = 0,
}
local new_velocity_addition = vector.subtract(goal_velocity, current_velocity)
new_velocity_addition.x = 0
new_velocity_addition.z = 0
--smooths out mobs a bit --smooths out mobs a bit
if vector.length(new_velocity_addition) >= 0.0001 then if new_velocity_addition >= 0.0001 then
self.object:add_velocity(new_velocity_addition) self.object:add_velocity({x = 0, y = new_velocity_addition, z = 0})
end
--mobs flow from Crafter
local pos = self.object:get_pos()
if pos then
local flow_dir = flow(pos)
if flow_dir then
flow_dir = vector.multiply(flow_dir,10)
local vel = self.object:get_velocity()
local acceleration = vector.new(flow_dir.x-vel.x,flow_dir.y-vel.y,flow_dir.z-vel.z)
acceleration = vector.multiply(acceleration, 0.1)
self.object:add_velocity(acceleration)
end
end end
end end

View File

@ -187,8 +187,6 @@ function mcl_structures.generate_igloo(pos, rotation, pr)
if real_depth <= 6 then if real_depth <= 6 then
return success return success
end end
-- Place hidden trapdoor
minetest.set_node(tpos, {name="mcl_doors:trapdoor", param2=20+minetest.dir_to_facedir(dir)}) -- TODO: more reliable param2
-- Generate ladder to basement -- Generate ladder to basement
for y=1, real_depth-1 do for y=1, real_depth-1 do
set_brick({x=tpos.x-1,y=tpos.y-y,z=tpos.z }) set_brick({x=tpos.x-1,y=tpos.y-y,z=tpos.z })
@ -199,6 +197,10 @@ function mcl_structures.generate_igloo(pos, rotation, pr)
end end
-- Place basement -- Place basement
mcl_structures.generate_igloo_basement(bpos, rotation, pr) mcl_structures.generate_igloo_basement(bpos, rotation, pr)
-- Place hidden trapdoor
minetest.after(5, function(tpos, dir)
minetest.set_node(tpos, {name="mcl_doors:trapdoor", param2=20+minetest.dir_to_facedir(dir)}) -- TODO: more reliable param2
end, tpos, dir)
end end
return success return success
end end

View File

@ -500,7 +500,7 @@ function mcl_spawn.shadow_worker()
if success then if success then
local wsp_node = minetest.get_node(wsp) local wsp_node = minetest.get_node(wsp)
if not (wsp_node and wsp_node.name == "ignore") if wsp_node and (minetest.compare_block_status(wsp, "loaded") or minetest.compare_block_status(wsp, "active"))
and ((not good_for_respawn(wsp)) or ((no_trees_area_counter >= 0) and not can_find_tree(wsp))) then and ((not good_for_respawn(wsp)) or ((no_trees_area_counter >= 0) and not can_find_tree(wsp))) then
success = false success = false
minetest.log("action", "[mcl_spawn] World spawn position isn't safe anymore: "..minetest.pos_to_string(wsp)) minetest.log("action", "[mcl_spawn] World spawn position isn't safe anymore: "..minetest.pos_to_string(wsp))