From 4bc6210fda27ebc2e938d10f60b1aabd2e7532b4 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 1 Aug 2022 00:04:52 +0200 Subject: [PATCH 01/11] disable smooth rotation --- mods/ENTITIES/mcl_mobs/api.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6b91f2f878..16f4343b15 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -311,7 +311,10 @@ end -- set and return valid yaw local set_yaw = function(self, yaw, delay, dtime) - + if true then + self.object:set_yaw(yaw) + return yaw + end if not yaw or yaw ~= yaw then yaw = 0 end From f629a6ba9d5e1b9bf92de55b47cf705d721aa3c7 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 1 Aug 2022 00:36:33 +0200 Subject: [PATCH 02/11] Only zombies attack villagers --- mods/ENTITIES/mcl_mobs/api.lua | 3 ++- mods/ENTITIES/mobs_mc/villager_zombie.lua | 1 + mods/ENTITIES/mobs_mc/zombie.lua | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 16f4343b15..6f3a4f13c7 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1949,7 +1949,7 @@ local monster_attack = function(self) -- find specific mob to attack, failing that attack player/npc/animal if specific_attack(self.specific_attack, name) - and (type == "player" or type == "npc" + and (type == "player" or ( type == "npc" and self.attack_npcs ) or (type == "animal" and self.attack_animals == true)) then p = player:get_pos() @@ -4033,6 +4033,7 @@ minetest.register_entity(name, { dogshoot_count_max = def.dogshoot_count_max or 5, dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5), attack_animals = def.attack_animals or false, + attack_npcs = def.attack_npcs or false, specific_attack = def.specific_attack, runaway_from = def.runaway_from, owner_loyal = def.owner_loyal, diff --git a/mods/ENTITIES/mobs_mc/villager_zombie.lua b/mods/ENTITIES/mobs_mc/villager_zombie.lua index cd0e892152..cbb4fa1d3b 100644 --- a/mods/ENTITIES/mobs_mc/villager_zombie.lua +++ b/mods/ENTITIES/mobs_mc/villager_zombie.lua @@ -133,6 +133,7 @@ mcl_mobs:register_mob("mobs_mc:villager_zombie", { view_range = 16, fear_height = 4, harmed_by_heal = true, + attack_npcs = true, }) mcl_mobs:spawn_specific( diff --git a/mods/ENTITIES/mobs_mc/zombie.lua b/mods/ENTITIES/mobs_mc/zombie.lua index 4bb77e5f9a..5ae7e922f6 100644 --- a/mods/ENTITIES/mobs_mc/zombie.lua +++ b/mods/ENTITIES/mobs_mc/zombie.lua @@ -101,6 +101,7 @@ local zombie = { self.object:set_properties({visual_size = self.visual_size}) self.base_size = self.visual_size end, + attack_npcs = true, } mcl_mobs:register_mob("mobs_mc:zombie", zombie) From 6d7e583db8704d1f9cbeb1b3a14de86130a33d91 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 1 Aug 2022 00:39:49 +0200 Subject: [PATCH 03/11] Vindicators attack villagers too --- mods/ENTITIES/mobs_mc/villager_vindicator.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENTITIES/mobs_mc/villager_vindicator.lua b/mods/ENTITIES/mobs_mc/villager_vindicator.lua index 0ed6118997..4b7173d36c 100644 --- a/mods/ENTITIES/mobs_mc/villager_vindicator.lua +++ b/mods/ENTITIES/mobs_mc/villager_vindicator.lua @@ -38,6 +38,7 @@ mcl_mobs:register_mob("mobs_mc:vindicator", { walk_velocity = 1.2, run_velocity = 2.4, attack_type = "dogfight", + attack_npcs = true, drops = { {name = "mcl_core:emerald", chance = 1, From 8c3ada1e11982695afd1f8c8e8cd04329bf0bbf8 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 1 Aug 2022 05:35:47 +0200 Subject: [PATCH 04/11] Fix spawn command --- mods/ENTITIES/mcl_mobs/spawning.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 4a7b678856..c429cf1095 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -488,6 +488,25 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min) return o end +function mcl_mobs.spawn(pos,id) + local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id] + if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then + return false + end + return minetest.add_entity(pos, def.name) +end + +minetest.register_chatcommand("spawn_mob",{ + privs = { debug = true }, + func = function(n,param) + local pos = minetest.get_player_by_name(n):get_pos() + if mcl_mobs.spawn(pos,param) then + return true, param.." spawned at "..minetest.pos_to_string(pos) + end + return false, "Couldn't spawn "..param + end +}) + if mobs_spawn then local perlin_noise From 97cab0d91faae4dc1a67ade4cca4a39052c8843b Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 9 Sep 2022 22:41:04 +0200 Subject: [PATCH 05/11] Use api spawn command for natural spawn --- mods/ENTITIES/mcl_mobs/spawning.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index c429cf1095..ff86061db0 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -481,7 +481,7 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min) if mob.type_of_spawning == "water" then sp = get_water_spawn(sp) end - o = minetest.add_entity(sp,mob.name) + o = mcl_mobs.spawn(sp,mob.name) if o then dbg_spawn_succ = dbg_spawn_succ + 1 end end end @@ -560,7 +560,7 @@ if mobs_spawn then object = spawn_group(spawning_position,mob_def,{minetest.get_node(vector.offset(spawning_position,0,-1,0)).name},spawn_in_group,spawn_in_group_min) minetest.log("action", "A group of mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) else - object = minetest.add_entity(spawning_position, mob_def.name) + object = mcl_mobs.spawn(spawning_position, mob_def.name) minetest.log("action", "Mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) end From 3093462ee3a59e5602e113f086ad0e24dc7a87bb Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 9 Sep 2022 23:31:02 +0200 Subject: [PATCH 06/11] Fix despawning --- mods/ENTITIES/mcl_mobs/api.lua | 18 +++++++++++------- mods/ENTITIES/mcl_mobs/spawning.lua | 17 ++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6f3a4f13c7..a9c36bfbb5 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3406,21 +3406,20 @@ end -- get entity staticdata local mob_staticdata = function(self) ---[[ + -- remove mob when out of range unless tamed if remove_far and self.can_despawn and self.remove_ok and ((not self.nametag) or (self.nametag == "")) and self.lifetimer <= 20 then - - minetest.log("action", "Mob "..name.." despawns in mob_staticdata at "..minetest.pos_to_string(self.object.get_pos(), 1)) + minetest.log("action", "Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos())) mcl_burning.extinguish(self.object) self.object:remove() - return ""-- nil + return "remove"-- nil end ---]] + self.remove_ok = true self.attack = nil self.following = nil @@ -3456,6 +3455,11 @@ local mob_activate = function(self, staticdata, def, dtime) return end + if staticdata == "remove" then + mcl_burning.extinguish(self.object) + self.object:remove() + return + end -- load entity variables local tmp = minetest.deserialize(staticdata) @@ -3623,6 +3627,7 @@ end -- main mob function local mob_step = function(self, dtime) + self.lifetimer = self.lifetimer - dtime check_item_pickup(self) check_aggro(self,dtime) if not self.fire_resistant then @@ -3836,12 +3841,11 @@ local mob_step = function(self, dtime) and ((not self.nametag) or (self.nametag == "")) and self.state ~= "attack" and self.following == nil then - - self.lifetimer = self.lifetimer - dtime if self.despawn_immediately or self.lifetimer <= 0 then minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) mcl_burning.extinguish(self.object) self.object:remove() + return elseif self.lifetimer <= 10 then if math.random(10) < 4 then self.despawn_immediately = true diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index ff86061db0..36d59be8d1 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -466,6 +466,15 @@ local function spawn_check(pos,spawn_def) return false end +function mcl_mobs.spawn(pos,id) + local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id] + if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then + return false + end + return minetest.add_entity(pos, def.name) +end + + local function spawn_group(p,mob,spawn_on,group_max,group_min) if not group_min then group_min = 1 end local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on) @@ -488,13 +497,7 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min) return o end -function mcl_mobs.spawn(pos,id) - local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id] - if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then - return false - end - return minetest.add_entity(pos, def.name) -end +mcl_mobs.spawn_group = spawn_group minetest.register_chatcommand("spawn_mob",{ privs = { debug = true }, From 186059ae13549683437ce003d538386b5c366374 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Fri, 9 Sep 2022 20:30:26 -0600 Subject: [PATCH 07/11] spawn_mob logging and pillager npc attack --- mods/ENTITIES/mcl_mobs/spawning.lua | 3 ++- mods/ENTITIES/mobs_mc/pillager.lua | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 36d59be8d1..fda76026a4 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -504,7 +504,8 @@ minetest.register_chatcommand("spawn_mob",{ func = function(n,param) local pos = minetest.get_player_by_name(n):get_pos() if mcl_mobs.spawn(pos,param) then - return true, param.." spawned at "..minetest.pos_to_string(pos) + return true, param.." spawned at "..minetest.pos_to_string(pos), + minetest.log("action", n.." spawned "..param.." at "..minetest.pos_to_string(pos)) end return false, "Couldn't spawn "..param end diff --git a/mods/ENTITIES/mobs_mc/pillager.lua b/mods/ENTITIES/mobs_mc/pillager.lua index c90aa38213..37122aa186 100644 --- a/mods/ENTITIES/mobs_mc/pillager.lua +++ b/mods/ENTITIES/mobs_mc/pillager.lua @@ -41,6 +41,7 @@ pillager = { fear_height = 4, arrow = "mcl_bows:arrow_entity", attack_type = "dogshoot", -- Alternate punching/shooting + attack_npcs = true, reach = 0, -- Punching max distance damage = 0, -- Punching damage dogshoot_switch = 1, -- Start of shooting From 786cea122d09067e396197ec01895efa0e81441a Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 13 Sep 2022 13:15:57 +0200 Subject: [PATCH 08/11] Remove some unsused settings from mcl_mobs --- mods/ENTITIES/mcl_mobs/api.lua | 9 --------- mods/ENTITIES/mcl_mobs/spawning.lua | 5 +++-- settingtypes.txt | 4 ---- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a9c36bfbb5..9fa48b718b 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1,4 +1,3 @@ - -- API for Mobs Redo: MineClone 2 Edition (MRM) mcl_mobs = {} @@ -14,12 +13,6 @@ local FLOP_HOR_SPEED = 1.5 local ENTITY_CRAMMING_MAX = 24 local CRAMMING_DAMAGE = 3 -local MOB_CAP = {} -MOB_CAP.hostile = 70 -MOB_CAP.passive = 10 -MOB_CAP.ambient = 15 -MOB_CAP.water = 15 - -- Localize local S = minetest.get_translator("mcl_mobs") @@ -55,8 +48,6 @@ local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= fa local remove_far = true local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0 local show_health = false -local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 64) -local mobs_spawn_chance = tonumber(minetest.settings:get("mobs_spawn_chance") or 2.5) -- Shows helpful debug info above each mob local mobs_debug = minetest.settings:get_bool("mobs_debug", false) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index fda76026a4..8a48aebf99 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -38,7 +38,7 @@ local mob_cap = { --do mobs spawn? local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false - +local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false local noise_params = { offset = 0, @@ -456,7 +456,8 @@ local function spawn_check(pos,spawn_def) and (spawn_def.check_position and spawn_def.check_position(pos) or true) and (not is_farm_animal(spawn_def.name) or is_grass) and (spawn_def.type_of_spawning ~= "water" or is_water) - and not is_bedrock then + and not spawn_protected or not minetest.is_protected(s, "") + and not is_bedrock --only need to poll for node light if everything else worked local gotten_light = get_node_light(pos) if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then diff --git a/settingtypes.txt b/settingtypes.txt index 75053092fe..577e4491db 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -76,10 +76,6 @@ mcl_enable_skin_customization (Enable player skin customization) bool true # This setting is only read at startup. mobs_spawn (Spawn mobs naturally) bool true -# Controls the overall amount of mobs that spawn. The higher the number, -# the less often mobs will spawn. This does not affect mob spawners. -mobs_spawn_chance (Mob spawn chance) float 2.5 0.0 - # If enabled, only peaceful mobs will appear naturally. This does not # affect mob spawners. # This setting is only read at startup. From 51e244fe35d7948d6ae5c214b723e1062687057c Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 13 Sep 2022 13:23:29 +0200 Subject: [PATCH 09/11] Make logging of mob spawning configurable --- mods/ENTITIES/mcl_mobs/api.lua | 9 +++++++-- mods/ENTITIES/mcl_mobs/spawning.lua | 14 ++++++++++---- settingtypes.txt | 3 +++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9fa48b718b..d899a02acf 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -51,6 +51,7 @@ local show_health = false -- Shows helpful debug info above each mob local mobs_debug = minetest.settings:get_bool("mobs_debug", false) +local spawn_logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) -- Peaceful mode message so players will know there are no monsters if minetest.settings:get_bool("only_peaceful_mobs", false) then @@ -3404,7 +3405,9 @@ local mob_staticdata = function(self) and self.remove_ok and ((not self.nametag) or (self.nametag == "")) and self.lifetimer <= 20 then - minetest.log("action", "Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos())) + if spawn_logging then + minetest.log("action", "[mcl_mobs] Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos())) + end mcl_burning.extinguish(self.object) self.object:remove() @@ -3833,7 +3836,9 @@ local mob_step = function(self, dtime) and self.state ~= "attack" and self.following == nil then if self.despawn_immediately or self.lifetimer <= 0 then - minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) + if spawn_logging then + minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) + end mcl_burning.extinguish(self.object) self.object:remove() return diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 8a48aebf99..810f9df4fb 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -39,6 +39,7 @@ local mob_cap = { --do mobs spawn? local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false +local logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) local noise_params = { offset = 0, @@ -456,8 +457,8 @@ local function spawn_check(pos,spawn_def) and (spawn_def.check_position and spawn_def.check_position(pos) or true) and (not is_farm_animal(spawn_def.name) or is_grass) and (spawn_def.type_of_spawning ~= "water" or is_water) - and not spawn_protected or not minetest.is_protected(s, "") - and not is_bedrock + and ( not spawn_protected or not minetest.is_protected(s, "") ) + and not is_bedrock then --only need to poll for node light if everything else worked local gotten_light = get_node_light(pos) if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then @@ -562,11 +563,16 @@ if mobs_spawn then --everything is correct, spawn mob local object if spawn_in_group and ( mob_type ~= "monster" or math.random(5) == 1 ) then + if logging then + minetest.log("action", "[mcl_mobs] A group of mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) + end object = spawn_group(spawning_position,mob_def,{minetest.get_node(vector.offset(spawning_position,0,-1,0)).name},spawn_in_group,spawn_in_group_min) - minetest.log("action", "A group of mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) + else + if logging then + minetest.log("action", "[mcl_mobs] Mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) + end object = mcl_mobs.spawn(spawning_position, mob_def.name) - minetest.log("action", "Mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) end diff --git a/settingtypes.txt b/settingtypes.txt index 577e4491db..5f80766538 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -182,3 +182,6 @@ mcl_enable_fapples (Enable swiftness on enchanted golden apples) bool true [Debugging] # If enabled, this will show the itemstring of an item in the description. mcl_item_id_debug (Item ID Debug) bool false + +#Log mob spawning and despawning events +mcl_logging_mobs_spawn (Log Mob Spawning) bool true From 87d4640ca18ce3af15b894b6d9f340582ce56829 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 13 Sep 2022 13:53:17 +0200 Subject: [PATCH 10/11] mcl_mobs: actually use the localized functions not that it actually gains *a lot* --- mods/ENTITIES/mcl_mobs/api.lua | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index d899a02acf..23bcbf37f3 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -29,6 +29,7 @@ local max = math.max local atann = math.atan local random = math.random local floor = math.floor +local ceil = math.ceil local atan = function(x) if not x or x ~= x then @@ -38,7 +39,6 @@ local atan = function(x) end end - -- Load settings local damage_enabled = minetest.settings:get_bool("enable_damage") local disable_blood = minetest.settings:get_bool("mobs_disable_blood") @@ -147,7 +147,7 @@ local mob_sound = function(self, soundname, is_opinion, fixed_pitch) pitch = base_pitch end -- randomize the pitch a bit - pitch = pitch + math.random(-10, 10) * 0.005 + pitch = pitch + random(-10, 10) * 0.005 end minetest.sound_play(sound, { object = self.object, @@ -280,7 +280,7 @@ local function update_roll(self) local cbox = table.copy(self.collisionbox) local acbox = self.object:get_properties().collisionbox - if math.abs(cbox[2] - acbox[2]) > 0.1 then + if abs(cbox[2] - acbox[2]) > 0.1 then was_Fleckenstein = true end @@ -315,7 +315,7 @@ local set_yaw = function(self, yaw, delay, dtime) if delay == 0 then if self.shaking and dtime then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime + yaw = yaw + (random() * 2 - 1) * 5 * dtime end self.object:set_yaw(yaw) update_roll(self) @@ -584,7 +584,7 @@ local damage_effect = function(self, damage) -- damage particles if (not disable_blood) and damage > 0 then - local amount_large = math.floor(damage / 2) + local amount_large = floor(damage / 2) local amount_small = damage % 2 local pos = self.object:get_pos() @@ -710,7 +710,7 @@ local item_drop = function(self, cooked, looting_level) end if do_common_looting then - num = num + math.floor(math.random(0, looting_level) + 0.5) + num = num + floor(random(0, looting_level) + 0.5) end if num > 0 then @@ -819,7 +819,7 @@ local check_for_death = function(self, cause, cmi_cause) item_drop(self, cooked, looting) if ((not self.child) or self.type ~= "animal") and (minetest.get_us_time() - self.xp_timestamp <= 5000000) then - mcl_experience.throw_xp(self.object:get_pos(), math.random(self.xp_min, self.xp_max)) + mcl_experience.throw_xp(self.object:get_pos(), random(self.xp_min, self.xp_max)) end end end @@ -1200,7 +1200,7 @@ local do_env_damage = function(self) end if drowning then - self.breath = math.max(0, self.breath - 1) + self.breath = max(0, self.breath - 1) effect(pos, 2, "bubble.png", nil, nil, 1, nil) if self.breath <= 0 then @@ -1218,7 +1218,7 @@ local do_env_damage = function(self) return true end else - self.breath = math.min(self.breath_max, self.breath + 1) + self.breath = min(self.breath_max, self.breath + 1) end end @@ -1544,7 +1544,7 @@ local breed = function(self) return end - mcl_experience.throw_xp(pos, math.random(1, 7)) + mcl_experience.throw_xp(pos, random(1, 7)) -- custom breed function if parent1.on_breed then @@ -1560,7 +1560,7 @@ local breed = function(self) -- Use texture of one of the parents - local p = math.random(1, 2) + local p = random(1, 2) if p == 1 then ent_c.base_texture = parent1.base_texture else @@ -1722,7 +1722,7 @@ local smart_mobs = function(self, s, p, dist, dtime) end, self) end - if math.abs(vector.subtract(s,target_pos).y) > self.stepheight then + if abs(vector.subtract(s,target_pos).y) > self.stepheight then if height_switcher then use_pathfind = true @@ -1763,7 +1763,7 @@ local smart_mobs = function(self, s, p, dist, dtime) if self.fear_height ~= 0 then dropheight = self.fear_height end local jumpheight = 0 if self.jump and self.jump_height >= 4 then - jumpheight = math.min(math.ceil(self.jump_height / 4), 4) + jumpheight = min(ceil(self.jump_height / 4), 4) elseif self.stepheight > 0.5 then jumpheight = 1 end @@ -1794,7 +1794,7 @@ local smart_mobs = function(self, s, p, dist, dtime) end end - local sheight = math.ceil(self.collisionbox[5]) + 1 + local sheight = ceil(self.collisionbox[5]) + 1 -- assume mob is 2 blocks high so it digs above its head s.y = s.y + sheight @@ -2232,9 +2232,9 @@ local follow_flop = function(self) if sdef and sdef.walkable then mob_sound(self, "flop") self.object:set_velocity({ - x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + x = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), y = FLOP_HEIGHT, - z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + z = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), }) end @@ -2289,8 +2289,8 @@ local function go_to_pos(entity,b) return true end local v = { x = b.x - s.x, z = b.z - s.z } - local yaw = (math.atan(v.z / v.x) + math.pi / 2) - entity.rotate - if b.x > s.x then yaw = yaw + math.pi end + local yaw = (atann(v.z / v.x) + pi / 2) - entity.rotate + if b.x > s.x then yaw = yaw + pi end entity.object:set_yaw(yaw) set_velocity(entity,entity.follow_velocity) mcl_mobs:set_animation(entity, "walk") @@ -3474,7 +3474,7 @@ local mob_activate = function(self, staticdata, def, dtime) local c = 1 if #def.textures > c then c = #def.textures end - self.base_texture = def.textures[math.random(c)] + self.base_texture = def.textures[random(c)] self.base_mesh = def.mesh self.base_size = self.visual_size self.base_colbox = self.collisionbox @@ -3688,7 +3688,7 @@ local mob_step = function(self, dtime) self.delay = self.delay - 1 if self.shaking then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime + yaw = yaw + (random() * 2 - 1) * 5 * dtime end self.object:set_yaw(yaw) update_roll(self) @@ -3843,7 +3843,7 @@ local mob_step = function(self, dtime) self.object:remove() return elseif self.lifetimer <= 10 then - if math.random(10) < 4 then + if random(10) < 4 then self.despawn_immediately = true else self.lifetimer = 20 @@ -4516,7 +4516,7 @@ minetest.register_globalstep(function(dtime) for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do local lua = obj:get_luaentity() if lua and lua.is_mob then - lua.lifetimer = math.max(20, lua.lifetimer) + lua.lifetimer = max(20, lua.lifetimer) lua.despawn_immediately = false end end From 8c16b8c7eec71cb40a51b952fee3d56f8e5a8f4c Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 13 Sep 2022 14:18:29 +0200 Subject: [PATCH 11/11] Make mob caps configurable --- mods/ENTITIES/mcl_mobs/spawning.lua | 10 +++++----- settingtypes.txt | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 810f9df4fb..7a67bd4c83 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -29,11 +29,11 @@ local dbg_spawn_succ = 0 local aoc_range = 136 local mob_cap = { - monster = 70, - animal =10, - ambient =15, - water = 5, --currently unused - water_ambient = 20, --currently unused + monster = minetest.settings:get_bool("mcl_mob_cap_monster") or 70, + animal = minetest.settings:get_bool("mcl_mob_cap_animal") or 10, + ambient = minetest.settings:get_bool("mcl_mob_cap_ambient") or 15, + water = minetest.settings:get_bool("mcl_mob_cap_water") or 5, --currently unused + water_ambient = minetest.settings:get_bool("mcl_mob_cap_water_ambient") or 20, --currently unused } --do mobs spawn? diff --git a/settingtypes.txt b/settingtypes.txt index 5f80766538..3d0ce9c05b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -99,6 +99,15 @@ mobs_griefing (Mobs change blocks) bool true # If enabled, mobs won't damage particles when they got hurt. mobs_disable_blood (Disable mob damage particles) bool false +#Maximum amount of monsters that will spawn near a player (default:70) +mcl_mob_cap_monster (Mob cap monsters) int 70 0 2048 + +#Maximum amount of animals that will spawn near a player (default:10) +mcl_mob_cap_animal (Mob cap animals) int 10 0 1024 + +#Maximum amount of ambient mobs that will spawn near a player (default:15) +mcl_mob_cap_ambient (Mob cap ambient mobs) int 15 0 1024 + [Audio] # Enable flame sound. flame_sound (Flame sound) bool true