mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2025-01-09 16:49:35 +01:00
Add metadata-based firework duration and force
This commit is contained in:
parent
a9187ab9de
commit
8b0534437a
3 changed files with 46 additions and 13 deletions
|
@ -184,3 +184,19 @@ tt.register_snippet(function(itemstring, _, itemstack)
|
||||||
end
|
end
|
||||||
return s:trim()
|
return s:trim()
|
||||||
end)
|
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)
|
||||||
|
|
|
@ -113,6 +113,16 @@ minetest.register_on_mods_loaded(function()
|
||||||
table.insert(inventory_lists["matr"], name)
|
table.insert(inventory_lists["matr"], name)
|
||||||
nonmisc = true
|
nonmisc = true
|
||||||
end
|
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
|
-- Misc. category is for everything which is not in any other category
|
||||||
if not nonmisc then
|
if not nonmisc then
|
||||||
table.insert(inventory_lists["misc"], name)
|
table.insert(inventory_lists["misc"], name)
|
||||||
|
|
|
@ -23,7 +23,7 @@ local firework_entity = {
|
||||||
_fire_damage_resistant = true,
|
_fire_damage_resistant = true,
|
||||||
|
|
||||||
_save_fields = {
|
_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
|
_damage=1, -- Damage on impact
|
||||||
|
@ -46,6 +46,10 @@ local firework_entity = {
|
||||||
|
|
||||||
function(self, dtime)
|
function(self, dtime)
|
||||||
self.object:add_velocity(vector.new(0, 5*dtime, 0)) -- TODO var. accel. TODO max speed?
|
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,
|
end,
|
||||||
|
|
||||||
vl_projectile.collides_with_solids,
|
vl_projectile.collides_with_solids,
|
||||||
|
@ -107,16 +111,14 @@ local firework_entity = {
|
||||||
|
|
||||||
vl_projectile.register("vl_fireworks:rocket", 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
|
minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata
|
||||||
description = description,
|
description = description,
|
||||||
-- _tt_help = tt_help .. " " .. duration,
|
|
||||||
inventory_image = "vl_fireworks_rocket.png",
|
inventory_image = "vl_fireworks_rocket.png",
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local elytra = mcl_playerplus.elytra[user]
|
local elytra = mcl_playerplus.elytra[user]
|
||||||
if elytra.active and elytra.rocketing <= 0 then
|
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
|
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
|
@ -126,21 +128,26 @@ minetest.register_craftitem("vl_fireworks:rocket", { -- TODO use metadata
|
||||||
end,
|
end,
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
local pos = pointed_thing.above
|
local pos = pointed_thing.above
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
-- pos.y = pos.y + 1
|
-- pos.y = pos.y + 1
|
||||||
vl_projectile.create("vl_fireworks:rocket", {
|
vl_projectile.create("vl_fireworks:rocket", {
|
||||||
pos=pos,
|
pos = pos,
|
||||||
velocity=vector.new(0,1,0)
|
dir = vector.new(0,1,0),
|
||||||
|
velocity = 1 + meta:get_int("vl_fireworks:force")/10,
|
||||||
|
extra = meta:get_float("vl_fireworks:duration")
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
_on_dispense = function(dropitem, pos, droppos, dropnode, dropdir)
|
_on_dispense = function(dropitem, pos, droppos, dropnode, dropdir)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
vl_projectile.create("vl_fireworks:rocket", {
|
vl_projectile.create("vl_fireworks:rocket", {
|
||||||
pos=pos,
|
pos = pos,
|
||||||
velocity=vector.new(0,1,0)
|
dir = vector.new(0,1,0),
|
||||||
|
velocity = 1 + meta:get_int("vl_fireworks:force")/10,
|
||||||
|
extra = meta:get_float("vl_fireworks:duration")
|
||||||
})
|
})
|
||||||
end,
|
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)
|
|
||||||
|
|
Loading…
Reference in a new issue