Predefined firework explosion size

This commit is contained in:
the-real-herowl 2024-12-27 04:52:43 +01:00 committed by the-real-herowl
parent c1badfd2e5
commit 1449466365
4 changed files with 64 additions and 6 deletions

@ -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)

@ -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()

@ -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

@ -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