basic API (WIP)

This commit is contained in:
AFCMS 2021-03-27 20:12:48 +01:00
parent cb294a5cad
commit 30e50a64ef
2 changed files with 34 additions and 12 deletions

View file

@ -0,0 +1,12 @@
# mcl_death_drop
Drop registered inventories on player death.
## mcl_death_drop.register_dropped_list(inv, listname, drop)
* inv: string of function returning a string
* listname: string
* drop: bool
-- if true the entire list will be dropped
-- if false, items with curse_of_vanishing enchantement will be broken.
## mcl_death_drop.registered_dropped_lists
Table containing dropped list definition.

View file

@ -1,3 +1,18 @@
local random = math.random
mcl_death_drop = {}
mcl_death_drop.registered_dropped_lists = {}
function mcl_death_drop.register_dropped_list(inv, listname, drop)
table.insert(mcl_death_drop.registered_dropped_player_lists, {inv=inv, listname=listname, drop=drop})
end
mcl_death_drop.register_dropped_list("PLAYER", "main", true)
mcl_death_drop.register_dropped_list("PLAYER", "craft", true)
mcl_death_drop.register_dropped_list("PLAYER", "armor", true)
mcl_death_drop.register_dropped_list(function(player) return minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"}) end , "armor", false)
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local keep = minetest.settings:get_bool("mcl_keepInventory", false) local keep = minetest.settings:get_bool("mcl_keepInventory", false)
if keep == false then if keep == false then
@ -7,20 +22,15 @@ minetest.register_on_dieplayer(function(player)
local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
-- No item drop if in deep void -- No item drop if in deep void
local void, void_deadly = mcl_worlds.is_in_void(pos) local void, void_deadly = mcl_worlds.is_in_void(pos)
local lists = {
{ inv = inv, listname = "main", drop = true }, for l=1,#mcl_death_drop.registered_dropped_lists do
{ inv = inv, listname = "craft", drop = true }, local inv = mcl_death_drop.registered_dropped_lists[l].inv
{ inv = player_armor_inv, listname = "armor", drop = true }, local listname = mcl_death_drop.registered_dropped_lists[l].listname
{ inv = armor_armor_inv, listname = "armor", drop = false }, local drop = mcl_death_drop.registered_dropped_lists[l].drop
}
for l=1,#lists do
local inv = lists[l].inv
local listname = lists[l].listname
local drop = lists[l].drop
if inv ~= nil then if inv ~= nil then
for i, stack in ipairs(inv:get_list(listname)) do for i, stack in ipairs(inv:get_list(listname)) do
local x = math.random(0, 9)/3 local x = random(0, 9)/3
local z = math.random(0, 9)/3 local z = random(0, 9)/3
pos.x = pos.x + x pos.x = pos.x + x
pos.z = pos.z + z pos.z = pos.z + z
if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then