1
0
Fork 0

Add smoke particles at torches

This commit is contained in:
Wuzzy 2020-08-19 19:14:37 +02:00
parent 731f42ac88
commit 8a39474793
5 changed files with 68 additions and 17 deletions

View File

@ -1,12 +1,15 @@
local particle_nodes = {}
mcl_particles = {}
-- Table of particlespawner IDs on a per-node hash basis
-- Keys: node position hashes
-- Values: Tables of particlespawner IDs (each node pos can have an arbitrary number of particlespawners)
local particle_nodes = {}
-- Node particles can be disabled via setting
local node_particles_allowed = minetest.settings:get_bool("mcl_node_particles", true)
-- Add a particlespawner that is assigned to a given node position.
-- * pos: Node positon. MUST use rounded values!
-- * pos: Node positon. MUST use integer values!
-- * particlespawner_definition: definition for minetest.add_particlespawner
-- NOTE: All particlespawners are automatically removed on shutdown.
-- Returns particlespawner ID on succcess and nil on failure
@ -22,22 +25,28 @@ function mcl_particles.add_node_particlespawner(pos, particlespawner_definition)
if id == -1 then
return
end
particle_nodes[poshash] = id
if not particle_nodes[poshash] then
particle_nodes[poshash] = {}
end
table.insert(particle_nodes[poshash], id)
return id
end
-- Deleted a particlespawner that is assigned to a node position, if one exists.
-- Otherwise, this does nothing.
-- pos: Node positon. MUST use rounded values!
-- Returns true if particlespawner could be removed and false if none existed
function mcl_particles.delete_node_particlespawner(pos)
-- Deletes all particlespawners that are assigned to a node position.
-- If no particlespawners exist for this position, nothing happens.
-- pos: Node positon. MUST use integer values!
-- Returns true if particlespawner could be removed and false if not
function mcl_particles.delete_node_particlespawners(pos)
if not node_particles_allowed then
return false
end
local poshash = minetest.hash_node_position(pos)
local id = particle_nodes[poshash]
if id then
minetest.delete_particlespawner(id)
local ids = particle_nodes[poshash]
if ids then
for i=1, #ids do
minetest.delete_particlespawner(ids[i])
end
particle_nodes[poshash] = nil
return true
end
return false

Binary file not shown.

Before

Width:  |  Height:  |  Size: 945 B

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

View File

@ -387,7 +387,7 @@ if minetest.get_modpath("screwdriver") then
on_rotate = screwdriver.rotate_simple
after_rotate_active = function(pos)
local node = minetest.get_node(pos)
mcl_particles.delete_node_particlespawner(pos)
mcl_particles.delete_node_particlespawners(pos)
spawn_flames(pos, node.param2)
end
end
@ -499,7 +499,7 @@ minetest.register_node("mcl_furnaces:furnace_active", {
spawn_flames(pos, node.param2)
end,
on_destruct = function(pos)
mcl_particles.delete_node_particlespawner(pos)
mcl_particles.delete_node_particlespawners(pos)
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,

View File

@ -2,7 +2,8 @@ local S = minetest.get_translator("mcl_torches")
local LIGHT_TORCH = minetest.LIGHT_MAX
local spawn_flames_floor = function(pos)
return mcl_particles.add_node_particlespawner(pos, {
-- Flames
mcl_particles.add_node_particlespawner(pos, {
amount = 8,
time = 0,
minpos = vector.add(pos, { x = -0.1, y = 0.05, z = -0.1 }),
@ -16,6 +17,26 @@ local spawn_flames_floor = function(pos)
texture = "mcl_particles_flame.png",
glow = LIGHT_TORCH,
})
-- Smoke
mcl_particles.add_node_particlespawner(pos, {
amount = 0.5,
time = 0,
minpos = vector.add(pos, { x = -1/16, y = 0.04, z = -1/16 }),
maxpos = vector.add(pos, { x = -1/16, y = 0.06, z = -1/16 }),
minvel = { x = 0, y = 0.5, z = 0 },
maxvel = { x = 0, y = 0.6, z = 0 },
minexptime = 2.0,
maxexptime = 2.0,
minsize = 1.5,
maxsize = 1.5,
texture = "mcl_particles_smoke_anim.png",
animation = {
type = "vertical_frames",
aspect_w = 8,
aspect_h = 8,
length = 2.05,
},
})
end
local spawn_flames_wall = function(pos, param2)
@ -36,7 +57,8 @@ local spawn_flames_wall = function(pos, param2)
else
return
end
return mcl_particles.add_node_particlespawner(pos, {
-- Flames
mcl_particles.add_node_particlespawner(pos, {
amount = 8,
time = 0,
minpos = vector.add(pos, minrelpos),
@ -50,10 +72,30 @@ local spawn_flames_wall = function(pos, param2)
texture = "mcl_particles_flame.png",
glow = LIGHT_TORCH,
})
-- Smoke
mcl_particles.add_node_particlespawner(pos, {
amount = 0.5,
time = 0,
minpos = vector.add(pos, minrelpos),
maxpos = vector.add(pos, maxrelpos),
minvel = { x = 0, y = 0.5, z = 0 },
maxvel = { x = 0, y = 0.6, z = 0 },
minexptime = 2.0,
maxexptime = 2.0,
minsize = 1.5,
maxsize = 1.5,
texture = "mcl_particles_smoke_anim.png",
animation = {
type = "vertical_frames",
aspect_w = 8,
aspect_h = 8,
length = 2.05,
},
})
end
local remove_flames = function(pos)
mcl_particles.delete_node_particlespawner(pos)
mcl_particles.delete_node_particlespawners(pos)
end
--