From fcdc04374ccd140a64af955a2ee9e080b32d8c0c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 19 Mar 2024 15:27:28 +0100 Subject: [PATCH] Disable child tool for some mobs --- mods/rp_mobs/API.md | 7 ++++++- mods/rp_mobs/api.lua | 4 ++-- mods/rp_mobs_mobs/boar.lua | 2 +- mods/rp_mobs_mobs/sheep.lua | 2 +- mods/rp_mobs_mobs/skunk.lua | 2 +- mods/rp_supertools/init.lua | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mods/rp_mobs/API.md b/mods/rp_mobs/API.md index 7f0bf69b..7058c612 100644 --- a/mods/rp_mobs/API.md +++ b/mods/rp_mobs/API.md @@ -211,7 +211,8 @@ by manipulating the drowning fields (see the mob field reference). ### Breeding Breeding will make mobs mate and create offspring. To enable, call -`rp_mobs.handle_breeding` in `on_step`. +`rp_mobs.handle_breeding` in `on_step`. You also need to add the tag +`"child_exists"` to the mob definition. In particular, to breed, two adult mobs of the same type need to be “horny” and close to each other. Then, a random mob of the pair gets pregnant and will soon @@ -328,6 +329,8 @@ The field `_cmi_is_mob=true` will be set automatically for all mobs and can be u the player alone. Peaceful mobs may still turn hostile when provoked. Mobs that start hostile towards the player do not count as peaceful. If the setting `spawn_peaceful_only` is enabled, only mobs with this tag can spawn. + * `"child_exists"`: Mob has a functional child version. This tag is only + for informing other mobs; it does not have an effect in the `rp_mobs` code * Example: `tags = { animal = 1, peaceful = 1, exploder = 1 }` * A peaceful animal, plus a custom `"exploder"` tag. @@ -697,6 +700,8 @@ Turns the mob into an adult. #### `rp_mobs.turn_into_child(mob)` Turns the mob into a child. +IMPORTANT: You *must* check whether the mob has the `"child_exists"` tag before calling this. +Don't call this function if the mob does not have this tag. #### `rp_mobs.advance_child_growth(mob, dtime)` diff --git a/mods/rp_mobs/api.lua b/mods/rp_mobs/api.lua index 973b16df..4a8a855a 100644 --- a/mods/rp_mobs/api.lua +++ b/mods/rp_mobs/api.lua @@ -182,10 +182,10 @@ end rp_mobs.mobdef_has_tag = function(mobname, tag_name) local mobdef = rp_mobs.registered_mobs[mobname] - if not mobdef then + if not mobdef or not mobdef.entity_definition or not mobdef.entity_definition._tags then return false end - return mobdef._tags[tag_name] == 1 + return mobdef.entity_definition._tags[tag_name] == 1 end local flip_over_collisionbox = function(box, is_child, y_offset) diff --git a/mods/rp_mobs_mobs/boar.lua b/mods/rp_mobs_mobs/boar.lua index 8f889942..4c0c0a45 100644 --- a/mods/rp_mobs_mobs/boar.lua +++ b/mods/rp_mobs_mobs/boar.lua @@ -37,7 +37,7 @@ local task_queue_roam_settings = { -- rp_mobs.register_mob("rp_mobs_mobs:boar", { description = S("Boar"), - tags = { animal = 1, peaceful = 1 }, + tags = { animal = 1, child_exists = 1, peaceful = 1 }, drops = { {name="rp_mobs_mobs:pork_raw", chance=1, min=1, max=4}, }, diff --git a/mods/rp_mobs_mobs/sheep.lua b/mods/rp_mobs_mobs/sheep.lua index 9cad4c0b..e44fb713 100644 --- a/mods/rp_mobs_mobs/sheep.lua +++ b/mods/rp_mobs_mobs/sheep.lua @@ -152,7 +152,7 @@ end rp_mobs.register_mob("rp_mobs_mobs:sheep", { description = S("Sheep"), - tags = { animal = 1, peaceful = 1 }, + tags = { animal = 1, child_exists = 1, peaceful = 1 }, drops = { {name="rp_mobs_mobs:meat_raw", chance=1, min=2, max=4}, }, diff --git a/mods/rp_mobs_mobs/skunk.lua b/mods/rp_mobs_mobs/skunk.lua index e89cf5ae..58373f2c 100644 --- a/mods/rp_mobs_mobs/skunk.lua +++ b/mods/rp_mobs_mobs/skunk.lua @@ -33,7 +33,7 @@ local task_queue_roam_settings = { rp_mobs.register_mob("rp_mobs_mobs:skunk", { description = S("Skunk"), - tags = { animal = 1, peaceful = 1 }, + tags = { animal = 1, child_exists = 1, peaceful = 1 }, drops = { {name="rp_mobs_mobs:meat_raw", chance=1, min=1, max=2}, }, diff --git a/mods/rp_supertools/init.lua b/mods/rp_supertools/init.lua index 501da9cc..468218a6 100644 --- a/mods/rp_supertools/init.lua +++ b/mods/rp_supertools/init.lua @@ -164,7 +164,7 @@ minetest.register_craftitem( end local obj = pointed_thing.ref local ent = obj:get_luaentity() - if ent and ent._cmi_is_mob and not ent._child then + if ent and ent._cmi_is_mob and not ent._child and rp_mobs.mobdef_has_tag(ent.name, "child_exists") then local pos = obj:get_pos() rp_mobs.turn_into_child(obj) if not minetest.is_creative_enabled(placer:get_player_name()) then