[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,25 +1,24 @@
--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 n
local function get_nodes(pos) local function get_nodes(pos)
tab,n = {},1 local x, y, z = pos.x, pos.y, pos.z
for i = -1,1,2 do local node1, node2, node3, node4 =
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} {x = x + 1, y = y, z = z },
}) do {x = x, y = y, z = z + 1}
tab[n] = {p, minetest_get_node(p)} local nodes = {
n = n+1 {node1, minetest_get_node(node1)},
{node2, minetest_get_node(node2)},
{node3, minetest_get_node(node3)},
{node4, minetest_get_node(node4)}
}
return nodes
end end
end
return tab
end
local data local data
local param2 local param2

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))