From 35f07a8b66e94e4f4e5161f2867daace1eff859d Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 25 Jun 2021 03:53:58 +0400 Subject: [PATCH] [mineclone5] Put mob flow code at its right place, fix unloaded player spawn rechech --- .../mcl_mobs/api/mob_functions/ai.lua | 14 -- .../mcl_mobs/api/mob_functions/flow_lib.lua | 155 +++++++++--------- .../mcl_mobs/api/mob_functions/movement.lua | 30 ++-- mods/MAPGEN/mcl_structures/init.lua | 6 +- mods/PLAYER/mcl_spawn/init.lua | 2 +- 5 files changed, 100 insertions(+), 107 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index 88ce3274b..af006d1cc 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -10,7 +10,6 @@ local minetest_get_node = minetest.get_node local minetest_line_of_sight = minetest.line_of_sight local minetest_get_node_light = minetest.get_node_light local minetest_registered_nodes = minetest.registered_nodes -local flow = mobs.get_flowing_dir local DOUBLE_PI = math.pi * 2 local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125 @@ -1013,19 +1012,6 @@ function mobs.mob_step(self, dtime) 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 if self.pause_timer > 0 then self.pause_timer = self.pause_timer - dtime diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/flow_lib.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/flow_lib.lua index aa64bfb4e..79271275a 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/flow_lib.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/flow_lib.lua @@ -1,78 +1,77 @@ ---this is from https://github.com/HybridDog/builtin_item/blob/e6dfd9dce86503b3cbd1474257eca5f6f6ca71c2/init.lua#L50 -local -minetest,vector,math,pairs,minetest_get_node,vector_subtract,minetest_registered_nodes -= -minetest,vector,math,pairs,minetest.get_node,vector.subtract,minetest.registered_nodes - -local tab -local n -local function get_nodes(pos) - tab,n = {},1 - for i = -1,1,2 do - for _,p in pairs({ - {x=pos.x+i, y=pos.y, z=pos.z}, - {x=pos.x, y=pos.y, z=pos.z+i} - }) do - tab[n] = {p, minetest_get_node(p)} - n = n+1 - end - end - return tab -end - - -local data -local param2 -local nd -local par2 -local name -local tmp -local c_node -function mobs.get_flowing_dir(pos) - c_node = minetest_get_node(pos).name - if c_node ~= "mcl_core:water_flowing" and c_node ~= "mcl_core:water" then - return nil - end - data = get_nodes(pos) - param2 = minetest_get_node(pos).param2 - if param2 > 7 then - return nil - end - if c_node == "mcl_core:water" then - for _,i in pairs(data) do - nd = i[2] - name = nd.name - par2 = nd.param2 - if name == "mcl_core:water_flowing" and par2 == 7 then - return(vector_subtract(i[1],pos)) - end - end - end - for _,i in pairs(data) do - nd = i[2] - name = nd.name - par2 = nd.param2 - if name == "mcl_core:water_flowing" and par2 < param2 then - return(vector_subtract(i[1],pos)) - end - end - for _,i in pairs(data) do - nd = i[2] - name = nd.name - par2 = nd.param2 - if name == "mcl_core:water_flowing" and par2 >= 11 then - return(vector_subtract(i[1],pos)) - end - end - for _,i in pairs(data) do - nd = i[2] - name = nd.name - par2 = nd.param2 - tmp = minetest_registered_nodes[name] - if tmp and not tmp.walkable and name ~= "mcl_core:water_flowing" and name ~= "mcl_core:water" then - return(vector_subtract(i[1],pos)) - end - end - - return nil -end +--this is from https://github.com/HybridDog/builtin_item/blob/e6dfd9dce86503b3cbd1474257eca5f6f6ca71c2/init.lua#L50 +local +pairs, minetest_get_node, vector_subtract, minetest_registered_nodes += +pairs, minetest.get_node, vector.subtract, minetest.registered_nodes + +local function get_nodes(pos) + local x, y, z = pos.x, pos.y, pos.z + local node1, node2, node3, node4 = + {x = x - 1, y = y, z = z }, + {x = x, y = y, z = z - 1}, + {x = x + 1, y = y, z = z }, + {x = x, y = y, z = z + 1} + local nodes = { + {node1, minetest_get_node(node1)}, + {node2, minetest_get_node(node2)}, + {node3, minetest_get_node(node3)}, + {node4, minetest_get_node(node4)} + } + return nodes +end + +local data +local param2 +local nd +local par2 +local name +local tmp +local c_node +function mobs.get_flowing_dir(pos) + c_node = minetest_get_node(pos).name + if c_node ~= "mcl_core:water_flowing" and c_node ~= "mcl_core:water" then + return nil + end + data = get_nodes(pos) + param2 = minetest_get_node(pos).param2 + if param2 > 7 then + return nil + end + if c_node == "mcl_core:water" then + for _,i in pairs(data) do + nd = i[2] + name = nd.name + par2 = nd.param2 + if name == "mcl_core:water_flowing" and par2 == 7 then + return(vector_subtract(i[1],pos)) + end + end + end + for _,i in pairs(data) do + nd = i[2] + name = nd.name + par2 = nd.param2 + if name == "mcl_core:water_flowing" and par2 < param2 then + return(vector_subtract(i[1],pos)) + end + end + for _,i in pairs(data) do + nd = i[2] + name = nd.name + par2 = nd.param2 + if name == "mcl_core:water_flowing" and par2 >= 11 then + return(vector_subtract(i[1],pos)) + end + end + for _,i in pairs(data) do + nd = i[2] + name = nd.name + par2 = nd.param2 + tmp = minetest_registered_nodes[name] + if tmp and not tmp.walkable and name ~= "mcl_core:water_flowing" and name ~= "mcl_core:water" then + return(vector_subtract(i[1],pos)) + end + end + + return nil +end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua index d9698a0a7..b10d794ea 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -13,6 +13,8 @@ local DEFAULT_JUMP_HEIGHT = 5 local DEFAULT_FLOAT_SPEED = 4 local DEFAULT_CLIMB_SPEED = 3 +local flow = mobs.get_flowing_dir + mobs.stick_in_cobweb = function(self) local current_velocity = self.object:get_velocity() @@ -43,20 +45,24 @@ mobs.float = function(self) local current_velocity = self.object:get_velocity() - local goal_velocity = { - 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 + local new_velocity_addition = DEFAULT_FLOAT_SPEED - current_velocity.y --smooths out mobs a bit - if vector.length(new_velocity_addition) >= 0.0001 then - self.object:add_velocity(new_velocity_addition) + if new_velocity_addition >= 0.0001 then + 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 diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 8efdd91b1..533c9cab0 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -187,8 +187,6 @@ function mcl_structures.generate_igloo(pos, rotation, pr) if real_depth <= 6 then return success 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 for y=1, real_depth-1 do 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 -- Place basement 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 return success end diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 113a4d27f..e50d8f08a 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -500,7 +500,7 @@ function mcl_spawn.shadow_worker() if success then 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 success = false minetest.log("action", "[mcl_spawn] World spawn position isn't safe anymore: "..minetest.pos_to_string(wsp))