2017-03-18 18:23:50 +01:00
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
local modpath = minetest.get_modpath(modname)
|
2017-03-17 21:05:55 +01:00
|
|
|
local worldpath = minetest.get_worldpath()
|
2017-04-05 18:46:09 +02:00
|
|
|
local last_punch_time = {}
|
2017-04-11 20:31:25 +02:00
|
|
|
local pending_players = {}
|
|
|
|
local timer = 0
|
2017-03-18 18:23:50 +01:00
|
|
|
|
2020-08-31 06:00:18 +02:00
|
|
|
dofile(modpath.."/api.lua")
|
|
|
|
|
2018-07-26 21:05:50 +02:00
|
|
|
-- local functions
|
|
|
|
local F = minetest.formspec_escape
|
2020-08-31 06:00:18 +02:00
|
|
|
local S = armor.get_translator
|
2017-03-18 18:23:50 +01:00
|
|
|
|
2020-02-13 12:26:32 +01:00
|
|
|
-- integration test
|
|
|
|
if minetest.settings:get_bool("enable_3d_armor_integration_test") then
|
2020-11-03 22:22:14 +01:00
|
|
|
dofile(modpath.."/integration_test.lua")
|
2020-02-13 12:26:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
-- Legacy Config Support
|
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
local input = io.open(modpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(modpath.."/armor.conf")
|
|
|
|
input:close()
|
2015-02-19 19:53:31 +01:00
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
input = io.open(worldpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(worldpath.."/armor.conf")
|
|
|
|
input:close()
|
2015-02-19 19:53:31 +01:00
|
|
|
end
|
2017-03-18 18:23:50 +01:00
|
|
|
for name, _ in pairs(armor.config) do
|
|
|
|
local global = "ARMOR_"..name:upper()
|
|
|
|
if minetest.global_exists(global) then
|
|
|
|
armor.config[name] = _G[global]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if minetest.global_exists("ARMOR_MATERIALS") then
|
|
|
|
armor.materials = table.copy(ARMOR_MATERIALS)
|
|
|
|
end
|
|
|
|
if minetest.global_exists("ARMOR_FIRE_NODES") then
|
|
|
|
armor.fire_nodes = table.copy(ARMOR_FIRE_NODES)
|
|
|
|
end
|
|
|
|
|
2017-03-18 19:04:10 +01:00
|
|
|
-- Load Configuration
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
for name, config in pairs(armor.config) do
|
2017-05-13 09:08:18 +02:00
|
|
|
local setting = minetest.settings:get("armor_"..name)
|
2017-03-18 18:23:50 +01:00
|
|
|
if type(config) == "number" then
|
|
|
|
setting = tonumber(setting)
|
2021-01-11 15:34:28 +01:00
|
|
|
elseif type(config) == "string" then
|
|
|
|
setting = tostring(setting)
|
2017-03-18 18:23:50 +01:00
|
|
|
elseif type(config) == "boolean" then
|
2017-05-13 09:08:18 +02:00
|
|
|
setting = minetest.settings:get_bool("armor_"..name)
|
2017-03-18 18:23:50 +01:00
|
|
|
end
|
2017-04-05 18:51:50 +02:00
|
|
|
if setting ~= nil then
|
2017-03-18 18:23:50 +01:00
|
|
|
armor.config[name] = setting
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for material, _ in pairs(armor.materials) do
|
|
|
|
local key = "material_"..material
|
|
|
|
if armor.config[key] == false then
|
|
|
|
armor.materials[material] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-11 15:34:28 +01:00
|
|
|
-- Convert set_elements to a Lua table splitting on blank spaces
|
|
|
|
local t_set_elements = armor.config.set_elements
|
|
|
|
armor.config.set_elements = string.split(t_set_elements, " ")
|
|
|
|
|
2020-12-13 13:07:39 +01:00
|
|
|
-- Remove torch damage if fire_protect_torch == false
|
|
|
|
if armor.config.fire_protect_torch == false and armor.config.fire_protect == true then
|
|
|
|
for k,v in pairs(armor.fire_nodes) do
|
|
|
|
for k2,v2 in pairs(v) do
|
|
|
|
if string.find (v2,"torch") then
|
|
|
|
armor.fire_nodes[k] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
-- Mod Compatibility
|
2013-03-15 21:27:58 +01:00
|
|
|
|
2017-03-19 19:39:58 +01:00
|
|
|
if minetest.get_modpath("technic") then
|
2017-03-31 20:54:12 +02:00
|
|
|
armor.formspec = armor.formspec..
|
2020-11-03 22:22:14 +01:00
|
|
|
"label[5,2.5;"..F(S("Radiation"))..": armor_group_radiation]"
|
2017-03-23 01:52:32 +01:00
|
|
|
armor:register_armor_group("radiation")
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"}
|
|
|
|
for _, mod in pairs(skin_mods) do
|
|
|
|
local path = minetest.get_modpath(mod)
|
|
|
|
if path then
|
|
|
|
local dir_list = minetest.get_dir_list(path.."/textures")
|
|
|
|
for _, fn in pairs(dir_list) do
|
|
|
|
if fn:find("_preview.png$") then
|
|
|
|
armor:add_preview(fn)
|
|
|
|
end
|
|
|
|
end
|
2021-07-13 20:50:22 +02:00
|
|
|
armor.set_skin_mod(mod)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
|
2017-05-10 21:33:49 +02:00
|
|
|
|
2017-04-19 22:53:13 +02:00
|
|
|
-- Armor Initialization
|
|
|
|
|
|
|
|
armor.formspec = armor.formspec..
|
2018-07-26 21:05:50 +02:00
|
|
|
"label[5,1;"..F(S("Level"))..": armor_level]"..
|
2020-11-03 22:22:14 +01:00
|
|
|
"label[5,1.5;"..F(S("Heal"))..": armor_attr_heal]"
|
2017-04-19 22:53:13 +02:00
|
|
|
if armor.config.fire_protect then
|
2020-11-03 22:22:14 +01:00
|
|
|
armor.formspec = armor.formspec.."label[5,2;"..F(S("Fire"))..": armor_attr_fire]"
|
2017-04-19 22:53:13 +02:00
|
|
|
end
|
2019-12-28 13:13:41 +01:00
|
|
|
armor:register_on_damage(function(player, index, stack)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local def = stack:get_definition()
|
|
|
|
if name and def and def.description and stack:get_wear() > 60100 then
|
|
|
|
minetest.chat_send_player(name, S("Your @1 is almost broken!", def.description))
|
|
|
|
minetest.sound_play("default_tool_breaks", {to_player = name, gain = 2.0})
|
|
|
|
end
|
|
|
|
end)
|
2017-04-19 22:53:13 +02:00
|
|
|
armor:register_on_destroy(function(player, index, stack)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local def = stack:get_definition()
|
|
|
|
if name and def and def.description then
|
2017-08-06 18:43:41 +02:00
|
|
|
minetest.chat_send_player(name, S("Your @1 got destroyed!", def.description))
|
2019-12-28 13:13:41 +01:00
|
|
|
minetest.sound_play("default_tool_breaks", {to_player = name, gain = 2.0})
|
2017-04-19 22:53:13 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2018-06-02 19:59:32 +02:00
|
|
|
local function validate_armor_inventory(player)
|
|
|
|
-- Workaround for detached inventory swap exploit
|
|
|
|
local _, inv = armor:get_valid_player(player, "[validate_armor_inventory]")
|
2019-07-16 04:40:28 +02:00
|
|
|
local pos = player:get_pos()
|
2018-06-02 19:59:32 +02:00
|
|
|
if not inv then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local armor_prev = {}
|
2019-06-16 22:17:21 +02:00
|
|
|
local attribute_meta = player:get_meta() -- I know, the function's name is weird but let it be like that. ;)
|
|
|
|
local armor_list_string = attribute_meta:get_string("3d_armor_inventory")
|
2018-06-02 19:59:32 +02:00
|
|
|
if armor_list_string then
|
|
|
|
local armor_list = armor:deserialize_inventory_list(armor_list_string)
|
|
|
|
for i, stack in ipairs(armor_list) do
|
|
|
|
if stack:get_count() > 0 then
|
|
|
|
armor_prev[stack:get_name()] = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local elements = {}
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
for i = 1, 6 do
|
|
|
|
local stack = inv:get_stack("armor", i)
|
|
|
|
if stack:get_count() > 0 then
|
|
|
|
local item = stack:get_name()
|
|
|
|
local element = armor:get_element(item)
|
|
|
|
if element and not elements[element] then
|
|
|
|
if armor_prev[item] then
|
|
|
|
armor_prev[item] = nil
|
|
|
|
else
|
|
|
|
-- Item was not in previous inventory
|
|
|
|
armor:run_callbacks("on_equip", player, i, stack)
|
|
|
|
end
|
|
|
|
elements[element] = true;
|
|
|
|
else
|
|
|
|
inv:remove_item("armor", stack)
|
2019-07-16 04:40:28 +02:00
|
|
|
minetest.item_drop(stack, player, pos)
|
2018-06-02 19:59:32 +02:00
|
|
|
-- The following code returns invalid items to the player's main
|
2018-06-02 21:46:44 +02:00
|
|
|
-- inventory but could open up the possibity for a hacked client
|
2018-06-02 19:59:32 +02:00
|
|
|
-- to receive items back they never really had. I am not certain
|
2018-06-02 21:46:44 +02:00
|
|
|
-- so remove the is_singleplayer check at your own risk :]
|
|
|
|
if minetest.is_singleplayer() and player_inv and
|
|
|
|
player_inv:room_for_item("main", stack) then
|
|
|
|
player_inv:add_item("main", stack)
|
|
|
|
end
|
2018-06-02 19:59:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for item, i in pairs(armor_prev) do
|
|
|
|
local stack = ItemStack(item)
|
|
|
|
-- Previous item is not in current inventory
|
|
|
|
armor:run_callbacks("on_unequip", player, i, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-13 12:26:32 +01:00
|
|
|
local function init_player_armor(initplayer)
|
|
|
|
local name = initplayer:get_player_name()
|
|
|
|
local pos = initplayer:get_pos()
|
2018-02-11 13:33:46 +01:00
|
|
|
if not name or not pos then
|
2017-04-19 22:53:13 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
local armor_inv = minetest.create_detached_inventory(name.."_armor", {
|
|
|
|
on_put = function(inv, listname, index, stack, player)
|
2018-06-02 19:59:32 +02:00
|
|
|
validate_armor_inventory(player)
|
2018-02-11 13:33:46 +01:00
|
|
|
armor:save_armor_inventory(player)
|
2017-04-19 22:53:13 +02:00
|
|
|
armor:set_player_armor(player)
|
|
|
|
end,
|
|
|
|
on_take = function(inv, listname, index, stack, player)
|
2018-06-02 19:59:32 +02:00
|
|
|
validate_armor_inventory(player)
|
2018-02-11 13:33:46 +01:00
|
|
|
armor:save_armor_inventory(player)
|
2017-04-19 22:53:13 +02:00
|
|
|
armor:set_player_armor(player)
|
|
|
|
end,
|
|
|
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
2018-06-02 19:59:32 +02:00
|
|
|
validate_armor_inventory(player)
|
2018-02-11 13:33:46 +01:00
|
|
|
armor:save_armor_inventory(player)
|
2017-04-19 22:53:13 +02:00
|
|
|
armor:set_player_armor(player)
|
|
|
|
end,
|
2018-05-21 11:46:54 +02:00
|
|
|
allow_put = function(inv, listname, index, put_stack, player)
|
2020-11-03 22:22:14 +01:00
|
|
|
if player:get_player_name() ~= name then
|
|
|
|
return 0
|
|
|
|
end
|
2018-05-21 11:46:54 +02:00
|
|
|
local element = armor:get_element(put_stack:get_name())
|
2018-05-19 21:25:27 +02:00
|
|
|
if not element then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
for i = 1, 6 do
|
|
|
|
local stack = inv:get_stack("armor", i)
|
|
|
|
local def = stack:get_definition() or {}
|
2018-05-21 11:46:54 +02:00
|
|
|
if def.groups and def.groups["armor_"..element]
|
|
|
|
and i ~= index then
|
2018-05-19 21:25:27 +02:00
|
|
|
return 0
|
2017-04-19 22:53:13 +02:00
|
|
|
end
|
|
|
|
end
|
2018-05-19 21:25:27 +02:00
|
|
|
return 1
|
2017-04-19 22:53:13 +02:00
|
|
|
end,
|
|
|
|
allow_take = function(inv, listname, index, stack, player)
|
2020-11-03 22:22:14 +01:00
|
|
|
if player:get_player_name() ~= name then
|
|
|
|
return 0
|
|
|
|
end
|
2023-05-31 14:59:20 +02:00
|
|
|
--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
|
2017-04-19 22:53:13 +02:00
|
|
|
return stack:get_count()
|
|
|
|
end,
|
|
|
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
2020-11-03 22:22:14 +01:00
|
|
|
if player:get_player_name() ~= name then
|
|
|
|
return 0
|
|
|
|
end
|
2017-04-19 22:53:13 +02:00
|
|
|
return count
|
|
|
|
end,
|
|
|
|
}, name)
|
|
|
|
armor_inv:set_size("armor", 6)
|
2020-02-13 12:26:32 +01:00
|
|
|
if not armor:load_armor_inventory(initplayer) and armor.migrate_old_inventory then
|
|
|
|
local player_inv = initplayer:get_inventory()
|
2018-02-11 13:33:46 +01:00
|
|
|
player_inv:set_size("armor", 6)
|
|
|
|
for i=1, 6 do
|
|
|
|
local stack = player_inv:get_stack("armor", i)
|
|
|
|
armor_inv:set_stack("armor", i, stack)
|
|
|
|
end
|
2020-02-13 12:26:32 +01:00
|
|
|
armor:save_armor_inventory(initplayer)
|
2018-02-11 13:33:46 +01:00
|
|
|
player_inv:set_size("armor", 0)
|
|
|
|
end
|
2017-04-19 22:53:13 +02:00
|
|
|
for i=1, 6 do
|
2018-02-11 13:33:46 +01:00
|
|
|
local stack = armor_inv:get_stack("armor", i)
|
2018-05-23 21:15:09 +02:00
|
|
|
if stack:get_count() > 0 then
|
2020-02-13 12:26:32 +01:00
|
|
|
armor:run_callbacks("on_equip", initplayer, i, stack)
|
2018-05-23 21:15:09 +02:00
|
|
|
end
|
2017-04-19 22:53:13 +02:00
|
|
|
end
|
|
|
|
armor.def[name] = {
|
|
|
|
init_time = minetest.get_gametime(),
|
|
|
|
level = 0,
|
|
|
|
state = 0,
|
|
|
|
count = 0,
|
|
|
|
groups = {},
|
|
|
|
}
|
|
|
|
for _, phys in pairs(armor.physics) do
|
|
|
|
armor.def[name][phys] = 1
|
|
|
|
end
|
|
|
|
for _, attr in pairs(armor.attributes) do
|
|
|
|
armor.def[name][attr] = 0
|
|
|
|
end
|
|
|
|
for group, _ in pairs(armor.registered_groups) do
|
|
|
|
armor.def[name].groups[group] = 0
|
|
|
|
end
|
|
|
|
local skin = armor:get_player_skin(name)
|
|
|
|
armor.textures[name] = {
|
2017-06-18 22:13:48 +02:00
|
|
|
skin = skin,
|
2017-04-19 22:53:13 +02:00
|
|
|
armor = "3d_armor_trans.png",
|
|
|
|
wielditem = "3d_armor_trans.png",
|
|
|
|
preview = armor.default_skin.."_preview.png",
|
|
|
|
}
|
|
|
|
local texture_path = minetest.get_modpath("player_textures")
|
|
|
|
if texture_path then
|
|
|
|
local dir_list = minetest.get_dir_list(texture_path.."/textures")
|
|
|
|
for _, fn in pairs(dir_list) do
|
|
|
|
if fn == "player_"..name..".png" then
|
|
|
|
armor.textures[name].skin = fn
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-13 12:26:32 +01:00
|
|
|
armor:set_player_armor(initplayer)
|
2017-04-19 22:53:13 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
-- Armor Player Model
|
|
|
|
|
2022-03-25 08:46:18 +01:00
|
|
|
player_api.register_model("3d_armor_character.b3d", {
|
2017-03-17 21:05:55 +01:00
|
|
|
animation_speed = 30,
|
|
|
|
textures = {
|
|
|
|
armor.default_skin..".png",
|
|
|
|
"3d_armor_trans.png",
|
|
|
|
"3d_armor_trans.png",
|
|
|
|
},
|
|
|
|
animations = {
|
|
|
|
stand = {x=0, y=79},
|
|
|
|
lay = {x=162, y=166},
|
|
|
|
walk = {x=168, y=187},
|
|
|
|
mine = {x=189, y=198},
|
|
|
|
walk_mine = {x=200, y=219},
|
|
|
|
sit = {x=81, y=160},
|
2023-01-14 21:44:41 +01:00
|
|
|
-- compatibility w/ the emote mod
|
|
|
|
wave = {x = 192, y = 196, override_local = true},
|
|
|
|
point = {x = 196, y = 196, override_local = true},
|
|
|
|
freeze = {x = 205, y = 205, override_local = true},
|
2017-03-17 21:05:55 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
2017-03-19 17:01:18 +01:00
|
|
|
if not name then
|
2017-03-17 21:05:55 +01:00
|
|
|
return
|
|
|
|
end
|
2020-11-03 22:22:14 +01:00
|
|
|
local player_name = player:get_player_name()
|
2017-03-17 21:05:55 +01:00
|
|
|
for field, _ in pairs(fields) do
|
|
|
|
if string.find(field, "skins_set") then
|
2020-10-12 07:47:57 +02:00
|
|
|
armor:update_skin(player_name)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
default.player_set_model(player, "3d_armor_character.b3d")
|
2020-11-03 22:22:14 +01:00
|
|
|
local player_name = player:get_player_name()
|
2020-02-13 12:26:32 +01:00
|
|
|
|
|
|
|
minetest.after(0, function()
|
2021-03-24 19:21:39 +01:00
|
|
|
-- TODO: Added in 7566ecc - What's the prupose?
|
2020-11-03 22:22:14 +01:00
|
|
|
local pplayer = minetest.get_player_by_name(player_name)
|
2020-02-13 12:26:32 +01:00
|
|
|
if pplayer and init_player_armor(pplayer) == false then
|
|
|
|
pending_players[pplayer] = 0
|
2017-04-16 17:52:12 +02:00
|
|
|
end
|
2020-02-13 12:26:32 +01:00
|
|
|
end)
|
2017-03-17 21:05:55 +01:00
|
|
|
end)
|
|
|
|
|
2017-03-23 01:52:32 +01:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if name then
|
|
|
|
armor.def[name] = nil
|
|
|
|
armor.textures[name] = nil
|
|
|
|
end
|
2017-04-13 20:47:43 +02:00
|
|
|
pending_players[player] = nil
|
2017-03-23 01:52:32 +01:00
|
|
|
end)
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
if armor.config.drop == true or armor.config.destroy == true then
|
2017-03-17 21:05:55 +01:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
2018-02-11 13:33:46 +01:00
|
|
|
local name, armor_inv = armor:get_valid_player(player, "[on_dieplayer]")
|
2017-03-17 21:05:55 +01:00
|
|
|
if not name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local drop = {}
|
2018-02-11 13:33:46 +01:00
|
|
|
for i=1, armor_inv:get_size("armor") do
|
|
|
|
local stack = armor_inv:get_stack("armor", i)
|
2017-03-17 21:05:55 +01:00
|
|
|
if stack:get_count() > 0 then
|
2023-05-31 14:59:20 +02:00
|
|
|
--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
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
2018-05-24 19:56:20 +02:00
|
|
|
armor:save_armor_inventory(player)
|
2017-03-17 21:05:55 +01:00
|
|
|
armor:set_player_armor(player)
|
2019-03-05 20:40:54 +01:00
|
|
|
local pos = player:get_pos()
|
2017-04-11 20:31:25 +02:00
|
|
|
if pos and armor.config.destroy == false then
|
2017-03-18 18:23:50 +01:00
|
|
|
minetest.after(armor.config.bones_delay, function()
|
2017-03-17 21:05:55 +01:00
|
|
|
local meta = nil
|
2019-12-09 11:04:11 +01:00
|
|
|
local maxp = vector.add(pos, 16)
|
|
|
|
local minp = vector.subtract(pos, 16)
|
2017-03-17 21:05:55 +01:00
|
|
|
local bones = minetest.find_nodes_in_area(minp, maxp, {"bones:bones"})
|
|
|
|
for _, p in pairs(bones) do
|
|
|
|
local m = minetest.get_meta(p)
|
|
|
|
if m:get_string("owner") == name then
|
|
|
|
meta = m
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
if inv:room_for_item("main", stack) then
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
else
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|
2020-12-23 15:40:44 +01:00
|
|
|
minetest.register_on_respawnplayer(function(player)
|
2023-05-31 14:59:20 +02:00
|
|
|
-- reset un-dropped armor and it's effects
|
2020-12-23 15:40:44 +01:00
|
|
|
armor:set_player_armor(player)
|
|
|
|
end)
|
2015-05-04 18:08:40 +02:00
|
|
|
end
|
|
|
|
|
2017-04-05 18:46:09 +02:00
|
|
|
if armor.config.punch_damage == true then
|
|
|
|
minetest.register_on_punchplayer(function(player, hitter,
|
|
|
|
time_from_last_punch, tool_capabilities)
|
|
|
|
local name = player:get_player_name()
|
2020-12-22 02:30:42 +01:00
|
|
|
local hit_ip = hitter:is_player()
|
|
|
|
if name and hit_ip and minetest.is_protected(player:get_pos(), "") then
|
2020-12-19 03:23:17 +01:00
|
|
|
return
|
|
|
|
elseif name then
|
2017-04-11 20:31:25 +02:00
|
|
|
armor:punch(player, hitter, time_from_last_punch, tool_capabilities)
|
2017-04-05 18:46:09 +02:00
|
|
|
last_punch_time[name] = minetest.get_gametime()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2020-04-30 00:10:31 +02:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
2023-04-19 23:02:29 +02:00
|
|
|
if not minetest.is_player(player) then
|
|
|
|
return hp_change
|
|
|
|
end
|
|
|
|
|
|
|
|
if reason.type == "drown" or reason.hunger or hp_change >= 0 then
|
|
|
|
return hp_change
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local properties = player:get_properties()
|
|
|
|
local hp = player:get_hp()
|
|
|
|
if hp + hp_change < properties.hp_max then
|
|
|
|
local heal = armor.def[name].heal
|
|
|
|
if heal >= math.random(100) then
|
|
|
|
hp_change = 0
|
|
|
|
end
|
|
|
|
-- check if armor damage was handled by fire or on_punchplayer
|
|
|
|
local time = last_punch_time[name] or 0
|
|
|
|
if time == 0 or time + 1 < minetest.get_gametime() then
|
|
|
|
armor:punch(player)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
2023-04-19 23:02:29 +02:00
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
return hp_change
|
|
|
|
end, true)
|
|
|
|
|
2017-04-11 20:31:25 +02:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
timer = timer + dtime
|
2022-04-02 17:16:23 +02:00
|
|
|
|
|
|
|
if armor.config.feather_fall == true then
|
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if armor.def[name].feather > 0 then
|
|
|
|
local vel_y = player:get_velocity().y
|
|
|
|
if vel_y < 0 and vel_y < 3 then
|
|
|
|
vel_y = -(vel_y * 0.05)
|
|
|
|
player:add_velocity({x = 0, y = vel_y, z = 0})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-07 09:47:23 +01:00
|
|
|
if timer <= armor.config.init_delay then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
timer = 0
|
|
|
|
|
|
|
|
for player, count in pairs(pending_players) do
|
|
|
|
local remove = init_player_armor(player) == true
|
|
|
|
pending_players[player] = count + 1
|
|
|
|
if remove == false and count > armor.config.init_times then
|
2022-12-25 18:23:49 +01:00
|
|
|
minetest.log("warning", "3d_armor: Failed to initialize player")
|
2021-02-07 09:47:23 +01:00
|
|
|
remove = true
|
|
|
|
end
|
|
|
|
if remove == true then
|
|
|
|
pending_players[player] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- water breathing protection, added by TenPlus1
|
|
|
|
if armor.config.water_protect == true then
|
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if armor.def[name].water > 0 and
|
|
|
|
player:get_breath() < 10 then
|
|
|
|
player:set_breath(10)
|
2017-04-11 20:31:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
if armor.config.fire_protect == true then
|
2013-03-15 21:27:58 +01:00
|
|
|
|
2023-02-05 17:44:17 +01:00
|
|
|
-- make torches hurt
|
|
|
|
minetest.override_item("default:torch", {damage_per_second = 1})
|
|
|
|
minetest.override_item("default:torch_wall", {damage_per_second = 1})
|
|
|
|
minetest.override_item("default:torch_ceiling", {damage_per_second = 1})
|
|
|
|
|
|
|
|
-- check player damage for any hot nodes we may be protected against
|
2021-02-07 09:47:23 +01:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
|
|
|
|
|
|
|
if reason.type == "node_damage" and reason.node then
|
2017-03-31 22:18:29 +02:00
|
|
|
-- fire protection
|
2021-02-07 09:47:23 +01:00
|
|
|
if armor.config.fire_protect == true and hp_change < 0 then
|
|
|
|
local name = player:get_player_name()
|
|
|
|
for _,igniter in pairs(armor.fire_nodes) do
|
|
|
|
if reason.node == igniter[1] then
|
2023-02-05 17:44:17 +01:00
|
|
|
if armor.def[name].fire >= igniter[2] then
|
2021-02-07 09:47:23 +01:00
|
|
|
hp_change = 0
|
2017-03-31 22:18:29 +02:00
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-07 09:47:23 +01:00
|
|
|
return hp_change
|
|
|
|
end, true)
|
2017-03-31 22:18:29 +02:00
|
|
|
end
|