From 3291786c1fb4ff1842f39b7749e1b58d1680ecd2 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Sun, 22 Dec 2024 04:37:18 +0100 Subject: [PATCH] Moved particle explosion to mcl_fireworks API - crossbow rockets use the API - fireworks use it obviously - fireworks fly a bit faster too --- mods/ITEMS/mcl_bows/rocket.lua | 190 +------------------------ mods/ITEMS/mcl_fireworks/init.lua | 191 +++++++++++++++++++++++++- mods/ITEMS/mcl_fireworks/register.lua | 3 +- 3 files changed, 194 insertions(+), 190 deletions(-) diff --git a/mods/ITEMS/mcl_bows/rocket.lua b/mods/ITEMS/mcl_bows/rocket.lua index 86f91f211..af8ca1f45 100644 --- a/mods/ITEMS/mcl_bows/rocket.lua +++ b/mods/ITEMS/mcl_bows/rocket.lua @@ -8,6 +8,8 @@ local ROCKET_TIMEOUT = 1 local YAW_OFFSET = -math.pi/2 +local particle_explosion = mcl_fireworks.particle_explosion + local function damage_explosion(self, damagemulitplier, pos) if self._harmless then return end @@ -27,194 +29,6 @@ local function damage_explosion(self, damagemulitplier, pos) end end -local function particle_explosion(pos) - if pos.object then pos = pos.object:get_pos() end - local particle_pattern = math.random(1, 3) - local fpitch - local type = math.random(1, 2) - local size = math.random(1, 3) - local colors = {"red", "yellow", "blue", "green", "white"} - local this_colors = {colors[math.random(#colors)], colors[math.random(#colors)], colors[math.random(#colors)]} - - if size == 1 then - fpitch = math.random(200, 300) - elseif size == 2 then - fpitch = math.random(100, 130) - else - fpitch = math.random(60, 70) - end - - if type == 1 then - core.sound_play("mcl_bows_firework", { - pos = pos, - max_hear_distance = 100, - gain = 3.0, - pitch = fpitch/100 - }, true) - else - core.sound_play("mcl_bows_firework_soft", { - pos = pos, - max_hear_distance = 100, - gain = 4.0, - pitch = fpitch/100 - }, true) - end - - if particle_pattern == 1 then - core.add_particlespawner({ - amount = 400 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-7 * size,-7 * size,-7 * size), - maxvel = vector.new(7 * size,7 * size,7 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[1]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 400 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-2 * size,-2 * size,-2 * size), - maxvel = vector.new(2 * size,2 * size,2 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[2]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 100 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-14 * size,-14 * size,-14 * size), - maxvel = vector.new(14 * size,14 * size,14 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[3]..".png", - glow = 14, - }) - elseif particle_pattern == 2 then - - core.add_particlespawner({ - amount = 240 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-5 * size,-5 * size,-5 * size), - maxvel = vector.new(5 * size,5 * size,5 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[1]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 500 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-2 * size,-2 * size,-2 * size), - maxvel = vector.new(2 * size,2 * size,2 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[2]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 350 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-3 * size,-3 * size,-3 * size), - maxvel = vector.new(3 * size,3 * size,3 * size), - minexptime = .6 * size / 2, - maxexptime = .9 * size / 2, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[3]..".png", - glow = 14, - }) - elseif particle_pattern == 3 then - - core.add_particlespawner({ - amount = 400 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-6 * size,-4 * size,-6 * size), - maxvel = vector.new(6 * size,4 * size,6 * size), - minexptime = .6 * size, - maxexptime = .9 * size, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[1]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 120 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-8 * size,6 * size,-8 * size), - maxvel = vector.new(8 * size,6 * size,8 * size), - minexptime = .6 * size, - maxexptime = .9 * size, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[2]..".png", - glow = 14, - }) - core.add_particlespawner({ - amount = 130 * size, - time = 0.0001, - minpos = pos, - maxpos = pos, - minvel = vector.new(-3 * size,3 * size,-3 * size), - maxvel = vector.new(3 * size,3 * size,3 * size), - minexptime = .6 * size, - maxexptime = .9 * size, - minsize = 2 * size, - maxsize = 3 * size, - collisiondetection = false, - vertical = false, - texture = "mcl_bows_firework_"..this_colors[3]..".png", - glow = 14, - }) - end - - return size - -end - core.register_craftitem("mcl_bows:rocket", { description = S("Arrow"), _tt_help = S("Ammunition").."\n"..S("Damage from bow: 1-10").."\n"..S("Damage from dispenser: 3"), diff --git a/mods/ITEMS/mcl_fireworks/init.lua b/mods/ITEMS/mcl_fireworks/init.lua index cd1922580..45d787677 100644 --- a/mods/ITEMS/mcl_fireworks/init.lua +++ b/mods/ITEMS/mcl_fireworks/init.lua @@ -1,4 +1,193 @@ local path = minetest.get_modpath("mcl_fireworks") +mcl_fireworks = {} + +function mcl_fireworks.particle_explosion(pos) + if pos.object then pos = pos.object:get_pos() end + local particle_pattern = math.random(1, 3) + local fpitch + local type = math.random(1, 2) + local size = math.random(1, 3) + local colors = {"red", "yellow", "blue", "green", "white"} + local this_colors = {colors[math.random(#colors)], colors[math.random(#colors)], colors[math.random(#colors)]} + + if size == 1 then + fpitch = math.random(200, 300) + elseif size == 2 then + fpitch = math.random(100, 130) + else + fpitch = math.random(60, 70) + end + + if type == 1 then + core.sound_play("mcl_bows_firework", { + pos = pos, + max_hear_distance = 100, + gain = 3.0, + pitch = fpitch/100 + }, true) + else + core.sound_play("mcl_bows_firework_soft", { + pos = pos, + max_hear_distance = 100, + gain = 4.0, + pitch = fpitch/100 + }, true) + end + + if particle_pattern == 1 then + core.add_particlespawner({ + amount = 400 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-7 * size,-7 * size,-7 * size), + maxvel = vector.new(7 * size,7 * size,7 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[1]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 400 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-2 * size,-2 * size,-2 * size), + maxvel = vector.new(2 * size,2 * size,2 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[2]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 100 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-14 * size,-14 * size,-14 * size), + maxvel = vector.new(14 * size,14 * size,14 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[3]..".png", + glow = 14, + }) + elseif particle_pattern == 2 then + + core.add_particlespawner({ + amount = 240 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-5 * size,-5 * size,-5 * size), + maxvel = vector.new(5 * size,5 * size,5 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[1]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 500 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-2 * size,-2 * size,-2 * size), + maxvel = vector.new(2 * size,2 * size,2 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[2]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 350 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-3 * size,-3 * size,-3 * size), + maxvel = vector.new(3 * size,3 * size,3 * size), + minexptime = .6 * size / 2, + maxexptime = .9 * size / 2, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[3]..".png", + glow = 14, + }) + elseif particle_pattern == 3 then + + core.add_particlespawner({ + amount = 400 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-6 * size,-4 * size,-6 * size), + maxvel = vector.new(6 * size,4 * size,6 * size), + minexptime = .6 * size, + maxexptime = .9 * size, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[1]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 120 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-8 * size,6 * size,-8 * size), + maxvel = vector.new(8 * size,6 * size,8 * size), + minexptime = .6 * size, + maxexptime = .9 * size, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[2]..".png", + glow = 14, + }) + core.add_particlespawner({ + amount = 130 * size, + time = 0.0001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-3 * size,3 * size,-3 * size), + maxvel = vector.new(3 * size,3 * size,3 * size), + minexptime = .6 * size, + maxexptime = .9 * size, + minsize = 2 * size, + maxsize = 3 * size, + collisiondetection = false, + vertical = false, + texture = "mcl_bows_firework_"..this_colors[3]..".png", + glow = 14, + }) + end + + return size +end + dofile(path .. "/register.lua") -dofile(path .. "/crafting.lua") \ No newline at end of file +dofile(path .. "/crafting.lua") diff --git a/mods/ITEMS/mcl_fireworks/register.lua b/mods/ITEMS/mcl_fireworks/register.lua index bbc42cdcd..5bb8808b2 100644 --- a/mods/ITEMS/mcl_fireworks/register.lua +++ b/mods/ITEMS/mcl_fireworks/register.lua @@ -5,6 +5,7 @@ local description = S("Firework Rocket") local function explode(self, pos) -- temp code + mcl_fireworks.particle_explosion(pos) mcl_mobs.mob_class.boom(self, pos, 1) end @@ -44,7 +45,7 @@ local firework_entity = { vl_projectile.has_tracer, function(self, dtime) - self.object:add_velocity(vector.new(0, 2*dtime, 0)) -- TODO var. accel. TODO max speed? + self.object:add_velocity(vector.new(0, 5*dtime, 0)) -- TODO var. accel. TODO max speed? end, vl_projectile.collides_with_solids,