From ea45d66ee8746209e155b0da4686303da76fad8d Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Tue, 27 Jun 2023 17:16:22 -0600 Subject: [PATCH] Make named fish buckets place fish with a nametag that says that name --- mods/ITEMS/mcl_buckets/fishbuckets.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mods/ITEMS/mcl_buckets/fishbuckets.lua b/mods/ITEMS/mcl_buckets/fishbuckets.lua index 185f72486..c9f1e1897 100644 --- a/mods/ITEMS/mcl_buckets/fishbuckets.lua +++ b/mods/ITEMS/mcl_buckets/fishbuckets.lua @@ -1,4 +1,5 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local MAX_MOB_NAME_LENGTH = 30 -- Fish Buckets local fish_names = { @@ -29,6 +30,18 @@ local function on_place_fish(itemstack, placer, pointed_thing) if props ~= "" then o:set_properties(minetest.deserialize(props)) end + + local ent = o:get_luaentity() + -- set nametag + local nametag = itemstack:get_meta():get_string("name") + if nametag ~= "" then + if string.len(nametag) > MAX_MOB_NAME_LENGTH then + nametag = string.sub(nametag, 1, MAX_MOB_NAME_LENGTH) + end + ent.nametag = nametag + ent:update_tag() + end + local water = "mcl_core:water_source" if n.name == "mclx_core:river_water_source" then water = n.name