forked from VoxeLibre/VoxeLibre
add basic API to mcl_item_entity
This commit is contained in:
parent
cb294a5cad
commit
c7389dc0a4
|
@ -1,3 +1,7 @@
|
||||||
|
local has_awards = minetest.get_modpath("awards")
|
||||||
|
|
||||||
|
mcl_item_entity = {}
|
||||||
|
|
||||||
--basic settings
|
--basic settings
|
||||||
local item_drop_settings = {} --settings table
|
local item_drop_settings = {} --settings table
|
||||||
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
|
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
|
||||||
|
@ -16,16 +20,33 @@ local get_gravity = function()
|
||||||
return tonumber(minetest.settings:get("movement_gravity")) or 9.81
|
return tonumber(minetest.settings:get("movement_gravity")) or 9.81
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local registered_pickup_achievement = {}
|
||||||
|
|
||||||
|
--TODO: remove limitation of 1 award per itemname
|
||||||
|
function mcl_item_entity.register_pickup_achievement(itemname, award)
|
||||||
|
if not has_awards then
|
||||||
|
minetest.log("warning", "[mcl_item_entity] Trying to register pickup achievement ["..award.."] for ["..itemname.."] while awards missing")
|
||||||
|
elseif registered_pickup_achievement[itemname] then
|
||||||
|
minetest.log("error", "[mcl_item_entity] Trying to register already existing pickup achievement ["..award.."] for ["..itemname.."]")
|
||||||
|
else
|
||||||
|
registered_pickup_achievement[itemname] = award
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
mcl_item_entity.register_pickup_achievement("tree", "mcl:mineWood")
|
||||||
|
mcl_item_entity.register_pickup_achievement("mcl_mobitems:blaze_rod", "mcl:blazeRod")
|
||||||
|
mcl_item_entity.register_pickup_achievement("mcl_mobitems:leather", "mcl:killCow")
|
||||||
|
mcl_item_entity.register_pickup_achievement("mcl_core:diamond", "mcl:diamonds")
|
||||||
|
|
||||||
local check_pickup_achievements = function(object, player)
|
local check_pickup_achievements = function(object, player)
|
||||||
|
if has_awards then
|
||||||
local itemname = ItemStack(object:get_luaentity().itemstring):get_name()
|
local itemname = ItemStack(object:get_luaentity().itemstring):get_name()
|
||||||
if minetest.get_item_group(itemname, "tree") ~= 0 then
|
local playername = player:get_player_name()
|
||||||
awards.unlock(player:get_player_name(), "mcl:mineWood")
|
for name,award in pairs(registered_pickup_achievement) do
|
||||||
elseif itemname == "mcl_mobitems:blaze_rod" then
|
if itemname == name or minetest.get_item_group(itemname, name) ~= 0 then
|
||||||
awards.unlock(player:get_player_name(), "mcl:blazeRod")
|
awards.unlock(playername, award)
|
||||||
elseif itemname == "mcl_mobitems:leather" then
|
end
|
||||||
awards.unlock(player:get_player_name(), "mcl:killCow")
|
end
|
||||||
elseif itemname == "mcl_core:diamond" then
|
|
||||||
awards.unlock(player:get_player_name(), "mcl:diamonds")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue