Implements item groups soulbound and cursed (#105)

* Implements item groups soulbound and cursed:
Soulbound armors respawn with their owner.
Cursed armors cannot be unequipped by the player.
(disabled in creative mode)

* Prevents a cursed armor from getting unequipped by right clicking another piece of armor.
This commit is contained in:
Kyrah Abattoir 2023-05-31 14:59:20 +02:00 committed by GitHub
parent 053c30b8b1
commit 1d8509e75b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

@ -681,6 +681,10 @@ armor.equip = function(self, player, itemstack)
for i=1, armor_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
if self:get_element(stack:get_name()) == armor_element then
--prevents equiping an armor that would unequip a cursed armor.
if minetest.get_item_group(stack:get_name(), "cursed") ~= 0 then
return itemstack
end
index = i
self:unequip(player, armor_element)
break

@ -224,6 +224,11 @@ local function init_player_armor(initplayer)
if player:get_player_name() ~= name then
return 0
end
--cursed items cannot be unequiped by the player
local is_cursed = minetest.get_item_group(stack:get_name(), "cursed") ~= 0
if not minetest.is_creative_enabled(player) and is_cursed then
return 0
end
return stack:get_count()
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
@ -355,11 +360,14 @@ if armor.config.drop == true or armor.config.destroy == true then
for i=1, armor_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then
--soulbound armors remain equipped after death
if minetest.get_item_group(stack:get_name(), "soulbound") == 0 then
table.insert(drop, stack)
armor:run_callbacks("on_unequip", player, i, stack)
armor_inv:set_stack("armor", i, nil)
end
end
end
armor:save_armor_inventory(player)
armor:set_player_armor(player)
local pos = player:get_pos()
@ -393,8 +401,8 @@ if armor.config.drop == true or armor.config.destroy == true then
end)
end
end)
else -- reset un-dropped armor and it's effects
minetest.register_on_respawnplayer(function(player)
-- reset un-dropped armor and it's effects
armor:set_player_armor(player)
end)
end