From 8b0534437aa57be0f66a22a908eb39aa01660de8 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 26 Dec 2024 02:58:53 +0100 Subject: [PATCH] Add metadata-based firework duration and force --- mods/HELP/mcl_tt/snippets_mcl.lua | 16 ++++++++++++++ mods/HUD/mcl_inventory/creative.lua | 10 +++++++++ mods/ITEMS/vl_fireworks/register.lua | 33 +++++++++++++++++----------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/mods/HELP/mcl_tt/snippets_mcl.lua b/mods/HELP/mcl_tt/snippets_mcl.lua index a964b96a3..384d590c0 100644 --- a/mods/HELP/mcl_tt/snippets_mcl.lua +++ b/mods/HELP/mcl_tt/snippets_mcl.lua @@ -184,3 +184,19 @@ tt.register_snippet(function(itemstring, _, itemstack) end return s:trim() end) + + +-- Fireworks info +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_tt then return end + + local s = "" + local meta = itemstack:get_meta() + s = s .. def._vl_fireworks_tt(meta:get_float("vl_fireworks:duration")) + + return s:trim() +end) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 3adede128..7504b080b 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -113,6 +113,16 @@ minetest.register_on_mods_loaded(function() table.insert(inventory_lists["matr"], name) nonmisc = true end + if def._vl_fireworks_std_durs_forces then + for i, tbl in ipairs(def._vl_fireworks_std_durs_forces) do + local stack = ItemStack(name) + local meta = stack:get_meta() + meta:set_float("vl_fireworks:duration", tbl[1]) + meta:set_int("vl_fireworks:force", tbl[2]) + table.insert(inventory_lists["misc"], stack:to_string()) + end + nonmisc = true + end -- Misc. category is for everything which is not in any other category if not nonmisc then table.insert(inventory_lists["misc"], name) diff --git a/mods/ITEMS/vl_fireworks/register.lua b/mods/ITEMS/vl_fireworks/register.lua index 4be469f5c..64f4e2114 100644 --- a/mods/ITEMS/vl_fireworks/register.lua +++ b/mods/ITEMS/vl_fireworks/register.lua @@ -23,7 +23,7 @@ local firework_entity = { _fire_damage_resistant = true, _save_fields = { - "last_pos", "startpos", "damage", "time_in_air", "vl_projectile", "arrow_item"--[[???]], "itemstring" + "last_pos", "startpos", "time_in_air", "vl_projectile", "arrow_item"--[[???]], "itemstring", "duration" }, _damage=1, -- Damage on impact @@ -46,6 +46,10 @@ local firework_entity = { function(self, dtime) self.object:add_velocity(vector.new(0, 5*dtime, 0)) -- TODO var. accel. TODO max speed? + if self._vl_projectile.extra then + self._vl_projectile.maximum_time = self._vl_projectile.extra + self._vl_projectile.extra = nil + end end, vl_projectile.collides_with_solids, @@ -107,16 +111,14 @@ local firework_entity = { vl_projectile.register("vl_fireworks:rocket", firework_entity) --- local function register_rocket(n, duration, force) minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata description = description, --- _tt_help = tt_help .. " " .. duration, inventory_image = "vl_fireworks_rocket.png", stack_max = 64, on_use = function(itemstack, user, pointed_thing) local elytra = mcl_playerplus.elytra[user] if elytra.active and elytra.rocketing <= 0 then - elytra.rocketing = 5 -- duration + elytra.rocketing = meta:get_float("vl_fireworks:duration") if not minetest.is_creative_enabled(user:get_player_name()) then itemstack:take_item() end @@ -126,21 +128,26 @@ minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata end, on_place = function(itemstack, user, pointed_thing) local pos = pointed_thing.above + local meta = itemstack:get_meta() -- pos.y = pos.y + 1 vl_projectile.create("vl_fireworks:rocket", { - pos=pos, - velocity=vector.new(0,1,0) + pos = pos, + dir = vector.new(0,1,0), + velocity = 1 + meta:get_int("vl_fireworks:force")/10, + extra = meta:get_float("vl_fireworks:duration") }) end, _on_dispense = function(dropitem, pos, droppos, dropnode, dropdir) + local meta = itemstack:get_meta() vl_projectile.create("vl_fireworks:rocket", { - pos=pos, - velocity=vector.new(0,1,0) + pos = pos, + dir = vector.new(0,1,0), + velocity = 1 + meta:get_int("vl_fireworks:force")/10, + extra = meta:get_float("vl_fireworks:duration") }) end, + _vl_fireworks_std_durs_forces = { {2.2, 10}, {4.5, 20}, {6, 30} }, + _vl_fireworks_tt = function(duration) + return S("Duration:") .. " " .. duration + end, }) --- end - --- register_rocket(1, 2.2, 10) --- register_rocket(2, 4.5, 20) --- register_rocket(3, 6, 30)