Add mule, document api additions
parent
7cabdb1707
commit
8d8d49c87d
|
@ -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)
|
* 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
|
*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.
|
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.
|
||||||
|
|
|
@ -46,11 +46,12 @@ local function save_inv(ent)
|
||||||
end
|
end
|
||||||
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 ent._inv_id then return end
|
||||||
if not open_invs[ent] then
|
if not open_invs[ent] then
|
||||||
open_invs[ent] = 0
|
open_invs[ent] = 0
|
||||||
end
|
end
|
||||||
|
text = text or ""
|
||||||
ent._inv = load_inv(ent,ent._inv_size)
|
ent._inv = load_inv(ent,ent._inv_size)
|
||||||
open_invs[ent] = open_invs[ent] + 1
|
open_invs[ent] = open_invs[ent] + 1
|
||||||
local playername = player:get_player_name()
|
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 spacing = (9 - cols) / 2
|
||||||
local formspec = "size[9,8.75]"
|
local formspec = "size[9,8.75]"
|
||||||
.. "label[0,0;" .. minetest.formspec_escape(
|
.. "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..";]"
|
.. "list[detached:"..ent._inv_id..";main;"..spacing..",0.5;"..cols..","..rows..";]"
|
||||||
.. mcl_formspec.get_itemslot_bg(spacing,0.5,cols,rows)
|
.. mcl_formspec.get_itemslot_bg(spacing,0.5,cols,rows)
|
||||||
.. "label[0,4.0;" .. minetest.formspec_escape(
|
.. "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)
|
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))
|
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_size = size
|
||||||
|
minetest.registered_entities[entity_name]._inv_title = show_name
|
||||||
|
|
||||||
local old_oa = minetest.registered_entities[entity_name].on_activate
|
local old_oa = minetest.registered_entities[entity_name].on_activate
|
||||||
minetest.registered_entities[entity_name].on_activate = function(self,staticdata,dtime_s)
|
minetest.registered_entities[entity_name].on_activate = function(self,staticdata,dtime_s)
|
||||||
|
|
|
@ -251,8 +251,9 @@ local horse = {
|
||||||
self.base_texture = tex
|
self.base_texture = tex
|
||||||
self.object:set_properties({textures = self.base_texture})
|
self.object:set_properties({textures = self.base_texture})
|
||||||
table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1})
|
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
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -558,6 +559,7 @@ mule.collisionbox = {
|
||||||
horse.collisionbox[6] * m,
|
horse.collisionbox[6] * m,
|
||||||
}
|
}
|
||||||
mcl_mobs:register_mob("mobs_mc:mule", mule)
|
mcl_mobs:register_mob("mobs_mc:mule", mule)
|
||||||
|
mcl_entity_invs.register_inv("mobs_mc:mule","Mule",15,true)
|
||||||
|
|
||||||
--===========================
|
--===========================
|
||||||
--Spawn Function
|
--Spawn Function
|
||||||
|
|
|
@ -136,16 +136,16 @@ mcl_mobs:register_mob("mobs_mc:llama", {
|
||||||
textures = self.base_texture,
|
textures = self.base_texture,
|
||||||
})
|
})
|
||||||
table.insert(self.drops,{name = "mcl_chests:chest",chance=1,min=1,max=1})
|
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
|
else
|
||||||
-- Feed with anything else
|
-- Feed with anything else
|
||||||
if mcl_mobs:feed_tame(self, clicker, 1, false, true) then return end
|
if mcl_mobs:feed_tame(self, clicker, 1, false, true) then return end
|
||||||
end
|
end
|
||||||
if mcl_mobs:protect(self, clicker) then return 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
|
-- 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
|
if self.tamed and not self.child and self.owner == clicker:get_player_name() then
|
||||||
-- Place carpet
|
-- Place carpet
|
||||||
|
|
Loading…
Reference in New Issue