diff --git a/mods/ENTITIES/mcl_entity_invs/api.txt b/mods/ENTITIES/mcl_entity_invs/api.txt index 9e81cbe25..98cee1a23 100644 --- a/mods/ENTITIES/mcl_entity_invs/api.txt +++ b/mods/ENTITIES/mcl_entity_invs/api.txt @@ -5,7 +5,9 @@ Inventories for your entities. It's simple. Depend on mcl_entity_invs and regist * mcl_entity_invs.register_inv("entity:name","Title shown in formspec",inventory_size,disable_on_righclick) *If disable_on_righclick is true other mods can handle when to show the inventory themselves + * The inventory size can be set dynamically by initializing it with an explicit nil -* mcl_entity_invs.show_inv_form(entity,clicker,"Title shown in formspec") +* mcl_entity_invs.show_inv_form(entity,clicker,[formspec text]) + * formspec_text is an additional text that is put after the title It works by setting up a detached inventory per entity which is accessed by an id/hash generated from the entities position at creation, the progressed gametime at creation and a random salt. diff --git a/mods/ENTITIES/mcl_entity_invs/init.lua b/mods/ENTITIES/mcl_entity_invs/init.lua index b60e9c18c..691222832 100644 --- a/mods/ENTITIES/mcl_entity_invs/init.lua +++ b/mods/ENTITIES/mcl_entity_invs/init.lua @@ -46,11 +46,12 @@ local function save_inv(ent) end end -function mcl_entity_invs.show_inv_form(ent,player,show_name) +function mcl_entity_invs.show_inv_form(ent,player,text) if not ent._inv_id then return end if not open_invs[ent] then open_invs[ent] = 0 end + text = text or "" ent._inv = load_inv(ent,ent._inv_size) open_invs[ent] = open_invs[ent] + 1 local playername = player:get_player_name() @@ -59,7 +60,7 @@ function mcl_entity_invs.show_inv_form(ent,player,show_name) local spacing = (9 - cols) / 2 local formspec = "size[9,8.75]" .. "label[0,0;" .. minetest.formspec_escape( - minetest.colorize("#313131", show_name)) .. "]" + minetest.colorize("#313131", ent._inv_title .. " ".. text)) .. "]" .. "list[detached:"..ent._inv_id..";main;"..spacing..",0.5;"..cols..","..rows..";]" .. mcl_formspec.get_itemslot_bg(spacing,0.5,cols,rows) .. "label[0,4.0;" .. minetest.formspec_escape( @@ -80,6 +81,7 @@ local function drop_inv(ent) local p = vector.add(pos,vector.new(math.random() - 0.5, math.random()-0.5, math.random()-0.5)) minetest.add_item(p,it) end + ent._items = nil end local function on_remove(self,killer,oldf) @@ -103,6 +105,7 @@ end) function mcl_entity_invs.register_inv(entity_name,show_name,size,no_on_righclick) assert(minetest.registered_entities[entity_name],"mcl_entity_invs.register_inv called with invalid entity: "..tostring(entity_name)) minetest.registered_entities[entity_name]._inv_size = size + minetest.registered_entities[entity_name]._inv_title = show_name local old_oa = minetest.registered_entities[entity_name].on_activate minetest.registered_entities[entity_name].on_activate = function(self,staticdata,dtime_s) diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index 6490b6d2d..0632f4d33 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -34,6 +34,30 @@ local horse_extra_texture = function(horse) return textures end + +local function get_drops(self) + self.drops = {} + table.insert(self.drops, + {name = "mcl_mobitems:leather", + chance = 1, + min = 0, + max = 2, + looting = "common", + }) + if self._saddle then + table.insert(self.drops,{name = "mcl_mobitems:saddle", + chance = 1, + min = 1, + max = 1,}) + end + if self._chest then + table.insert(self.drops,{name = "mcl_chests:chest", + chance = 1, + min = 1, + max = 1,}) + end +end + -- Helper functions to determine equipment rules local can_equip_horse_armor = function(entity_id) return entity_id == "mobs_mc:horse" or entity_id == "mobs_mc:skeleton_horse" or entity_id == "mobs_mc:zombie_horse" @@ -237,6 +261,27 @@ local horse = { local iname = item:get_name() local heal = 0 + if self._inv_id then + if not self._chest and item:get_name() == "mcl_chests:chest" then + item:take_item() + clicker:set_wielded_item(item) + self._chest = true + -- Update texture + if not self._naked_texture then + -- Base horse texture without chest or saddle + self._naked_texture = self.base_texture[2] + end + local tex = horse_extra_texture(self) + self.base_texture = tex + self.object:set_properties({textures = self.base_texture}) + get_drops(self) + return + elseif self._chest and clicker:get_player_control().sneak then + mcl_entity_invs.show_inv_form(self,clicker) + return + end + end + -- Taming self.temper = self.temper or (math.random(1,100)) @@ -340,6 +385,7 @@ local horse = { self.base_texture = tex self.object:set_properties({textures = self.base_texture}) minetest.sound_play({name = "mcl_armor_equip_leather"}, {gain=0.5, max_hear_distance=12, pos=self.object:get_pos()}, true) + get_drops(self) -- Put on horse armor if tamed elseif can_equip_horse_armor(self.name) and not self.driver and not self._horse_armor @@ -518,8 +564,9 @@ donkey.collisionbox = { donkey.jump = true donkey.jump_height = 3.75 -- can clear 1 block height -mcl_mobs:register_mob("mobs_mc:donkey", donkey) +mcl_mobs:register_mob("mobs_mc:donkey", donkey) +mcl_entity_invs.register_inv("mobs_mc:donkey","Donkey",15,true) -- Mule local m = 0.94 local mule = table.copy(donkey) @@ -537,6 +584,7 @@ mule.collisionbox = { horse.collisionbox[6] * m, } mcl_mobs:register_mob("mobs_mc:mule", mule) +mcl_entity_invs.register_inv("mobs_mc:mule","Mule",15,true) --=========================== --Spawn Function diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index acd9fbe58..c050375ad 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -24,6 +24,29 @@ local carpets = { unicolor_light_blue = { "mcl_wool:light_blue_carpet", "light_blue" }, } +local function get_drops(self) + self.drops = {} + table.insert(self.drops, + {name = "mcl_mobitems:leather", + chance = 1, + min = 0, + max = 2, + looting = "common", + }) + if self.carpet then + table.insert(self.drops,{name = self.carpet, + chance = 1, + min = 1, + max = 1,}) + end + if self._has_chest then + table.insert(self.drops,{name = "mcl_chests:chest", + chance = 1, + min = 1, + max = 1,}) + end +end + mcl_mobs:register_mob("mobs_mc:llama", { description = S("Llama"), type = "animal", @@ -135,17 +158,17 @@ mcl_mobs:register_mob("mobs_mc:llama", { self.object:set_properties({ textures = self.base_texture, }) - table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1}) + get_drops(self) + return + elseif self._has_chest and clicker:get_player_control().sneak then + mcl_entity_invs.show_inv_form(self,clicker," - Strength "..math.floor(self._inv_size / 3)) + return else -- Feed with anything else if mcl_mobs:feed_tame(self, clicker, 1, false, true) then return end end if mcl_mobs:protect(self, clicker) then return end - if self._has_chest and clicker:get_player_control().sneak then - mcl_entity_invs.show_inv_form(self,clicker,"Llama - Strength "..math.floor(self._inv_size / 3)) - return - end -- Make sure tamed llama is mature and being clicked by owner only if self.tamed and not self.child and self.owner == clicker:get_player_name() then -- Place carpet @@ -164,16 +187,7 @@ mcl_mobs:register_mob("mobs_mc:llama", { textures = self.base_texture, }) self.carpet = item:get_name() - self.drops = { - {name = "mcl_mobitems:leather", - chance = 1, - min = 0, - max = 2,}, - {name = item:get_name(), - chance = 1, - min = 1, - max = 1,}, - } + get_drops(self) return end end