Add metadata-based firework duration and force

This commit is contained in:
the-real-herowl 2024-12-26 02:58:53 +01:00 committed by the-real-herowl
parent a9187ab9de
commit 8b0534437a
3 changed files with 46 additions and 13 deletions

View file

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

View file

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

View file

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