3 -- Table of particlespawner IDs on a per-node hash basis
4 -- Keys: node position hashes
5 -- Values: Tables of particlespawner IDs (each node pos can have an arbitrary number of particlespawners)
6 local particle_nodes
= {}
8 -- Node particles can be disabled via setting
9 local node_particles_allowed
= minetest
.settings
:get("mcl_node_particles") or "none"
18 allowed_level
= levels
[node_particles_allowed
]
19 if not allowed_level
then
20 allowed_level
= levels
["none"]
24 -- Add a particlespawner that is assigned to a given node position.
25 -- * pos: Node positon. MUST use integer values!
26 -- * particlespawner_definition: definition for minetest.add_particlespawner
27 -- * level: detail level of particles. "high", "medium", "low" or "none". High detail levels are for
28 -- CPU-demanding particles, like smoke of fire (which occurs frequently)
29 -- NOTE: All particlespawners are automatically removed on shutdown.
30 -- Returns particlespawner ID on succcess and nil on failure
31 function mcl_particles
.add_node_particlespawner(pos
, particlespawner_definition
, level
)
32 if allowed_level
== 0 or levels
[level
] > allowed_level
then
35 local poshash
= minetest
.hash_node_position(pos
)
39 local id
= minetest
.add_particlespawner(particlespawner_definition
)
43 if not particle_nodes
[poshash
] then
44 particle_nodes
[poshash
] = {}
46 table.insert(particle_nodes
[poshash
], id
)
50 -- Deletes all particlespawners that are assigned to a node position.
51 -- If no particlespawners exist for this position, nothing happens.
52 -- pos: Node positon. MUST use integer values!
53 -- Returns true if particlespawner could be removed and false if not
54 function mcl_particles
.delete_node_particlespawners(pos
)
55 if allowed_level
== 0 then
58 local poshash
= minetest
.hash_node_position(pos
)
59 local ids
= particle_nodes
[poshash
]
62 minetest
.delete_particlespawner(ids
[i
])
64 particle_nodes
[poshash
] = nil