From 1449466365659f134c495306954b4c7179f963e4 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Fri, 27 Dec 2024 04:52:43 +0100 Subject: [PATCH] Predefined firework explosion size --- mods/HELP/mcl_tt/snippets_mcl.lua | 16 ++++++++++++++ mods/ITEMS/vl_fireworks/crafting.lua | 31 ++++++++++++++++++++++++++++ mods/ITEMS/vl_fireworks/rockets.lua | 9 ++++---- mods/ITEMS/vl_fireworks/star.lua | 14 ++++++++++++- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/mods/HELP/mcl_tt/snippets_mcl.lua b/mods/HELP/mcl_tt/snippets_mcl.lua index 76665f897..bd50c095a 100644 --- a/mods/HELP/mcl_tt/snippets_mcl.lua +++ b/mods/HELP/mcl_tt/snippets_mcl.lua @@ -202,3 +202,19 @@ tt.register_snippet(function(itemstring, _, itemstack) return s:trim() end) +tt.register_snippet(function(itemstring, _, itemstack) + if not itemstack then return end + local def = itemstack:get_definition() + if not def then return end + + if not def._vl_fireworks_star then return end + + local s = "" + local meta = itemstack:get_meta() + local effect = meta:get("vl_fireworks:star_effect") or core.serialize({fn="generic"}) + if effect then + s = vl_fireworks.star_tt(core.deserialize(effect)) + end + + return s +end) diff --git a/mods/ITEMS/vl_fireworks/crafting.lua b/mods/ITEMS/vl_fireworks/crafting.lua index b18ef6066..684788543 100644 --- a/mods/ITEMS/vl_fireworks/crafting.lua +++ b/mods/ITEMS/vl_fireworks/crafting.lua @@ -4,6 +4,37 @@ core.register_craft({ -- temporary output = "vl_fireworks:firework_star", recipe = {"mcl_mobitems:gunpowder", "mcl_core:clay_lump"} }) +core.register_craft({ -- temporary + type = "shapeless", + output = "vl_fireworks:firework_star", + recipe = {"mcl_mobitems:gunpowder", "mcl_core:clay_lump", "mcl_fire:fire_charge"} +}) +core.register_craft({ -- temporary + type = "shapeless", + output = "vl_fireworks:firework_star", + recipe = {"mcl_mobitems:gunpowder", "mcl_core:clay_lump", "mcl_end:crystal"} +}) + +local function craft_star(itemstack, player, old_grid) + if itemstack:get_name() ~= "vl_fireworks:firework_star" then return end + local size = 1 + + -- analyze the recipe used + for _, item in pairs(old_grid) do + if item:get_name() == "mcl_fire:fire_charge" then size = 2 end + if item:get_name() == "mcl_end:crystal" then size = 3 end + end + + local effect = { + fn = "generic", + size = size + } + itemstack:get_meta():set_string("vl_fireworks:star_effect", core.serialize(effect)) + tt.reload_itemstack_description(itemstack) + return itemstack +end +core.register_craft_predict(craft_star) +core.register_on_craft(craft_star) -- Firework Rocket local function register_firework_crafts() diff --git a/mods/ITEMS/vl_fireworks/rockets.lua b/mods/ITEMS/vl_fireworks/rockets.lua index 5dfdcbaf6..d78c74f8d 100644 --- a/mods/ITEMS/vl_fireworks/rockets.lua +++ b/mods/ITEMS/vl_fireworks/rockets.lua @@ -9,8 +9,9 @@ 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 type(effect) == "string" then effect = core.deserialize(effect) end if effect.fn == "generic" then - vl_fireworks.generic_particle_explosion(pos) + vl_fireworks.generic_particle_explosion(pos, effect.size or 1) end -- TODO implement other handlers end @@ -185,10 +186,8 @@ local firework_def = { 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 + if type(effect) == "string" then effect = core.deserialize(effect) end + retval = retval .. "\n\n" .. vl_fireworks.star_tt(effect) end return retval diff --git a/mods/ITEMS/vl_fireworks/star.lua b/mods/ITEMS/vl_fireworks/star.lua index 4e76fe598..7d86d6948 100644 --- a/mods/ITEMS/vl_fireworks/star.lua +++ b/mods/ITEMS/vl_fireworks/star.lua @@ -7,7 +7,19 @@ minetest.register_craftitem("vl_fireworks:firework_star", { inventory_image = "vl_fireworks_star.png", groups = { craftitem = 1 }, stack_max = 64, + + _vl_fireworks_star = true }) --- TODO tt snippets +function vl_fireworks.star_tt(effect) + local s = "" + if effect.fn == "generic" then + s = S("Generic Firework Star") + end + if effect.size then + s = s .. "\nSize: " .. effect.size + end + return s:trim() +end + -- TODO image handlers