1
0
Fork 0

Implement respiration

respiration
cora 2022-10-16 03:30:34 +02:00 committed by Gitea
parent 23f0c9a83e
commit 333ae2e3a5
2 changed files with 28 additions and 5 deletions

View File

@ -197,11 +197,29 @@ function mcl_armor.register_protection_enchantment(def)
} }
end end
local function activate_respiration(player,r)
if player:get_meta():get_int("respiration") ~= 0 then return end
if r then
local new_breath = 15 + (15 * r)
player:get_meta():set_int("respiration",r)
player:set_properties({breath_max=new_breath})
if player:get_breath() == 15 then
player:set_breath(new_breath)
end
end
end
local function deactivate_respiration(player)
if player:get_meta():get_int("respiration") == 0 then return end
player:get_meta():set_int("respiration",0)
player:set_properties({breath_max=15})
end
function mcl_armor.update(obj) function mcl_armor.update(obj)
local info = {points = 0, view_range_factors = {}} local info = {points = 0, view_range_factors = {}}
local inv = mcl_util.get_inventory(obj) local inv = mcl_util.get_inventory(obj)
local resp = 0
if inv then if inv then
for i = 2, 5 do for i = 2, 5 do
local itemstack = inv:get_stack("armor", i) local itemstack = inv:get_stack("armor", i)
@ -210,8 +228,8 @@ function mcl_armor.update(obj)
if minetest.registered_aliases[itemname] then if minetest.registered_aliases[itemname] then
itemname = minetest.registered_aliases[itemname] itemname = minetest.registered_aliases[itemname]
end end
if not itemstack:is_empty() then if not itemstack:is_empty() then
resp = math.max(mcl_enchanting.get_enchantments(itemstack).respiration or 0, resp or 0)
local def = itemstack:get_definition() local def = itemstack:get_definition()
local texture = def._mcl_armor_texture local texture = def._mcl_armor_texture
@ -247,6 +265,11 @@ function mcl_armor.update(obj)
info.texture = info.texture or "blank.png" info.texture = info.texture or "blank.png"
if obj:is_player() then if obj:is_player() then
if resp ~= 0 then
activate_respiration(obj,resp)
else
deactivate_respiration(obj)
end
mcl_armor.update_player(obj, info) mcl_armor.update_player(obj, info)
else else
local luaentity = obj:get_luaentity() local luaentity = obj:get_luaentity()

View File

@ -519,8 +519,8 @@ mcl_enchanting.enchantments.quick_charge = {
inv_tool_tab = false, inv_tool_tab = false,
} }
-- unimplemented -- implemented in mcl_armor/api.lua
--[[mcl_enchanting.enchantments.respiration = { mcl_enchanting.enchantments.respiration = {
name = S("Respiration"), name = S("Respiration"),
max_level = 3, max_level = 3,
primary = {armor_head = true}, primary = {armor_head = true},
@ -536,7 +536,7 @@ mcl_enchanting.enchantments.quick_charge = {
power_range_table = {{10, 40}, {20, 50}, {30, 60}}, power_range_table = {{10, 40}, {20, 50}, {30, 60}},
inv_combat_tab = true, inv_combat_tab = true,
inv_tool_tab = false, inv_tool_tab = false,
}]]-- }
-- requires missing MineClone2 feature -- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.riptide = { --[[mcl_enchanting.enchantments.riptide = {