mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2025-01-01 14:17:29 +01:00
Added firework stars
- empty fireworks now have a simple boom - fireworks with generic stars have a colorful boom
This commit is contained in:
parent
36b8689bf4
commit
d4ca99f09e
@ -196,7 +196,9 @@ tt.register_snippet(function(itemstring, _, itemstack)
|
||||
|
||||
local s = ""
|
||||
local meta = itemstack:get_meta()
|
||||
s = s .. def._vl_fireworks_tt(meta:get_float("vl_fireworks:duration"))
|
||||
local stars = meta:get("vl_fireworks:stars") or core.serialize({})
|
||||
s = s .. def._vl_fireworks_tt(meta:get_float("vl_fireworks:duration"),
|
||||
core.deserialize(stars))
|
||||
|
||||
return s:trim()
|
||||
end)
|
||||
|
@ -116,6 +116,7 @@ minetest.register_on_mods_loaded(function()
|
||||
nonmisc = true
|
||||
end
|
||||
if def._vl_fireworks_std_durs_forces then
|
||||
local generic = core.serialize({{fn="generic"}})
|
||||
for i, tbl in ipairs(def._vl_fireworks_std_durs_forces) do
|
||||
local stack = ItemStack(name)
|
||||
local meta = stack:get_meta()
|
||||
@ -123,6 +124,9 @@ minetest.register_on_mods_loaded(function()
|
||||
meta:set_int("vl_fireworks:force", tbl[2])
|
||||
table.insert(inventory_lists["misc"], stack:to_string())
|
||||
table.insert(inventory_lists["all"], stack:to_string())
|
||||
meta:set_string("vl_fireworks:stars", generic)
|
||||
table.insert(inventory_lists["misc"], stack:to_string())
|
||||
table.insert(inventory_lists["all"], stack:to_string())
|
||||
end
|
||||
nonmisc = true
|
||||
all_handled = true
|
||||
|
@ -313,8 +313,7 @@ minetest.register_craftitem("mcl_mobitems:nether_star", {
|
||||
_doc_items_longdesc = S("A nether star is dropped when the Wither dies. Place it in an item frame to show the world how hardcore you are! Or just as decoration."),
|
||||
wield_image = "mcl_mobitems_nether_star.png",
|
||||
inventory_image = "mcl_mobitems_nether_star.png",
|
||||
-- TODO: Reveal item when it's useful
|
||||
groups = { craftitem = 1, not_in_creative_inventory = 1 },
|
||||
groups = { craftitem = 1 },
|
||||
stack_max = 64,
|
||||
})
|
||||
|
||||
|
@ -1,11 +1,27 @@
|
||||
-- Firework Star
|
||||
core.register_craft({ -- temporary
|
||||
type = "shapeless",
|
||||
output = "vl_fireworks:firework_star",
|
||||
recipe = {"mcl_mobitems:gunpowder", "mcl_core:clay_lump"}
|
||||
})
|
||||
|
||||
-- Firework Rocket
|
||||
local function register_firework_crafts()
|
||||
local recipe = {"mcl_core:paper"}
|
||||
local r1 = {"mcl_core:paper"}
|
||||
local r2 = table.copy(r1)
|
||||
table.insert(r2, "vl_fireworks:firework_star") -- TODO replace with a loop or such to allow more stars
|
||||
for i=1, 3 do
|
||||
table.insert(recipe, "mcl_mobitems:gunpowder")
|
||||
minetest.register_craft({
|
||||
table.insert(r1, "mcl_mobitems:gunpowder")
|
||||
table.insert(r2, "mcl_mobitems:gunpowder")
|
||||
core.register_craft({
|
||||
type = "shapeless",
|
||||
output = "vl_fireworks:rocket 3",
|
||||
recipe = recipe,
|
||||
recipe = r1,
|
||||
})
|
||||
core.register_craft({
|
||||
type = "shapeless",
|
||||
output = "vl_fireworks:rocket 3",
|
||||
recipe = r2,
|
||||
})
|
||||
end
|
||||
end
|
||||
@ -13,14 +29,28 @@ register_firework_crafts()
|
||||
|
||||
local function craft_firework(itemstack, player, old_grid)
|
||||
if itemstack:get_name() ~= "vl_fireworks:rocket" then return end
|
||||
local gp = 0
|
||||
local gp = 0 -- gunpowder
|
||||
local stars = {}
|
||||
|
||||
-- analyze the recipe used
|
||||
for _, item in pairs(old_grid) do
|
||||
if item:get_name() == "mcl_mobitems:gunpowder" then gp = gp + 1 end
|
||||
if item:get_name() == "vl_fireworks:firework_star" then
|
||||
local effect = item:get_meta():get("vl_fireworks:star_effect")
|
||||
or core.serialize({fn="generic"})
|
||||
table.insert(stars, effect)
|
||||
end
|
||||
end
|
||||
|
||||
-- determine duration and force from the amount of gunpowder used
|
||||
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])
|
||||
|
||||
-- write star effects into metadata
|
||||
meta:set_string("vl_fireworks:stars", core.serialize(stars))
|
||||
|
||||
tt.reload_itemstack_description(itemstack)
|
||||
return itemstack
|
||||
end
|
||||
|
@ -1,14 +1,19 @@
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
local S = core.get_translator(core.get_current_modname())
|
||||
|
||||
local tt_help = S("Flight Duration:")
|
||||
local description = S("Firework Rocket")
|
||||
|
||||
local TAU = 2*math.pi
|
||||
|
||||
local function explode(self, pos)
|
||||
-- temp code
|
||||
vl_fireworks.generic_particle_explosion(pos)
|
||||
local function explode(self, pos, stars)
|
||||
mcl_mobs.mob_class.safe_boom(self, pos, 1)
|
||||
if not stars then return end
|
||||
for _, effect in pairs(stars) do
|
||||
if effect.fn == "generic" then
|
||||
vl_fireworks.generic_particle_explosion(pos)
|
||||
end
|
||||
-- TODO implement other handlers
|
||||
end
|
||||
end
|
||||
|
||||
local firework_entity = {
|
||||
@ -25,7 +30,7 @@ local firework_entity = {
|
||||
_fire_damage_resistant = true,
|
||||
|
||||
_save_fields = {
|
||||
"last_pos", "vl_projectile", "dir", "rot_axis", "force"
|
||||
"last_pos", "vl_projectile", "dir", "rot_axis", "force", "stars"
|
||||
},
|
||||
|
||||
_vector_save_fields = {
|
||||
@ -57,6 +62,7 @@ local firework_entity = {
|
||||
self._vl_projectile.maximum_time = e.dur
|
||||
self._rot_axis = e.rot_axis
|
||||
self._dir = self.object:get_velocity():normalize()
|
||||
self._stars = e.stars
|
||||
self._vl_projectile.extra = nil
|
||||
end
|
||||
if not self._dir then return end
|
||||
@ -76,7 +82,7 @@ local firework_entity = {
|
||||
if lua and lua.name == "mobs_mc:rover" then return false end
|
||||
--if (self.object:get_velocity() + object:get_velocity()).length() < 5 then return end
|
||||
|
||||
minetest.log("allow punching")
|
||||
core.log("allow punching")
|
||||
|
||||
return true
|
||||
end,
|
||||
@ -94,13 +100,13 @@ local firework_entity = {
|
||||
-- Preserve entity properties
|
||||
out.properties = self.object:get_properties()
|
||||
|
||||
return minetest.serialize(out)
|
||||
return core.serialize(out)
|
||||
end,
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
self.object:set_armor_groups({ immortal = 1 })
|
||||
|
||||
self._time_in_air = 1.0
|
||||
local data = minetest.deserialize(staticdata)
|
||||
local data = core.deserialize(staticdata)
|
||||
if not data then return end
|
||||
|
||||
-- Restore entity properties
|
||||
@ -128,7 +134,7 @@ local firework_entity = {
|
||||
end,
|
||||
|
||||
_on_remove = function(self)
|
||||
explode(self, self.object:get_pos())
|
||||
explode(self, self.object:get_pos(), self._stars)
|
||||
end,
|
||||
}
|
||||
|
||||
@ -138,6 +144,7 @@ function vl_fireworks.shoot_firework(itemstack, pos, dir)
|
||||
local meta = itemstack:get_meta()
|
||||
local rot_axis = vector.new(1,0,0)
|
||||
rot_axis = rot_axis:rotate_around_axis(vector.new(0,1,0), math.random()*TAU)
|
||||
local stars = meta:get("vl_fireworks:stars") or core.serialize({})
|
||||
vl_projectile.create("vl_fireworks:rocket", {
|
||||
pos = pos,
|
||||
dir = dir or vector.new(0,1,0),
|
||||
@ -145,7 +152,8 @@ function vl_fireworks.shoot_firework(itemstack, pos, dir)
|
||||
extra = {
|
||||
dur = meta:get_float("vl_fireworks:duration"),
|
||||
force = meta:get_float("vl_fireworks:force"),
|
||||
rot_axis = rot_axis
|
||||
rot_axis = rot_axis,
|
||||
stars = core.deserialize(stars)
|
||||
}
|
||||
})
|
||||
end
|
||||
@ -158,10 +166,10 @@ local firework_def = {
|
||||
local elytra = mcl_playerplus.elytra[user]
|
||||
if elytra.active and elytra.rocketing <= 0 then
|
||||
elytra.rocketing = meta:get_float("vl_fireworks:duration")
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
if not core.is_creative_enabled(user:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
minetest.sound_play("vl_fireworks_rocket", {pos = user:get_pos()})
|
||||
core.sound_play("vl_fireworks_rocket", {pos = user:get_pos()})
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
@ -173,10 +181,19 @@ local firework_def = {
|
||||
vl_fireworks.shoot_firework(dropitem, pos, dropdir)
|
||||
end,
|
||||
_vl_fireworks_std_durs_forces = { {2.2, 10}, {4.5, 20}, {6, 30} },
|
||||
_vl_fireworks_tt = function(duration)
|
||||
return S("Duration:") .. " " .. duration
|
||||
_vl_fireworks_tt = function(duration, stars)
|
||||
local retval = S("Duration:") .. " " .. duration
|
||||
|
||||
for _, effect in pairs(stars) do
|
||||
retval = retval .. "\n\n"
|
||||
if effect.fn == "generic" then
|
||||
retval = retval .. S("Generic Firework Star")
|
||||
end
|
||||
end
|
||||
|
||||
return retval
|
||||
end,
|
||||
}
|
||||
vl_fireworks.firework_def = table.copy(firework_def)
|
||||
|
||||
minetest.register_craftitem("vl_fireworks:rocket", firework_def)
|
||||
core.register_craftitem("vl_fireworks:rocket", firework_def)
|
||||
|
@ -1 +1,13 @@
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
minetest.register_craftitem("vl_fireworks:firework_star", {
|
||||
description = S("Firework Star"),
|
||||
_doc_items_longdesc = S("A firework star is the key component of a firework rocket which is responsible for the visible explosion."),
|
||||
wield_image = "vl_fireworks_star.png",
|
||||
inventory_image = "vl_fireworks_star.png",
|
||||
groups = { craftitem = 1 },
|
||||
stack_max = 64,
|
||||
})
|
||||
|
||||
-- TODO tt snippets
|
||||
-- TODO image handlers
|
||||
|
BIN
textures/vl_fireworks_star.png
Normal file
BIN
textures/vl_fireworks_star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 241 B |
Loading…
Reference in New Issue
Block a user