0
0
Fork 0

simple totem particles

This commit is contained in:
NO11 2021-10-24 19:31:51 +00:00
parent 2b322a451f
commit dafe860e56
1 changed files with 20 additions and 57 deletions

View File

@ -4,49 +4,7 @@ minetest.register_on_leaveplayer(function(player)
hud_totem[player] = nil
end)
-- Totem particle registration
function rgb_to_hex(r, g, b)
return string.format("%02x%02x%02x", r, g, b)
end
minetest.register_entity("mcl_totems:totem_particle", {
physical = true,
collide_with_objects = false,
collisionbox = { -0.02, -0.02, -0.02, 0.02, 0.02, 0.02 },
pointable = false,
visual = "sprite",
visual_size = { x = 0.2, y = 0.2 },
spritediv = { x = 1, y = 1 },
initial_sprite_basepos = { x = 0, y = 0 },
static_save = false,
glow = 14,
on_activate = function(self, staticdata)
local color
if math.random(0, 3) == 0 then
color = rgb_to_hex( 153 + math.random() * 51, 153 + math.random() * 76.5, math.random() * 51)
else
color = rgb_to_hex(25.5 + math.random() * 102, 153 + math.random() * 76.5, math.random() * 51)
end
self.object:set_properties({
textures = { "mcl_particles_totem"..math.random(1, 4)..".png^[colorize:#"..color }
})
local t = math.random(1, 2)*math.random()
minetest.after(t, function()
self.object:set_velocity({ x = math.random(-4, 4) * math.random(), y = math.random(-1, 4) * math.random(), z = math.random(-4, 4) * math.random() })
end)
minetest.after(0.3 + t, function()
self.object:set_acceleration({ x = 0, y = -4, z = 0 })
self.object:set_velocity({ x = 0, y = 0, z = 0 })
end)
end,
on_step = function(self, dtime)
local r = math.random(1, 50)
if r == 1 then
self.object:remove()
end
end
})
local particle_colors = {"98BF22", "C49E09", "337D0B", "B0B021", "1E9200"} -- TODO: real MC colors
-- Save the player from death when holding totem of undying in hand
mcl_damage.register_modifier(function(obj, damage, reason)
@ -74,27 +32,32 @@ mcl_damage.register_modifier(function(obj, damage, reason)
end
-- Effects
minetest.sound_play({ name = "mcl_totems_totem", gain = 1 }, { pos = ppos, max_hear_distance = 16 }, true)
--Particles
minetest.sound_play({name = "mcl_totems_totem", gain = 1}, {pos=ppos, max_hear_distance = 16}, true)
minetest.after(0.1, function()
local new_pos = obj:get_pos()
if not new_pos then return end
local particlepos = { x = new_pos.x, y = new_pos.y + 1, z = new_pos.z }
for i = 1, 150 do
minetest.add_entity(particlepos, "mcl_totems:totem_particle")
end
end)
for i = 1, 100 do
minetest.add_particle({
pos = vector.offset(ppos, 0, math.random(-10, 10) / 10, 0),
velocity = vector.new(math.random(-15, 15) / 10, math.random(0, 15) / 10, math.random(-15, 15) / 10),
acceleration = vector.new(0, -math.random(1, 10) / 10, 0),
expirationtime = math.random(1, 3),
size = math.random(1, 2),
collisiondetection = true,
collision_removal = true,
object_collision = false,
texture = "mcl_particles_totem" .. math.random(1, 4) .. ".png^[colorize:#" .. particle_colors[math.random(#particle_colors)],
glow = 10,
})
end
-- 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 },
position = {x = 0.5, y = 1},
scale = {x = 17, y = 17},
offset = {x = 0, y = -178},
z_index = 100,
})
minetest.after(3, function()