From 32cf25dc17ac0df52c0a5533c86d535b521a20f8 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 3 Feb 2021 03:53:47 +0400 Subject: [PATCH 1/6] Fix spawn point search --- mods/PLAYER/mcl_spawn/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index a3a461f7d..5baa461f6 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -425,13 +425,13 @@ end minetest.register_on_respawnplayer(mcl_spawn.spawn) function mcl_spawn.shadow_worker() - if #biome_ids > 1 then - for _, biome_name in pairs(biomes_white_list) do - table.insert(biome_ids, minetest.get_biome_id(biome_name)) - end - end if not searched then searched = true + if #biome_ids < 1 then + for _, biome_name in pairs(biomes_white_list) do + table.insert(biome_ids, minetest.get_biome_id(biome_name)) + end + end mcl_spawn.search() minetest.log("action", "[mcl_spawn] Started world spawn point search") end -- 2.40.1 From e8f8d4cb1eb119de7ff16ffded97a453b5c51689 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 3 Feb 2021 04:22:02 +0400 Subject: [PATCH 2/6] Better fix spawn point search (follow-up 32cf25dc17ac0df52c0a5533c86d535b521a20f8) --- mods/PLAYER/mcl_spawn/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 5baa461f6..11dd60e67 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -225,6 +225,11 @@ end -- Spawn position search local function next_biome() + if #biome_ids < 1 then + for _, biome_name in pairs(biomes_white_list) do + table.insert(biome_ids, minetest.get_biome_id(biome_name)) + end + end while check <= checks do local biome_data = minetest.get_biome_data(cp) -- Sometimes biome_data is nil @@ -427,11 +432,6 @@ minetest.register_on_respawnplayer(mcl_spawn.spawn) function mcl_spawn.shadow_worker() if not searched then searched = true - if #biome_ids < 1 then - for _, biome_name in pairs(biomes_white_list) do - table.insert(biome_ids, minetest.get_biome_id(biome_name)) - end - end mcl_spawn.search() minetest.log("action", "[mcl_spawn] Started world spawn point search") end -- 2.40.1 From 9492f276fc28702716cf2ec85097c93f73d45c53 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 3 Feb 2021 16:08:00 +0400 Subject: [PATCH 3/6] Make mcl_spawn compatible with flat mapgen with superflat MCL2 option (but better to have some trees still) --- mods/PLAYER/mcl_spawn/init.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 11dd60e67..103a0c3d9 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -227,8 +227,16 @@ end local function next_biome() if #biome_ids < 1 then for _, biome_name in pairs(biomes_white_list) do - table.insert(biome_ids, minetest.get_biome_id(biome_name)) + local biome_id = minetest.get_biome_id(biome_name) + if biome_id then + table.insert(biome_ids, biome_id) + end end + if #biome_ids < 1 then + minetest.log("warning", "[mcl_spawn] No suitable biomes found") + return false + end + minetest.log("action", "[mcl_spawn] Suitable biomes found: "..tostring(#biome_ids)) end while check <= checks do local biome_data = minetest.get_biome_data(cp) -- 2.40.1 From 13a9dbed3ed4fae3cb93a0bffa0a4fd13934c775 Mon Sep 17 00:00:00 2001 From: kay27 Date: Thu, 4 Feb 2021 03:41:43 +0400 Subject: [PATCH 4/6] Fix https://git.minetest.land/MineClone2/MineClone2/issues/1052 (stop searching trees after 10+ attempts) --- mods/PLAYER/mcl_spawn/init.lua | 72 ++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 103a0c3d9..5a4f3d634 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -45,6 +45,8 @@ local start_pos = minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 8 -- Table of suitable biomes local biome_ids = {} +local no_trees_area_counter = 0 + -- Bed spawning offsets local node_search_list = { @@ -233,8 +235,22 @@ local function next_biome() end end if #biome_ids < 1 then - minetest.log("warning", "[mcl_spawn] No suitable biomes found") - return false + next_pos() + if math.abs(cp.x) > spawn_limit or math.abs(cp.z) > spawn_limit then + check = checks + 1 + minetest.log("warning", "[mcl_spawn] No white-listed biomes found - search stopped by overlimit") + return false + end + check = check + 1 + cp.y = minetest.get_spawn_level(cp.x, cp.z) or start_pos.y + if cp.y then + wsp = {x = cp.x, y = cp.y, z = cp.z} + minetest.log("warning", "[mcl_spawn] No white-listed biomes found - using current") + return true + else + minetest.log("warning", "[mcl_spawn] No white-listed biomes found and spawn level is nil - please define start_pos to continue") + return false + end end minetest.log("action", "[mcl_spawn] Suitable biomes found: "..tostring(#biome_ids)) end @@ -277,16 +293,56 @@ local function ecb_search_continue(blockpos, action, calls_remaining, param) local nodes = minetest.find_nodes_in_area_under_air(emerge_pos1, emerge_pos2, node_groups_white_list) minetest.log("verbose", "[mcl_spawn] Data emerge callback: "..minetest.pos_to_string(wsp).." - "..tostring(nodes and #nodes) .. " node(s) found under air") if nodes then - local trees = get_trees(emerge_pos1, emerge_pos2) - if trees then + if no_trees_area_counter >= 0 then + local trees = get_trees(emerge_pos1, emerge_pos2) + if trees and #trees > 0 then + no_trees_area_counter = 0 + if attempts_to_find_pos * 3 < #nodes then + -- random + for i=1, attempts_to_find_pos do + wsp = nodes[math.random(1,#nodes)] + if wsp then + wsp.y = wsp.y + 1 + if good_for_respawn(wsp) and can_find_tree(wsp, trees) then + minetest.log("action", "[mcl_spawn] Dynamic world spawn randomly determined to be "..minetest.pos_to_string(wsp)) + searched = true + success = true + return + end + end + end + else + -- in a sequence + for i=1, math.min(#nodes, attempts_to_find_pos) do + wsp = nodes[i] + if wsp then + wsp.y = wsp.y + 1 + if good_for_respawn(wsp) and can_find_tree(wsp, trees) then + minetest.log("action", "[mcl_spawn] Dynamic world spawn determined to be "..minetest.pos_to_string(wsp)) + searched = true + success = true + return + end + end + end + end + else + no_trees_area_counter = no_trees_area_counter + 1 + if no_trees_area_counter > 10 then + minetest.log("verbose", "[mcl_spawn] More than 10 times no trees at all! Won't search trees next 200 calls") + no_trees_area_counter = -200 + end + end + else -- seems there are no trees but we'll check it later, after next 200 calls + no_trees_area_counter = no_trees_area_counter + 1 if attempts_to_find_pos * 3 < #nodes then -- random for i=1, attempts_to_find_pos do wsp = nodes[math.random(1,#nodes)] if wsp then wsp.y = wsp.y + 1 - if good_for_respawn(wsp) and can_find_tree(wsp, trees) then - minetest.log("action", "[mcl_spawn] Dynamic world spawn determined to be "..minetest.pos_to_string(wsp)) + if good_for_respawn(wsp) then + minetest.log("action", "[mcl_spawn] Dynamic world spawn randomly determined to be "..minetest.pos_to_string(wsp) .. " (no trees)") searched = true success = true return @@ -299,8 +355,8 @@ local function ecb_search_continue(blockpos, action, calls_remaining, param) wsp = nodes[i] if wsp then wsp.y = wsp.y + 1 - if good_for_respawn(wsp) and can_find_tree(wsp, trees) then - minetest.log("action", "[mcl_spawn] Dynamic world spawn determined to be "..minetest.pos_to_string(wsp)) + if good_for_respawn(wsp) then + minetest.log("action", "[mcl_spawn] Dynamic world spawn determined to be "..minetest.pos_to_string(wsp) .. " (no trees)") searched = true success = true return -- 2.40.1 From 95b0a27213538967eed831bbf2c552c8222dd41f Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Fri, 5 Feb 2021 10:36:48 +0000 Subject: [PATCH 5/6] Fix Mobs not taking knockback on the Y-axis --- mods/ENTITIES/mcl_mobs/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 430c97166..4ef270ec4 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3091,7 +3091,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) self.object:set_velocity({ x = dir.x * kb, - y = dir.y * kb + up, + y = dir.y * kb + up * 2, z = dir.z * kb }) -- 2.40.1 From fa3e37c6045129336971ee4234619c56a210dfb9 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 5 Feb 2021 16:34:49 +0400 Subject: [PATCH 6/6] A mob does not drop XP unless it dies within 5 s of an attack registered as a player hit, https://git.minetest.land/MineClone2/MineClone2/issues/1021#issuecomment-13894 --- mods/ENTITIES/mcl_mobs/api.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 430c97166..641529c54 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -789,15 +789,15 @@ local check_for_death = function(self, cause, cmi_cause) local puncher = cmi_cause.puncher if puncher then wielditem = puncher:get_wielded_item() - - if mod_experience and ((not self.child) or self.type ~= "animal") then - mcl_experience.throw_experience(self.object:get_pos(), math.random(self.xp_min, self.xp_max)) - end end end local cooked = mcl_burning.is_burning(self.object) or mcl_enchanting.has_enchantment(wielditem, "fire_aspect") local looting = mcl_enchanting.get_enchantment(wielditem, "looting") item_drop(self, cooked, looting) + + if mod_experience and ((not self.child) or self.type ~= "animal") and (minetest.get_us_time() - self.xp_timestamp <= 5000000) then + mcl_experience.throw_experience(self.object:get_pos(), math.random(self.xp_min, self.xp_max)) + end end end @@ -2921,10 +2921,16 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) return end - -- is mob protected? - if self.protected and hitter:is_player() - and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then - return + local is_player = hitter:is_player() + + if is_player then + -- is mob protected? + if self.protected and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then + return + end + + -- set/update 'drop xp' timestamp if hitted by player + self.xp_timestamp = minetest.get_us_time() end @@ -2933,7 +2939,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) local punch_interval = 1.4 -- exhaust attacker - if mod_hunger and hitter:is_player() then + if mod_hunger and is_player then mcl_hunger.exhaust(hitter:get_player_name(), mcl_hunger.EXHAUST_ATTACK) end @@ -3082,7 +3088,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) if hitter then luaentity = hitter:get_luaentity() end - if hitter and hitter:is_player() then + if hitter and is_player then local wielditem = hitter:get_wielded_item() kb = kb + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") elseif luaentity and luaentity._knockback then @@ -3719,6 +3725,7 @@ minetest.register_entity(name, { hp_max = scale_difficulty(def.hp_max, 10, 1), xp_min = def.xp_min or 0, xp_max = def.xp_max or 0, + xp_timestamp = 0, breath_max = def.breath_max or 15, breathes_in_water = def.breathes_in_water or false, physical = true, -- 2.40.1