From de0ab3351aa014a7c82a8f39470ec13e2a414049 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 12 Oct 2016 21:57:06 +0200 Subject: [PATCH] particles for mob spawners --- spawners_mobs/api.lua | 90 +++++++++++++++--- spawners_mobs/spawners_mobs.lua | 47 ++++----- .../textures/spawners_mobs_flame_particle.png | Bin 0 -> 278 bytes .../spawners_mobs_smoke2_particle.png | Bin 0 -> 233 bytes .../textures/spawners_mobs_smoke_particle.png | Bin 233 -> 170 bytes .../textures/spawners_mobs_spawner_16.png | Bin 0 -> 329 bytes 6 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 spawners_mobs/textures/spawners_mobs_flame_particle.png create mode 100644 spawners_mobs/textures/spawners_mobs_smoke2_particle.png create mode 100644 spawners_mobs/textures/spawners_mobs_spawner_16.png diff --git a/spawners_mobs/api.lua b/spawners_mobs/api.lua index 735bd9b..ff12eae 100644 --- a/spawners_mobs/api.lua +++ b/spawners_mobs/api.lua @@ -38,9 +38,68 @@ for k, mob_mod in ipairs(ENABLED_MODS) do end end +-- particles +function spawners_mobs.cloud_booom(pos) + minetest.add_particlespawner({ + amount = 5, + time = 2, + minpos = vector.subtract({x=pos.x-0.5, y=pos.y, z=pos.z-0.5}, 0.5), + maxpos = vector.add({x=pos.x+0.5, y=pos.y, z=pos.z+0.5}, 0.5), + minvel = {x=0.1, y=0.1, z=0.1}, + maxvel = {x=0.2, y=0.2, z=0.2}, + minacc = vector.new({x=-0.1, y=0.1, z=-0.1}), + maxacc = vector.new({x=0.1, y=0.3, z=0.1}), + minexptime = 2, + maxexptime = 3, + minsize = 4, + maxsize = 8, + texture = "spawners_mobs_smoke2_particle.png", + }) +end + +function spawners_mobs.add_flame_effects(pos) + local id = minetest.add_particlespawner({ + amount = 6, + time = 0, + minpos = vector.subtract({x=pos.x-0.001, y=pos.y-0.001, z=pos.z-0.001}, 0.5), + maxpos = vector.add({x=pos.x+0.001, y=pos.y+0.001, z=pos.z+0.001}, 0.5), + minvel = {x=-0.1, y=-0.1, z=-0.1}, + maxvel = {x=0.1, y=0.1, z=0.1}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = 1, + maxexptime = 5, + minsize = .5, + maxsize = 2.5, + texture = "spawners_mobs_flame_particle.png", + }) + + return id +end + +function spawners_mobs.add_smoke_effects(pos) + local id = minetest.add_particlespawner({ + amount = 1, + time = 0, + minpos = vector.subtract({x=pos.x-0.001, y=pos.y-0.001, z=pos.z-0.001}, 0.5), + maxpos = vector.add({x=pos.x+0.001, y=pos.y+0.001, z=pos.z+0.001}, 0.5), + minvel = {x=-0.5, y=0.5, z=-0.5}, + maxvel = {x=0.5, y=1.5, z=0.5}, + minacc = vector.new({x=-0.1, y=0.1, z=-0.1}), + maxacc = vector.new({x=0.1, y=0.3, z=0.1}), + minexptime = .5, + maxexptime = 1.5, + minsize = .5, + maxsize = 2, + texture = "spawners_mobs_smoke_particle.png", + }) + + return id +end + -- start spawning mobs -function spawners_mobs.start_spawning(pos, how_many, mob_name, mod_prefix, sound_custom) - if not (pos or how_many or mob_name) then return end +function spawners_mobs.start_spawning(random_pos, how_many, mob_name, mod_prefix, sound_custom, pos) + if not (random_pos or how_many or mob_name) then return end local sound_name -- remove 'spawners_mobs:' from the string @@ -64,18 +123,25 @@ function spawners_mobs.start_spawning(pos, how_many, mob_name, mod_prefix, sound end for i=1,how_many do - pos.y = pos.y+1 - local obj = minetest.add_entity(pos, mod_prefix..":"..mob_name) + random_pos.y = random_pos.y+1 + + spawners_mobs.cloud_booom(random_pos) - if obj then - if sound_name then - minetest.sound_play(sound_name, { - pos = pos, - max_hear_distance = 32, - gain = 5, - }) + local obj + + minetest.after(1, function() + obj = minetest.add_entity(random_pos, mod_prefix..":"..mob_name) + + if obj then + if sound_name then + minetest.sound_play(sound_name, { + random_pos = random_pos, + max_hear_distance = 32, + gain = 5, + }) + end end - end + end) end end diff --git a/spawners_mobs/spawners_mobs.lua b/spawners_mobs/spawners_mobs.lua index 774025d..f16d3c6 100644 --- a/spawners_mobs/spawners_mobs.lua +++ b/spawners_mobs/spawners_mobs.lua @@ -43,12 +43,6 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, minetest.register_entity("spawners_mobs:dummy_"..mod_prefix.."_"..mob_name, dummy_definition) - -- - -- * CRAFTING SPAWNERS * - -- - - -- print("[Mod][Spawners] Registering Crafting Spawner.") - -- -- ACTIVE SPAWNER -- @@ -56,29 +50,38 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, minetest.register_node("spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner_active", { description = mod_prefix.."_"..mob_name.." spawner active", paramtype = "light", - light_source = 4, + light_source = 6 , drawtype = "allfaces", walkable = true, sounds = default.node_sound_stone_defaults(), damage_per_second = 4, sunlight_propagates = true, - tiles = { - { - name = "spawners_mobs_spawner_animated.png", - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0 - }, - } - }, + tiles = {"spawners_mobs_spawner_16.png"}, is_ground_content = true, groups = {cracky=1,level=2,igniter=1,not_in_creative_inventory=1}, drop = "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner", on_construct = function(pos) pos.y = pos.y + offset minetest.add_entity(pos,"spawners_mobs:dummy_"..mod_prefix.."_"..mob_name) + local id_flame = spawners_mobs.add_flame_effects(pos) + local id_smoke = spawners_mobs.add_smoke_effects(pos) + local meta = minetest.get_meta(pos) + print("construct: "..id_flame) + print("construct: "..id_smoke) + meta:set_int("id_flame", id_flame) + meta:set_int("id_smoke", id_smoke) + end, + on_destruct = function(pos) + local meta = minetest.get_meta(pos) + local id_flame = meta:get_int("id_flame") + local id_smoke = meta:get_int("id_smoke") + + if id_flame and id_smoke and id_flame ~= nil and id_smoke ~= nil then + print("destruct: "..id_flame) + print("destruct: "..id_smoke) + minetest.delete_particlespawner(id_flame) + minetest.delete_particlespawner(id_smoke) + end end, }) @@ -122,7 +125,7 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, walkable = true, sounds = default.node_sound_stone_defaults(), sunlight_propagates = true, - tiles = {"spawners_mobs_spawner.png"}, + tiles = {"spawners_mobs_spawner_16.png"}, is_ground_content = true, groups = {cracky=1,level=2}, stack_max = 1, @@ -151,7 +154,7 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, sounds = default.node_sound_stone_defaults(), damage_per_second = 4, sunlight_propagates = true, - tiles = {"spawners_mobs_spawner.png^[colorize:#FF000030"}, + tiles = {"spawners_mobs_spawner_16.png^[colorize:#FF000030"}, is_ground_content = true, groups = {cracky=1,level=2,igniter=1,not_in_creative_inventory=1}, drop = "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner", @@ -176,7 +179,7 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, }, neighbors = {"air"}, interval = 10.0, - chance = 6, + chance = 5, catch_up = false, action = function(pos, node, active_object_count, active_object_count_wider) @@ -208,7 +211,7 @@ function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, end -- enough place to spawn more mobs - spawners_mobs.start_spawning(random_pos, 1, "spawners_mobs:"..mob_name, mod_prefix, sound_custom) + spawners_mobs.start_spawning(random_pos, 1, "spawners_mobs:"..mob_name, mod_prefix, sound_custom, pos) elseif waiting then -- waiting status diff --git a/spawners_mobs/textures/spawners_mobs_flame_particle.png b/spawners_mobs/textures/spawners_mobs_flame_particle.png new file mode 100644 index 0000000000000000000000000000000000000000..c63d52ad58ae4120ab72d79946bf5311d39b6a6d GIT binary patch literal 278 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPE^4e$wZ%`eLR&%p3Mi{aUF(f>CX z{(n98|Ns9*tl64C1&k#@e!&b5&u*lFI7!~_E({&4vK~MVXMsm#F#`kN0T5=)y4J}F z6l5>)^mS!_z{M@dZzUb5v;!z4S>hT|;+&tGo0?a`;9QiNSdyBeP@Y+mq2TW68xY>e zCk|8;>gnPb!f`!00SHnWnABJ`nvXJ^3gB$H(4%*bDS>VCY;Ko{9oZd3p^r=85p>QL70(Y)*K0-AbW|YuPgflMtL3qew(+N z|A9g=o-U3d9M@gX9ppTqz{7e$zUswAK`XEDY;$2Nhwy?HIng8W`vuQD6r3zC@PVu0 z?t514Hxn-2Jkb)%QaB+p#8y0V;`zg7yA7ppFY9hA4w`GoJ$Y3@o9)W_qe@|aPx||P U4xd~x9cT}Or>mdKI;Vst0FT2;djJ3c literal 0 HcmV?d00001 diff --git a/spawners_mobs/textures/spawners_mobs_smoke_particle.png b/spawners_mobs/textures/spawners_mobs_smoke_particle.png index 89d81c146dfc92d2528e05abcd0fa5892d1902a8..c70a9be4be2108e849f4b13bd4486c4dec815e78 100644 GIT binary patch delta 122 zcmaFKxQfxZGr-TCmrII^fq{Y7)59eQNDF{4BQuaxwarxmQfvV}A+A7LTU*$TRx1OAfx@z$E{-7_*OL>bCp0W*l2$4MGr-TCmrII^fq{Y7)59eQNGpIaBQucn-11^OkYWq)32_C||NsAAdUO8W ziN=<-jPg7J{5Eej{{w|%JY5_^IIg>%JIHxJfrs^ieASDKf>vJP+2+Dl4&enYa-v7# z_Y0nRC^%VO-~(5~-S@28Zzf#4d7>qjrEo%Ih^=_!#Pf&Eb{k6HUe?`K95mOEd-AG+ gHrti;N0q|2o2H&HgSRWY_xGj(vg6LuVEC1XjD zUoeBivm0qZPKT$9V@SoV*gkim!wwuQnPE{+pUnCE|9-}Xk_kK^g$Y#>D+52B-q648 zu(0Tw+LSvh-@Fl$pEzyP@_T+=M?^cdH`Ol@a%B!zxO_0folmJSD5vfK&&egGt6SMO z>#yYBw5TEZ-12a#TG2_~0+sp`eqVAv-}QI9%