From 0dc5701d9bb4ee691ac1a577bbe8ab19994811cf Mon Sep 17 00:00:00 2001 From: IamPyu Date: Fri, 8 Nov 2024 18:36:36 -0600 Subject: [PATCH] Added Fireworks --- CHANGELOG.md | 1 + mods/CORE/pyutest/util.lua | 8 +++ mods/ENTITIES/pyutest_entities/api.lua | 6 +- mods/ENTITIES/pyutest_fireworks/init.lua | 84 +++++++++++++++++++++++ mods/ENTITIES/pyutest_fireworks/mod.conf | 1 + mods/ITEMS/pyutest_grass/init.lua | 16 +++++ textures/pyutest-firework-blast.png | Bin 0 -> 78 bytes textures/pyutest-firework.png | Bin 0 -> 154 bytes 8 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 mods/ENTITIES/pyutest_fireworks/init.lua create mode 100644 mods/ENTITIES/pyutest_fireworks/mod.conf create mode 100644 textures/pyutest-firework-blast.png create mode 100644 textures/pyutest-firework.png diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0aae3..9dd30ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ I should just start giving updates a version number to avoid naming updates. - Added various new sounds - Give Fire an animated texture - Added a Sky Dimension for people using `floatlands` mapgen setting in v7 +- Added Fireworks! ## [Oct 20th - Nov 2nd] Update: The Something Update diff --git a/mods/CORE/pyutest/util.lua b/mods/CORE/pyutest/util.lua index fee78ae..bd7feae 100644 --- a/mods/CORE/pyutest/util.lua +++ b/mods/CORE/pyutest/util.lua @@ -303,3 +303,11 @@ function PyuTest.get_inventory_drops(pos, inventory, drops) end end end + +PyuTest.drop_item = function (pos, name) + local o = minetest.add_item(pos, name) + + if o then + o:add_velocity(vector.new(math.random(-2, 2), 5, math.random(-2, 2))) + end +end diff --git a/mods/ENTITIES/pyutest_entities/api.lua b/mods/ENTITIES/pyutest_entities/api.lua index 739da48..9dd9c88 100644 --- a/mods/ENTITIES/pyutest_entities/api.lua +++ b/mods/ENTITIES/pyutest_entities/api.lua @@ -259,11 +259,7 @@ PyuTest.make_mob = function (name, properties, options) local pos = self.object:get_pos() for _, v in pairs(self.options.drops) do - local o = minetest.add_item(pos, v) - - if o then - o:add_velocity(vector.new(math.random(-2, 2), 5, math.random(-2, 2))) - end + PyuTest.drop_item(pos, v) end end }, {__index = class})) diff --git a/mods/ENTITIES/pyutest_fireworks/init.lua b/mods/ENTITIES/pyutest_fireworks/init.lua new file mode 100644 index 0000000..09d8ed9 --- /dev/null +++ b/mods/ENTITIES/pyutest_fireworks/init.lua @@ -0,0 +1,84 @@ +minetest.register_entity("pyutest_fireworks:firework", { + initial_properties = { + visual = "upright_sprite", + textures = {"pyutest-firework.png", "pyutest-firework.png"}, + physical = true + }, + + on_activate = function (self) + self.object:set_velocity(vector.new(0, 10, 0)) + end, + + on_step = function (self, dtime) + local vel = self.object:get_velocity() + if vel.y < 0 then + self:explode() + self.object:remove() + end + + vel.y = vel.y - (2 * dtime) + self.object:set_velocity(vel) + self:trail() + end, + + trail = function (self) + local pos = self.object:get_pos() + + minetest.add_particle({ + pos = pos, + size = 2, + expirationtime = 0.2, + glow = minetest.LIGHT_MAX, + vertical = true, + texture = "pyutest-firework-blast.png" + }) + end, + + explode = function (self) + local color = { + r = math.random(50, 255), + g = math.random(50, 255), + b = math.random(50, 255), + } + local texture = string.format("pyutest-firework-blast.png^[colorize:%s", minetest.colorspec_to_colorstring(color)) + + local pos = self.object:get_pos() + + minetest.add_particlespawner({ + amount = math.random(20, 40), + time = 1.8, + minexptime = 0.4, + maxexptime = 1.4, + minsize = 2, + maxsize = 2, + vertical = false, + glow = minetest.LIGHT_MAX, + + collisiondetection = false, + texture = texture, + minpos = pos, + maxpos = pos, + minvel = vector.new(-6, -6, -6), + maxvel = vector.new( 6, 6, 6), + }) + + minetest.sound_play({ + name = "block_break", + gain = 3, + }, { + pos = pos + }) + end +}) + +PyuTest.make_item("pyutest_fireworks:firework", "Firework", {}, "pyutest-firework.png", { + on_place = function (itemstack, placer, pointed_thing) + if pointed_thing.type == "node" then + local pos = pointed_thing.above + minetest.add_entity(pos, "pyutest_fireworks:firework") + itemstack:take_item() + end + + return itemstack + end +}) diff --git a/mods/ENTITIES/pyutest_fireworks/mod.conf b/mods/ENTITIES/pyutest_fireworks/mod.conf new file mode 100644 index 0000000..15c0bdd --- /dev/null +++ b/mods/ENTITIES/pyutest_fireworks/mod.conf @@ -0,0 +1 @@ +depends = pyutest_tools diff --git a/mods/ITEMS/pyutest_grass/init.lua b/mods/ITEMS/pyutest_grass/init.lua index 6177a5b..bb583f5 100644 --- a/mods/ITEMS/pyutest_grass/init.lua +++ b/mods/ITEMS/pyutest_grass/init.lua @@ -27,6 +27,22 @@ PyuTest.make_grass = function (name, desc, groups, color, ttex, stex, dtex, econ }, type = "shapeless" }) + + minetest.register_decoration({ + deco_type = "simple", + place_on = {name.."_block"}, + sidelen = 16, + fill_ratio = 0.048, + decoration = name.."_plant" + }) + + minetest.register_decoration({ + deco_type = "simple", + place_on = {name.."_block"}, + sidelen = 16, + fill_ratio = 0.022, + decoration = name.."_fern" + }) end PyuTest.make_grass("pyutest_grass:grass", "Grass", { diff --git a/textures/pyutest-firework-blast.png b/textures/pyutest-firework-blast.png new file mode 100644 index 0000000000000000000000000000000000000000..ba9b40df233f4eecb5a4dc9908dba2f9dba29f12 GIT binary patch literal 78 zcmeAS@N?(olHy`uVBq!ia0vp^Od!m`1|*BN@u~nRQBN1g5RRG2fBygfU(W^vYHS(| Z47NX57;e@yxB(R~c)I$ztaD0e0sunW5v~9L literal 0 HcmV?d00001 diff --git a/textures/pyutest-firework.png b/textures/pyutest-firework.png new file mode 100644 index 0000000000000000000000000000000000000000..20d967afb0f17df9fdffa820f3206aa81c6e329b GIT binary patch literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`iJmTwAr`&K2@6akUcC4rKi@`q zaFmfcw$6x61cf|1V6Kv|9V8 zUc{3pE#Y$O84b?HeV#rcoq_pqhJ=AZfCSqS28LE!