Skip to content

Commit

Permalink
Implements item groups soulbound and cursed (stujones11#105)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kyrahabattoir authored May 31, 2023
1 parent 053c30b commit 1d8509e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 3d_armor/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions 3d_armor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -355,9 +360,12 @@ 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
table.insert(drop, stack)
armor:run_callbacks("on_unequip", player, i, stack)
armor_inv:set_stack("armor", i, nil)
--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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d8509e

Please sign in to comment.