Integrate totems

This commit is contained in:
Lizzy Fleckenstein 2021-04-23 13:40:51 +02:00
parent 50b6f03977
commit 78355c5c57
3 changed files with 59 additions and 66 deletions

View File

@ -516,8 +516,6 @@ end
-- Evoker -- Evoker
if c("totem") then if c("totem") then
local hud_totem = {}
-- Totem of Undying -- Totem of Undying
minetest.register_craftitem("mobs_mc:totem", { minetest.register_craftitem("mobs_mc:totem", {
description = S("Totem of Undying"), description = S("Totem of Undying"),
@ -527,66 +525,8 @@ if c("totem") then
inventory_image = "mcl_totems_totem.png", inventory_image = "mcl_totems_totem.png",
wield_image = "mcl_totems_totem.png", wield_image = "mcl_totems_totem.png",
stack_max = 1, stack_max = 1,
groups = {combat_item=1},
}) })
minetest.register_on_leaveplayer(function(player)
hud_totem[player:get_player_name()] = nil
end)
-- Save the player from death when holding totem of undying in hand
minetest.register_on_player_hpchange(function(player, hp_change)
local hp = player:get_hp()
-- Fatal damage?
if hp + hp_change <= 0 then
local wield = player:get_wielded_item()
if wield:get_name() == "mobs_mc:totem" then
local ppos = player:get_pos()
local pnname = minetest.get_node(ppos).name
-- Some exceptions when _not_ to save the player
for n=1, #mobs_mc.misc.totem_fail_nodes do
if pnname == mobs_mc.misc.totem_fail_nodes[n] then
return hp_change
end
end
-- Reset breath as well
if player:get_breath() < 11 then
player:set_breath(10)
end
if not minetest.is_creative_enabled(player:get_player_name()) then
wield:take_item()
player:set_wielded_item(wield)
end
-- Effects
minetest.sound_play({name = "mcl_totems_totem", gain=1}, {pos=ppos, max_hear_distance=16}, true)
-- Big totem overlay
if not hud_totem[player:get_player_name()] then
hud_totem[player:get_player_name()] = player:hud_add({
hud_elem_type = "image",
text = "mcl_totems_totem.png",
position = { x=0.5, y=1 },
scale = { x=17, y=17 },
offset = { x=0, y=-178 },
z_index = 100,
})
minetest.after(3, function(name)
local player = minetest.get_player_by_name(name)
if player and player:is_player() then
local name = player:get_player_name()
if hud_totem[name] then
player:hud_remove(hud_totem[name])
hud_totem[name] = nil
end
end
end, player:get_player_name())
end
-- Set HP to exactly 1
return -hp + 1
end
end
return hp_change
end, true)
end end
-- Rotten flesh -- Rotten flesh

View File

@ -1,5 +1,58 @@
-- Node is currently defined in mobs_mc. local hud_totem = {}
-- TODO: Add full item definition here when status effects become a thing.
-- Add group for Creative Mode. minetest.register_on_leaveplayer(function(player)
minetest.override_item("mobs_mc:totem", {groups = { combat_item=1}}) hud_totem[player] = nil
end)
-- Save the player from death when holding totem of undying in hand
mcl_damage.register_modifier(function(obj, damage, reason)
if obj:is_player() then
local hp = obj:get_hp()
if hp - damage <= 0 then
local wield = obj:get_wielded_item()
if wield:get_name() == "mobs_mc:totem" then
local ppos = obj:get_pos()
local pnname = minetest.get_node(ppos).name
-- Some exceptions when _not_ to save the player
for n=1, #mobs_mc.misc.totem_fail_nodes do
if pnname == mobs_mc.misc.totem_fail_nodes[n] then
return
end
end
-- Reset breath as well
if obj:get_breath() < 11 then
obj:set_breath(10)
end
if not minetest.is_creative_enabled(obj:get_player_name()) then
wield:take_item()
obj:set_wielded_item(wield)
end
-- Effects
minetest.sound_play({name = "mcl_totems_totem", gain=1}, {pos=ppos, max_hear_distance=16}, true)
-- Big totem overlay
if not hud_totem[obj] then
hud_totem[obj] = obj:hud_add({
hud_elem_type = "image",
text = "mcl_totems_totem.png",
position = { x=0.5, y=1 },
scale = { x=17, y=17 },
offset = { x=0, y=-178 },
z_index = 100,
})
minetest.after(3, function()
if obj:is_player() then
obj:hud_remove(hud_totem[obj])
hud_totem[obj] = nil
end
end)
end
-- Set HP to exactly 1
return hp - 1
end
end
end
end, 1000)

View File

@ -1,2 +1,2 @@
name = mcl_totems name = mcl_totems
depends = mobs_mc depends = mobs_mc, mcl_damage