From 9602b564c48a0f0d62c5895e3c589d2e34503e38 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 1 Oct 2022 04:27:58 +0200 Subject: [PATCH 1/5] Add donkey inv --- mods/ENTITIES/mobs_mc/horse.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index 6490b6d2de..ea04495541 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -237,6 +237,24 @@ local horse = { local iname = item:get_name() local heal = 0 + if self._inv_id then + if not self._has_chest and item:get_name() == "mcl_chests:chest" then + item:take_item() + clicker:set_wielded_item(item) + self._has_chest = true + local tex_chest = "mcl_chests_normal.png" + self.base_texture = table.copy(self.base_texture) + self.base_texture[1] = tex_chest + self.object:set_properties({ + textures = self.base_texture, + }) + table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1}) + elseif self._has_chest and clicker:get_player_control().sneak then + mcl_entity_invs.show_inv_form(self,clicker,"Donkey") + return + end + end + -- Taming self.temper = self.temper or (math.random(1,100)) @@ -518,8 +536,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) From 7cabdb1707f2679238c1a73bc53beb18e839192b Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 1 Oct 2022 11:33:59 +0200 Subject: [PATCH 2/5] fix donkey chest texture --- mods/ENTITIES/mobs_mc/horse.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index ea04495541..9da733783f 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -238,18 +238,20 @@ local horse = { local heal = 0 if self._inv_id then - if not self._has_chest and item:get_name() == "mcl_chests:chest" then + if not self._chest and item:get_name() == "mcl_chests:chest" then item:take_item() clicker:set_wielded_item(item) - self._has_chest = true - local tex_chest = "mcl_chests_normal.png" - self.base_texture = table.copy(self.base_texture) - self.base_texture[1] = tex_chest - self.object:set_properties({ - textures = self.base_texture, - }) + 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}) table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1}) - elseif self._has_chest and clicker:get_player_control().sneak then + elseif self._chest and clicker:get_player_control().sneak then mcl_entity_invs.show_inv_form(self,clicker,"Donkey") return end From 8d8d49c87dcc74b08acadd7a43250d86d7e56fea Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 1 Oct 2022 23:47:06 +0200 Subject: [PATCH 3/5] Add mule, document api additions --- mods/ENTITIES/mcl_entity_invs/api.txt | 4 +++- mods/ENTITIES/mcl_entity_invs/init.lua | 6 ++++-- mods/ENTITIES/mobs_mc/horse.lua | 4 +++- mods/ENTITIES/mobs_mc/llama.lua | 8 ++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mcl_entity_invs/api.txt b/mods/ENTITIES/mcl_entity_invs/api.txt index 9e81cbe250..98cee1a23b 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 b60e9c18c3..63e134beba 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( @@ -103,6 +104,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 9da733783f..db51cee344 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -251,8 +251,9 @@ local horse = { self.base_texture = tex self.object:set_properties({textures = self.base_texture}) table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1}) + return elseif self._chest and clicker:get_player_control().sneak then - mcl_entity_invs.show_inv_form(self,clicker,"Donkey") + mcl_entity_invs.show_inv_form(self,clicker) return end end @@ -558,6 +559,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 acd9fbe583..d5f2c4853b 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -136,16 +136,16 @@ mcl_mobs:register_mob("mobs_mc:llama", { textures = self.base_texture, }) table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1}) + 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 From d202db00b70b19c1a2fe4fc9a3af3b6e00f0bd72 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 4 Oct 2022 11:36:43 +0200 Subject: [PATCH 4/5] Fix llama and donkey/mule drops --- mods/ENTITIES/mobs_mc/horse.lua | 27 ++++++++++++++++++++++++- mods/ENTITIES/mobs_mc/llama.lua | 36 +++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index db51cee344..0632f4d336 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" @@ -250,7 +274,7 @@ local horse = { local tex = horse_extra_texture(self) self.base_texture = tex 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._chest and clicker:get_player_control().sneak then mcl_entity_invs.show_inv_form(self,clicker) @@ -361,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 diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index d5f2c4853b..c050375ad7 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,7 +158,7 @@ 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)) @@ -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 From b3c34bd08167bfad7a4d1c50ea4eb5a3d29b640f Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 6 Oct 2022 20:53:52 +0200 Subject: [PATCH 5/5] unset item list when dropping inv --- mods/ENTITIES/mcl_entity_invs/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENTITIES/mcl_entity_invs/init.lua b/mods/ENTITIES/mcl_entity_invs/init.lua index 63e134beba..6912228323 100644 --- a/mods/ENTITIES/mcl_entity_invs/init.lua +++ b/mods/ENTITIES/mcl_entity_invs/init.lua @@ -81,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)