From d4ca99f09ea3eccffaa8f6b64418675075aa4fb6 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Fri, 27 Dec 2024 04:20:01 +0100 Subject: [PATCH] Added firework stars - empty fireworks now have a simple boom - fireworks with generic stars have a colorful boom --- mods/HELP/mcl_tt/snippets_mcl.lua | 4 ++- mods/HUD/mcl_inventory/creative.lua | 4 +++ mods/ITEMS/mcl_mobitems/init.lua | 3 +- mods/ITEMS/vl_fireworks/crafting.lua | 40 ++++++++++++++++++++--- mods/ITEMS/vl_fireworks/rockets.lua | 47 ++++++++++++++++++--------- mods/ITEMS/vl_fireworks/star.lua | 12 +++++++ textures/vl_fireworks_star.png | Bin 0 -> 241 bytes 7 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 textures/vl_fireworks_star.png diff --git a/mods/HELP/mcl_tt/snippets_mcl.lua b/mods/HELP/mcl_tt/snippets_mcl.lua index 384d590c0..76665f897 100644 --- a/mods/HELP/mcl_tt/snippets_mcl.lua +++ b/mods/HELP/mcl_tt/snippets_mcl.lua @@ -196,7 +196,9 @@ tt.register_snippet(function(itemstring, _, itemstack) local s = "" local meta = itemstack:get_meta() - s = s .. def._vl_fireworks_tt(meta:get_float("vl_fireworks:duration")) + local stars = meta:get("vl_fireworks:stars") or core.serialize({}) + s = s .. def._vl_fireworks_tt(meta:get_float("vl_fireworks:duration"), + core.deserialize(stars)) return s:trim() end) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index a2e510d53..5a2a79ce3 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -116,6 +116,7 @@ minetest.register_on_mods_loaded(function() nonmisc = true end if def._vl_fireworks_std_durs_forces then + local generic = core.serialize({{fn="generic"}}) for i, tbl in ipairs(def._vl_fireworks_std_durs_forces) do local stack = ItemStack(name) local meta = stack:get_meta() @@ -123,6 +124,9 @@ minetest.register_on_mods_loaded(function() meta:set_int("vl_fireworks:force", tbl[2]) table.insert(inventory_lists["misc"], stack:to_string()) table.insert(inventory_lists["all"], stack:to_string()) + meta:set_string("vl_fireworks:stars", generic) + table.insert(inventory_lists["misc"], stack:to_string()) + table.insert(inventory_lists["all"], stack:to_string()) end nonmisc = true all_handled = true diff --git a/mods/ITEMS/mcl_mobitems/init.lua b/mods/ITEMS/mcl_mobitems/init.lua index a3155b13c..edf07c7bd 100644 --- a/mods/ITEMS/mcl_mobitems/init.lua +++ b/mods/ITEMS/mcl_mobitems/init.lua @@ -313,8 +313,7 @@ minetest.register_craftitem("mcl_mobitems:nether_star", { _doc_items_longdesc = S("A nether star is dropped when the Wither dies. Place it in an item frame to show the world how hardcore you are! Or just as decoration."), wield_image = "mcl_mobitems_nether_star.png", inventory_image = "mcl_mobitems_nether_star.png", - -- TODO: Reveal item when it's useful - groups = { craftitem = 1, not_in_creative_inventory = 1 }, + groups = { craftitem = 1 }, stack_max = 64, }) diff --git a/mods/ITEMS/vl_fireworks/crafting.lua b/mods/ITEMS/vl_fireworks/crafting.lua index 60b371a02..b18ef6066 100644 --- a/mods/ITEMS/vl_fireworks/crafting.lua +++ b/mods/ITEMS/vl_fireworks/crafting.lua @@ -1,11 +1,27 @@ +-- Firework Star +core.register_craft({ -- temporary + type = "shapeless", + output = "vl_fireworks:firework_star", + recipe = {"mcl_mobitems:gunpowder", "mcl_core:clay_lump"} +}) + +-- Firework Rocket local function register_firework_crafts() - local recipe = {"mcl_core:paper"} + local r1 = {"mcl_core:paper"} + local r2 = table.copy(r1) + table.insert(r2, "vl_fireworks:firework_star") -- TODO replace with a loop or such to allow more stars for i=1, 3 do - table.insert(recipe, "mcl_mobitems:gunpowder") - minetest.register_craft({ + table.insert(r1, "mcl_mobitems:gunpowder") + table.insert(r2, "mcl_mobitems:gunpowder") + core.register_craft({ type = "shapeless", output = "vl_fireworks:rocket 3", - recipe = recipe, + recipe = r1, + }) + core.register_craft({ + type = "shapeless", + output = "vl_fireworks:rocket 3", + recipe = r2, }) end end @@ -13,14 +29,28 @@ register_firework_crafts() local function craft_firework(itemstack, player, old_grid) if itemstack:get_name() ~= "vl_fireworks:rocket" then return end - local gp = 0 + local gp = 0 -- gunpowder + local stars = {} + + -- analyze the recipe used for _, item in pairs(old_grid) do if item:get_name() == "mcl_mobitems:gunpowder" then gp = gp + 1 end + if item:get_name() == "vl_fireworks:firework_star" then + local effect = item:get_meta():get("vl_fireworks:star_effect") + or core.serialize({fn="generic"}) + table.insert(stars, effect) + end end + + -- determine duration and force from the amount of gunpowder used local tbl = vl_fireworks.firework_def._vl_fireworks_std_durs_forces[gp] local meta = itemstack:get_meta() meta:set_float("vl_fireworks:duration", tbl[1]) meta:set_int("vl_fireworks:force", tbl[2]) + + -- write star effects into metadata + meta:set_string("vl_fireworks:stars", core.serialize(stars)) + tt.reload_itemstack_description(itemstack) return itemstack end diff --git a/mods/ITEMS/vl_fireworks/rockets.lua b/mods/ITEMS/vl_fireworks/rockets.lua index 4f2af0034..5dfdcbaf6 100644 --- a/mods/ITEMS/vl_fireworks/rockets.lua +++ b/mods/ITEMS/vl_fireworks/rockets.lua @@ -1,14 +1,19 @@ -local S = minetest.get_translator(minetest.get_current_modname()) +local S = core.get_translator(core.get_current_modname()) local tt_help = S("Flight Duration:") local description = S("Firework Rocket") local TAU = 2*math.pi -local function explode(self, pos) - -- temp code - vl_fireworks.generic_particle_explosion(pos) +local function explode(self, pos, stars) mcl_mobs.mob_class.safe_boom(self, pos, 1) + if not stars then return end + for _, effect in pairs(stars) do + if effect.fn == "generic" then + vl_fireworks.generic_particle_explosion(pos) + end + -- TODO implement other handlers + end end local firework_entity = { @@ -25,7 +30,7 @@ local firework_entity = { _fire_damage_resistant = true, _save_fields = { - "last_pos", "vl_projectile", "dir", "rot_axis", "force" + "last_pos", "vl_projectile", "dir", "rot_axis", "force", "stars" }, _vector_save_fields = { @@ -57,6 +62,7 @@ local firework_entity = { self._vl_projectile.maximum_time = e.dur self._rot_axis = e.rot_axis self._dir = self.object:get_velocity():normalize() + self._stars = e.stars self._vl_projectile.extra = nil end if not self._dir then return end @@ -76,7 +82,7 @@ local firework_entity = { if lua and lua.name == "mobs_mc:rover" then return false end --if (self.object:get_velocity() + object:get_velocity()).length() < 5 then return end - minetest.log("allow punching") + core.log("allow punching") return true end, @@ -94,13 +100,13 @@ local firework_entity = { -- Preserve entity properties out.properties = self.object:get_properties() - return minetest.serialize(out) + return core.serialize(out) end, on_activate = function(self, staticdata, dtime_s) self.object:set_armor_groups({ immortal = 1 }) self._time_in_air = 1.0 - local data = minetest.deserialize(staticdata) + local data = core.deserialize(staticdata) if not data then return end -- Restore entity properties @@ -128,7 +134,7 @@ local firework_entity = { end, _on_remove = function(self) - explode(self, self.object:get_pos()) + explode(self, self.object:get_pos(), self._stars) end, } @@ -138,6 +144,7 @@ function vl_fireworks.shoot_firework(itemstack, pos, dir) local meta = itemstack:get_meta() local rot_axis = vector.new(1,0,0) rot_axis = rot_axis:rotate_around_axis(vector.new(0,1,0), math.random()*TAU) + local stars = meta:get("vl_fireworks:stars") or core.serialize({}) vl_projectile.create("vl_fireworks:rocket", { pos = pos, dir = dir or vector.new(0,1,0), @@ -145,7 +152,8 @@ function vl_fireworks.shoot_firework(itemstack, pos, dir) extra = { dur = meta:get_float("vl_fireworks:duration"), force = meta:get_float("vl_fireworks:force"), - rot_axis = rot_axis + rot_axis = rot_axis, + stars = core.deserialize(stars) } }) end @@ -158,10 +166,10 @@ local firework_def = { local elytra = mcl_playerplus.elytra[user] if elytra.active and elytra.rocketing <= 0 then elytra.rocketing = meta:get_float("vl_fireworks:duration") - if not minetest.is_creative_enabled(user:get_player_name()) then + if not core.is_creative_enabled(user:get_player_name()) then itemstack:take_item() end - minetest.sound_play("vl_fireworks_rocket", {pos = user:get_pos()}) + core.sound_play("vl_fireworks_rocket", {pos = user:get_pos()}) end return itemstack end, @@ -173,10 +181,19 @@ local firework_def = { vl_fireworks.shoot_firework(dropitem, pos, dropdir) end, _vl_fireworks_std_durs_forces = { {2.2, 10}, {4.5, 20}, {6, 30} }, - _vl_fireworks_tt = function(duration) - return S("Duration:") .. " " .. duration + _vl_fireworks_tt = function(duration, stars) + local retval = S("Duration:") .. " " .. duration + + for _, effect in pairs(stars) do + retval = retval .. "\n\n" + if effect.fn == "generic" then + retval = retval .. S("Generic Firework Star") + end + end + + return retval end, } vl_fireworks.firework_def = table.copy(firework_def) -minetest.register_craftitem("vl_fireworks:rocket", firework_def) +core.register_craftitem("vl_fireworks:rocket", firework_def) diff --git a/mods/ITEMS/vl_fireworks/star.lua b/mods/ITEMS/vl_fireworks/star.lua index e3e7585af..4e76fe598 100644 --- a/mods/ITEMS/vl_fireworks/star.lua +++ b/mods/ITEMS/vl_fireworks/star.lua @@ -1 +1,13 @@ local S = minetest.get_translator(minetest.get_current_modname()) + +minetest.register_craftitem("vl_fireworks:firework_star", { + description = S("Firework Star"), + _doc_items_longdesc = S("A firework star is the key component of a firework rocket which is responsible for the visible explosion."), + wield_image = "vl_fireworks_star.png", + inventory_image = "vl_fireworks_star.png", + groups = { craftitem = 1 }, + stack_max = 64, +}) + +-- TODO tt snippets +-- TODO image handlers diff --git a/textures/vl_fireworks_star.png b/textures/vl_fireworks_star.png new file mode 100644 index 0000000000000000000000000000000000000000..cb4b03d851a5006d9d6e401de7c79d97dd12f80a GIT binary patch literal 241 zcmViO+#`f}z{~#KK zL7HK-v6k|GoGyV$fHZ?_#bpRyufP<-G{b0^H$X0slN80&jqd!uzCJL9xd0RvAk8?v z0TTe(1kwP~4D$wh7=T=W(*R_}*a8sd61>p|QUKG0>~|22)pl&I(AL&Q@iR;_QPBv) rFbz2UjSG;HlnLe|LV19q91Oz%?hr+a2qV!|00000NkvXXu0mjfC`x4) literal 0 HcmV?d00001