Fireworks are now craftable

This commit is contained in:
the-real-herowl 2024-12-26 04:24:43 +01:00 committed by the-real-herowl
parent e69bd1412e
commit a65684e875
2 changed files with 32 additions and 18 deletions

@ -1,17 +1,28 @@
local function register_firework_crafts()
local recipe = {"mcl_core:paper"}
for i=1, 3 do
table.insert(recipe, "mcl_mobitems:gunpowder")
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",
output = "vl_fireworks:rocket 3", output = "vl_fireworks:rocket 3",
recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder"}, recipe = recipe,
}) })
end
end
register_firework_crafts()
minetest.register_craft({ local function craft_firework(itemstack, player, old_grid)
type = "shapeless", if itemstack:get_name() ~= "vl_fireworks:rocket" then return end
output = "vl_fireworks:rocket 3", local gp = 0
recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder"}, for _, item in pairs(old_grid) do
}) if item:get_name() == "mcl_mobitems:gunpowder" then gp = gp + 1 end
end
minetest.register_craft({ local tbl = vl_fireworks.firework_def._vl_fireworks_std_durs_forces[gp]
type = "shapeless", local meta = itemstack:get_meta()
output = "vl_fireworks:rocket 3", meta:set_float("vl_fireworks:duration", tbl[1])
recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder"}, meta:set_int("vl_fireworks:force", tbl[2])
}) tt.reload_itemstack_description(itemstack)
return itemstack
end
core.register_craft_predict(craft_firework)
core.register_on_craft(craft_firework)

@ -136,7 +136,7 @@ function vl_fireworks.shoot_firework(itemstack, pos)
}) })
end end
minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata local firework_def = {
description = description, description = description,
inventory_image = "vl_fireworks_rocket.png", inventory_image = "vl_fireworks_rocket.png",
stack_max = 64, stack_max = 64,
@ -162,4 +162,7 @@ minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata
_vl_fireworks_tt = function(duration) _vl_fireworks_tt = function(duration)
return S("Duration:") .. " " .. duration return S("Duration:") .. " " .. duration
end, end,
}) }
vl_fireworks.firework_def = table.copy(firework_def)
minetest.register_craftitem("vl_fireworks:rocket", firework_def)