Update helptext of obsidian
[MineClone/MineClone2.git] / mods / CORE / mcl_particles / init.lua
blob757c0452f118fd676c1c3047bb0999b649c842a1
1 mcl_particles = {}
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"
11 local levels = {
12 high = 3,
13 medium = 2,
14 low = 1,
15 none = 0,
18 allowed_level = levels[node_particles_allowed]
19 if not allowed_level then
20 allowed_level = levels["none"]
21 end
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
33 return
34 end
35 local poshash = minetest.hash_node_position(pos)
36 if not poshash then
37 return
38 end
39 local id = minetest.add_particlespawner(particlespawner_definition)
40 if id == -1 then
41 return
42 end
43 if not particle_nodes[poshash] then
44 particle_nodes[poshash] = {}
45 end
46 table.insert(particle_nodes[poshash], id)
47 return id
48 end
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
56 return false
57 end
58 local poshash = minetest.hash_node_position(pos)
59 local ids = particle_nodes[poshash]
60 if ids then
61 for i=1, #ids do
62 minetest.delete_particlespawner(ids[i])
63 end
64 particle_nodes[poshash] = nil
65 return true
66 end
67 return false
68 end