mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
Faster rgb to hex
This commit is contained in:
parent
509568b4b0
commit
5ceb48fcb1
@ -5,64 +5,43 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Totem particle registration
|
-- Totem particle registration
|
||||||
function rgb_to_hex(rgb)
|
|
||||||
local hexadecimal = "#"
|
|
||||||
|
|
||||||
for key, value in pairs(rgb) do
|
function rgb_to_hex(r, g, b)
|
||||||
local hex = ""
|
return string.format("%02x%02x%02x", r, g, b)
|
||||||
|
|
||||||
while value > 0 do
|
|
||||||
local index = math.fmod(value, 16) + 1
|
|
||||||
value = math.floor(value / 16)
|
|
||||||
hex = string.sub("0123456789ABCDEF", index, index) .. hex
|
|
||||||
end
|
|
||||||
|
|
||||||
local len = string.len(hex)
|
|
||||||
|
|
||||||
if len == 0 then
|
|
||||||
hex = "00"
|
|
||||||
elseif len == 1 then
|
|
||||||
hex = "0" .. hex
|
|
||||||
end
|
|
||||||
|
|
||||||
hexadecimal = hexadecimal .. hex
|
|
||||||
end
|
|
||||||
|
|
||||||
return hexadecimal
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("mcl_totems:totem_particle", {
|
minetest.register_entity("mcl_totems:totem_particle", {
|
||||||
physical = true,
|
physical = true,
|
||||||
collide_with_objects = false,
|
collide_with_objects = false,
|
||||||
collisionbox = {-0.02,-0.02,-0.02, 0.02,0.02,0.02},
|
collisionbox = { -0.02, -0.02, -0.02, 0.02, 0.02, 0.02 },
|
||||||
pointable = false,
|
pointable = false,
|
||||||
visual = "sprite",
|
visual = "sprite",
|
||||||
visual_size = {x=0.2, y=0.2},
|
visual_size = { x = 0.2, y = 0.2 },
|
||||||
spritediv = {x=1, y=1},
|
spritediv = { x = 1, y = 1 },
|
||||||
initial_sprite_basepos = {x=0, y=0},
|
initial_sprite_basepos = { x = 0, y = 0 },
|
||||||
static_save = false,
|
static_save = false,
|
||||||
glow = 14,
|
glow = 14,
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
local color
|
local color
|
||||||
if math.random(0, 3) == 0 then
|
if math.random(0, 3) == 0 then
|
||||||
color = rgb_to_hex({ (0.6 + math.random() * 0.2) * 255, (0.6 + math.random() * 0.3) * 255, (math.random() * 0.2) * 255 })
|
color = rgb_to_hex( 153 + math.random() * 51, 153 + math.random() * 76.5, math.random() * 51)
|
||||||
else
|
else
|
||||||
color = rgb_to_hex({ (0.1 + math.random() * 0.4) * 255, (0.6 + math.random() * 0.3) * 255, (math.random() * 0.2) * 255 })
|
color = rgb_to_hex(25.5 + math.random() * 102, 153 + math.random() * 76.5, math.random() * 51)
|
||||||
end
|
end
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures = { "mcl_particles_totem"..math.random(1, 4)..".png^[colorize:"..color }
|
textures = { "mcl_particles_totem"..math.random(1, 4)..".png^[colorize:#"..color }
|
||||||
})
|
})
|
||||||
local t = math.random(1, 2)*math.random()
|
local t = math.random(1, 2)*math.random()
|
||||||
minetest.after(t, function()
|
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()})
|
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)
|
end)
|
||||||
minetest.after(0.3 + t, function()
|
minetest.after(0.3 + t, function()
|
||||||
self.object:set_acceleration({x=0, y=-4, z=0})
|
self.object:set_acceleration({ x = 0, y = -4, z = 0 })
|
||||||
self.object:set_velocity({x=0, y=0, z=0})
|
self.object:set_velocity({ x = 0, y = 0, z = 0 })
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local r = math.random(1,50)
|
local r = math.random(1, 50)
|
||||||
if r == 1 then
|
if r == 1 then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
@ -79,7 +58,7 @@ mcl_damage.register_modifier(function(obj, damage, reason)
|
|||||||
local ppos = obj:get_pos()
|
local ppos = obj:get_pos()
|
||||||
local pnname = minetest.get_node(ppos).name
|
local pnname = minetest.get_node(ppos).name
|
||||||
-- Some exceptions when _not_ to save the player
|
-- Some exceptions when _not_ to save the player
|
||||||
for n=1, #mobs_mc.misc.totem_fail_nodes do
|
for n = 1, #mobs_mc.misc.totem_fail_nodes do
|
||||||
if pnname == mobs_mc.misc.totem_fail_nodes[n] then
|
if pnname == mobs_mc.misc.totem_fail_nodes[n] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -95,14 +74,14 @@ mcl_damage.register_modifier(function(obj, damage, reason)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Effects
|
-- Effects
|
||||||
minetest.sound_play({name = "mcl_totems_totem", gain=1}, {pos=ppos, max_hear_distance=16}, true)
|
minetest.sound_play({ name = "mcl_totems_totem", gain = 1 }, { pos = ppos, max_hear_distance = 16 }, true)
|
||||||
|
|
||||||
--Particles
|
--Particles
|
||||||
|
|
||||||
minetest.after(0.1, function()
|
minetest.after(0.1, function()
|
||||||
local new_pos = obj:get_pos()
|
local new_pos = obj:get_pos()
|
||||||
if not new_pos then return end
|
if not new_pos then return end
|
||||||
local particlepos = {x = new_pos.x, y = new_pos.y + 1, z = new_pos.z}
|
local particlepos = { x = new_pos.x, y = new_pos.y + 1, z = new_pos.z }
|
||||||
for i = 1, 150 do
|
for i = 1, 150 do
|
||||||
minetest.add_entity(particlepos, "mcl_totems:totem_particle")
|
minetest.add_entity(particlepos, "mcl_totems:totem_particle")
|
||||||
end
|
end
|
||||||
@ -113,9 +92,9 @@ mcl_damage.register_modifier(function(obj, damage, reason)
|
|||||||
hud_totem[obj] = obj:hud_add({
|
hud_totem[obj] = obj:hud_add({
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
text = "mcl_totems_totem.png",
|
text = "mcl_totems_totem.png",
|
||||||
position = { x=0.5, y=1 },
|
position = { x = 0.5, y = 1 },
|
||||||
scale = { x=17, y=17 },
|
scale = { x = 17, y = 17 },
|
||||||
offset = { x=0, y=-178 },
|
offset = { x = 0, y = -178 },
|
||||||
z_index = 100,
|
z_index = 100,
|
||||||
})
|
})
|
||||||
minetest.after(3, function()
|
minetest.after(3, function()
|
||||||
@ -131,4 +110,4 @@ mcl_damage.register_modifier(function(obj, damage, reason)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, 1000)
|
end, 1000)
|
||||||
|
Loading…
Reference in New Issue
Block a user