VoxeLibre/mods/ITEMS/mcl_totems/init.lua

86 lines
2.4 KiB
Lua
Raw Normal View History

2021-04-23 14:40:51 +03:00
local hud_totem = {}
2021-04-23 14:40:51 +03:00
minetest.register_on_leaveplayer(function(player)
hud_totem[player] = nil
end)
2021-10-24 22:31:51 +03:00
local particle_colors = {"98BF22", "C49E09", "337D0B", "B0B021", "1E9200"} -- TODO: real MC colors
2021-05-29 22:24:16 +03:00
2021-04-23 14:40:51 +03:00
-- 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
2021-07-12 21:05:52 +03:00
for n = 1, #mobs_mc.misc.totem_fail_nodes do
2021-04-23 14:40:51 +03:00
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
2021-10-24 22:31:51 +03:00
minetest.sound_play({name = "mcl_totems_totem", gain = 1}, {pos=ppos, max_hear_distance = 16}, true)
2021-06-08 18:13:00 +03:00
for i = 1, 4 do
for c = 1, #particle_colors do
minetest.add_particlespawner({
2021-10-25 23:25:34 +03:00
amount = math.floor(100 / (4 * #particle_colors)),
time = 1,
minpos = vector.offset(ppos, 0, -1, 0),
maxpos = vector.offset(ppos, 0, 1, 0),
minvel = vector.new(-1.5, 0, -1.5),
maxvel = vector.new(1.5, 1.5, 1.5),
minacc = vector.new(0, -0.1, 0),
maxacc = vector.new(0, -1, 0),
minexptime = 1,
maxexptime = 3,
minsize = 1,
maxsize = 2,
collisiondetection = true,
collision_removal = true,
object_collision = false,
vertical = false,
texture = "mcl_particles_totem" .. i .. ".png^[colorize:#" .. particle_colors[c],
glow = 10,
})
end
2021-10-24 22:31:51 +03:00
end
2021-05-29 22:24:16 +03:00
2021-08-26 13:17:15 +03:00
-- Big totem overlay
2021-04-23 14:40:51 +03:00
if not hud_totem[obj] then
hud_totem[obj] = obj:hud_add({
hud_elem_type = "image",
text = "mcl_totems_totem.png",
2021-10-24 22:31:51 +03:00
position = {x = 0.5, y = 1},
scale = {x = 17, y = 17},
offset = {x = 0, y = -178},
2021-04-23 14:40:51 +03:00
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
2021-07-12 21:05:52 +03:00
end, 1000)