From a65684e8758e80396ca175e841b5f1ab361204da Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 26 Dec 2024 04:24:43 +0100 Subject: [PATCH] Fireworks are now craftable --- mods/ITEMS/vl_fireworks/crafting.lua | 43 +++++++++++++++++----------- mods/ITEMS/vl_fireworks/register.lua | 7 +++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/vl_fireworks/crafting.lua b/mods/ITEMS/vl_fireworks/crafting.lua index f8b83b17e..60b371a02 100644 --- a/mods/ITEMS/vl_fireworks/crafting.lua +++ b/mods/ITEMS/vl_fireworks/crafting.lua @@ -1,17 +1,28 @@ -minetest.register_craft({ - type = "shapeless", - output = "vl_fireworks:rocket 3", - recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder"}, -}) +local function register_firework_crafts() + local recipe = {"mcl_core:paper"} + for i=1, 3 do + table.insert(recipe, "mcl_mobitems:gunpowder") + minetest.register_craft({ + type = "shapeless", + output = "vl_fireworks:rocket 3", + recipe = recipe, + }) + end +end +register_firework_crafts() -minetest.register_craft({ - type = "shapeless", - output = "vl_fireworks:rocket 3", - recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder"}, -}) - -minetest.register_craft({ - type = "shapeless", - output = "vl_fireworks:rocket 3", - recipe = {"mcl_core:paper", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder", "mcl_mobitems:gunpowder"}, -}) +local function craft_firework(itemstack, player, old_grid) + if itemstack:get_name() ~= "vl_fireworks:rocket" then return end + local gp = 0 + for _, item in pairs(old_grid) do + if item:get_name() == "mcl_mobitems:gunpowder" then gp = gp + 1 end + end + 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]) + tt.reload_itemstack_description(itemstack) + return itemstack +end +core.register_craft_predict(craft_firework) +core.register_on_craft(craft_firework) diff --git a/mods/ITEMS/vl_fireworks/register.lua b/mods/ITEMS/vl_fireworks/register.lua index 21a378744..b19b6b597 100644 --- a/mods/ITEMS/vl_fireworks/register.lua +++ b/mods/ITEMS/vl_fireworks/register.lua @@ -136,7 +136,7 @@ function vl_fireworks.shoot_firework(itemstack, pos) }) end -minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata +local firework_def = { description = description, inventory_image = "vl_fireworks_rocket.png", stack_max = 64, @@ -162,4 +162,7 @@ minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata _vl_fireworks_tt = function(duration) return S("Duration:") .. " " .. duration end, -}) +} +vl_fireworks.firework_def = table.copy(firework_def) + +minetest.register_craftitem("vl_fireworks:rocket", firework_def)