add basic API to mcl_item_entity

This commit is contained in:
AFCMS 2021-03-28 08:13:24 +02:00
parent cb294a5cad
commit c7389dc0a4

View file

@ -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)
local itemname = ItemStack(object:get_luaentity().itemstring):get_name() if has_awards then
if minetest.get_item_group(itemname, "tree") ~= 0 then local itemname = ItemStack(object:get_luaentity().itemstring):get_name()
awards.unlock(player:get_player_name(), "mcl:mineWood") local playername = player:get_player_name()
elseif itemname == "mcl_mobitems:blaze_rod" then for name,award in pairs(registered_pickup_achievement) do
awards.unlock(player:get_player_name(), "mcl:blazeRod") if itemname == name or minetest.get_item_group(itemname, name) ~= 0 then
elseif itemname == "mcl_mobitems:leather" then awards.unlock(playername, award)
awards.unlock(player:get_player_name(), "mcl:killCow") end
elseif itemname == "mcl_core:diamond" then end
awards.unlock(player:get_player_name(), "mcl:diamonds")
end end
end end