Merge pull request 'Make recovery compass optional' (#1) from chud/recovery_coffre:optional_compass into main

Reviewed-on: https://codeberg.org/neocraft1293/recovery_coffre/pulls/1
This commit is contained in:
neocraft1293 2024-12-29 11:01:27 +00:00
commit 0cbc0811f4
2 changed files with 28 additions and 19 deletions

View File

@ -1,5 +1,9 @@
local S = minetest.get_translator("chest_recovery") -- Récupérer le traducteur pour ce mod local S = minetest.get_translator("chest_recovery") -- Récupérer le traducteur pour ce mod
-- settings
local setting_give_recovery_compass = minetest.settings:get_bool("chest_recovery_give_recovery_compass", false)
chest_positions = {} chest_positions = {}
@ -305,11 +309,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Traitement du bouton de transfert -- Traitement du bouton de transfert
if fields.transfer then if fields.transfer then
-- Supprimer les éléments de récupération du joueur if setting_give_recovery_compass == true then
for i = 1, player_inv:get_size("main") do -- Supprimer les éléments de récupération du joueur
local stack = player_inv:get_stack("main", i) for i = 1, player_inv:get_size("main") do
if stack:get_name():find("mcl_compass:.*_recovery") then local stack = player_inv:get_stack("main", i)
player_inv:remove_item("main", stack) if stack:get_name():find("mcl_compass:.*_recovery") then
player_inv:remove_item("main", stack)
end
end end
end end
@ -546,23 +552,24 @@ minetest.register_privilege("chest_recovery_bypass", {
if setting_give_recovery_compass == true then
-- Define compass_frames as a global variable
compass_frames = 32
-- Define compass_frames as a global variable minetest.register_on_respawnplayer(function(player)
compass_frames = 32 -- Generate a new random frame for the recovery compass
local random_frame = math.random(0, compass_frames - 1)
minetest.register_on_respawnplayer(function(player) -- Create the recovery compass item
-- Generate a new random frame for the recovery compass local recovery_compass = ItemStack("mcl_compass:" .. random_frame .. "_recovery")
local random_frame = math.random(0, compass_frames - 1) local player_inv_2 = player:get_inventory()
-- Create the recovery compass item if player_inv_2 then
local recovery_compass = ItemStack("mcl_compass:" .. random_frame .. "_recovery") player_inv_2:add_item("main", recovery_compass)
local player_inv_2 = player:get_inventory() end
if player_inv_2 then end)
player_inv_2:add_item("main", recovery_compass) end
end
end)

2
settingtypes.txt Normal file
View File

@ -0,0 +1,2 @@
# give player a recovery compass on death, and delete it on recovery
chest_recovery_give_recovery_compass (Recovery Compass) bool false