Add mule, document api additions

This commit is contained in:
cora 2022-10-01 23:47:06 +02:00
parent 7cabdb1707
commit 8d8d49c87d
4 changed files with 14 additions and 8 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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