Remove node_particle_spawner code

This is faulty and can not be fixed by design
This commit is contained in:
cora 2024-04-02 20:35:12 +02:00 committed by ryvnf
parent b0aca4d040
commit 7f4ea1dd35
5 changed files with 4 additions and 342 deletions

View File

@ -1,120 +1,15 @@
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 = {}
local warning_text = "invoked. This function has been inactivated in mineclonia and does not do anything. It may be removed in the future."
-- Node particles can be disabled via setting
local node_particles_allowed = minetest.settings:get("mcl_node_particles") or "none"
local levels = {
high = 3,
medium = 2,
low = 1,
none = 0,
}
allowed_level = levels[node_particles_allowed]
if not allowed_level then
allowed_level = levels["none"]
end
-- Add a particlespawner that is assigned to a given node position.
-- * pos: Node positon. MUST use integer values!
-- * particlespawner_definition: definition for minetest.add_particlespawner
-- * level: detail level of particles. "high", "medium", "low" or "none". High detail levels are for
-- CPU-demanding particles, like smoke of fire (which occurs frequently)
-- NOTE: All particlespawners are automatically removed on shutdown.
-- Returns particlespawner ID on succcess and nil on failure
function mcl_particles.add_node_particlespawner(pos, particlespawner_definition, level)
if allowed_level == 0 or levels[level] > allowed_level then
return
end
local poshash = minetest.hash_node_position(pos)
if not poshash then
return
end
local id = minetest.add_particlespawner(particlespawner_definition)
if id == -1 then
return
end
if not particle_nodes[poshash] then
particle_nodes[poshash] = {}
end
table.insert(particle_nodes[poshash], id)
return id
minetest.log("warning", "mcl_particles.add_node_particlespawner "..warning_text)
end
-- 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 allowed_level == 0 then
return false
end
local poshash = minetest.hash_node_position(pos)
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
minetest.log("warning", "mcl_particles.delete_node_particlespawner "..warning_text)
end
-- 3 exptime variants because the animation is not tied to particle expiration time.
-- 3 colorized variants to imitate minecraft's
local smoke_pdef_cached = {}
function mcl_particles.spawn_smoke(pos, name, smoke_pdef_base)
local new_minpos = vector.add(pos, smoke_pdef_base.minrelpos)
local new_maxpos = vector.add(pos, smoke_pdef_base.maxrelpos)
-- populate the cache
if smoke_pdef_cached[name] then
for i, smoke_pdef in ipairs(smoke_pdef_cached[name]) do
smoke_pdef.minpos = new_minpos
smoke_pdef.maxpos = new_maxpos
mcl_particles.add_node_particlespawner(pos, smoke_pdef, "high")
end
-- cache already populated
else
smoke_pdef_cached[name] = {}
local smoke_pdef = table.copy(smoke_pdef_base)
smoke_pdef.amount = smoke_pdef_base.amount / 9
smoke_pdef.time = 0
smoke_pdef.animation = {
type = "vertical_frames",
aspect_w = 8,
aspect_h = 8,
-- length = 3 exptime variants
}
smoke_pdef.collisiondetection = true
smoke_pdef.minpos = new_minpos
smoke_pdef.maxpos = new_maxpos
-- the last frame plays for 1/8 * N seconds, so we can take advantage of it
-- to have varying exptime for each variant.
local exptimes = { 0.175, 0.375, 1.0 }
local colorizes = { "199", "209", "243" } -- round(78%, 82%, 90% of 256) - 1
for _,exptime in ipairs(exptimes) do
for _,colorize in ipairs(colorizes) do
smoke_pdef.maxexptime = exptime * smoke_pdef_base.maxexptime
smoke_pdef.animation.length = exptime + 0.1
-- minexptime must be set such that the last frame is actully rendered,
-- even if its very short. Larger exptime -> larger range
smoke_pdef.minexptime = math.min(exptime, (7.0/8.0 * (exptime + 0.1) + 0.1))
smoke_pdef.texture = "mcl_particles_smoke_anim.png^[colorize:#000000:" ..colorize
mcl_particles.add_node_particlespawner(pos, smoke_pdef, "high")
table.insert(smoke_pdef_cached[name], table.copy(smoke_pdef))
end
end
end
minetest.log("warning", "mcl_particles.add_node_particlespawner "..warning_text)
end

View File

@ -35,25 +35,6 @@ local function has_flammable(pos)
end
end
local smoke_pdef = {
amount = 0.009,
maxexptime = 4.0,
minvel = { x = -0.1, y = 0.3, z = -0.1 },
maxvel = { x = 0.1, y = 1.6, z = 0.1 },
minsize = 4.0,
maxsize = 4.5,
minrelpos = { x = -0.45, y = -0.45, z = -0.45 },
maxrelpos = { x = 0.45, y = 0.45, z = 0.45 },
}
--
-- Items
--
-- Flame nodes
-- Fire settings
-- When enabled, fire destroys other blocks.
local fire_enabled = minetest.settings:get_bool("enable_fire", true)
@ -120,11 +101,6 @@ minetest.register_node("mcl_fire:fire", {
if has_mcl_portals then
mcl_portals.light_nether_portal(pos)
end
mcl_particles.spawn_smoke(pos, "fire", smoke_pdef)
end,
on_destruct = function(pos)
mcl_particles.delete_node_particlespawners(pos)
end,
_mcl_blast_resistance = 0,
})
@ -163,10 +139,6 @@ minetest.register_node("mcl_fire:eternal_fire", {
if has_mcl_portals then --Calling directly minetest.get_modpath consumes 4x more compute time
mcl_portals.light_nether_portal(pos)
end
mcl_particles.spawn_smoke(pos, "fire", smoke_pdef)
end,
on_destruct = function(pos)
mcl_particles.delete_node_particlespawners(pos)
end,
sounds = {},
drop = "",
@ -450,16 +422,6 @@ function mcl_fire.set_fire(pointed_thing, player, allow_on_fire)
minetest.set_node(pointed_thing.above, {name="mcl_fire:fire"})
end
minetest.register_lbm({
label = "Smoke particles from fire",
name = "mcl_fire:smoke",
nodenames = {"group:fire"},
run_at_every_load = true,
action = function(pos, node)
mcl_particles.spawn_smoke(pos, "fire", smoke_pdef)
end,
})
minetest.register_alias("mcl_fire:basic_flame", "mcl_fire:fire")
minetest.register_alias("fire:basic_flame", "mcl_fire:fire")
minetest.register_alias("fire:permanent_flame", "mcl_fire:eternal_fire")

View File

@ -234,40 +234,6 @@ function mcl_furnaces.on_metadata_inventory_put(pos, listname, index, stack, pla
end
end
function mcl_furnaces.spawn_flames(pos, param2)
local minrelpos, maxrelpos
local dir = minetest.facedir_to_dir(param2)
if dir.x > 0 then
minrelpos = { x = -0.6, y = -0.05, z = -0.25 }
maxrelpos = { x = -0.55, y = -0.45, z = 0.25 }
elseif dir.x < 0 then
minrelpos = { x = 0.55, y = -0.05, z = -0.25 }
maxrelpos = { x = 0.6, y = -0.45, z = 0.25 }
elseif dir.z > 0 then
minrelpos = { x = -0.25, y = -0.05, z = -0.6 }
maxrelpos = { x = 0.25, y = -0.45, z = -0.55 }
elseif dir.z < 0 then
minrelpos = { x = -0.25, y = -0.05, z = 0.55 }
maxrelpos = { x = 0.25, y = -0.45, z = 0.6 }
else
return
end
mcl_particles.add_node_particlespawner(pos, {
amount = 4,
time = 0,
minpos = vector.add(pos, minrelpos),
maxpos = vector.add(pos, maxrelpos),
minvel = { x = -0.01, y = 0, z = -0.01 },
maxvel = { x = 0.01, y = 0.1, z = 0.01 },
minexptime = 0.3,
maxexptime = 0.6,
minsize = 0.4,
maxsize = 0.8,
texture = "mcl_particles_flame.png",
glow = LIGHT_ACTIVE_FURNACE,
}, "low")
end
function mcl_furnaces.swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
@ -275,11 +241,6 @@ function mcl_furnaces.swap_node(pos, name)
end
node.name = name
minetest.swap_node(pos, node)
if name == "mcl_furnaces:furnace_active" then
mcl_furnaces.spawn_flames(pos, node.param2)
else
mcl_particles.delete_node_particlespawners(pos)
end
end
function mcl_furnaces.furnace_reset_delta_time(pos)
@ -497,15 +458,6 @@ end
mcl_furnaces.furnace_node_timer = mcl_furnaces.get_timer_function()
mcl_furnaces.on_rotate = screwdriver.rotate_simple
function mcl_furnaces.after_rotate_active(pos)
local node = minetest.get_node(pos)
mcl_particles.delete_node_particlespawners(pos)
if minetest.get_item_group(node.name, "furnace_active") == 0 then
return
end
mcl_furnaces.spawn_flames(pos, node.param2)
end
-- Returns true if itemstack is fuel, but not for lava bucket if destination already has one
function mcl_furnaces.is_transferrable_fuel(itemstack, src_inventory, src_list, dst_inventory, dst_list)
@ -557,7 +509,6 @@ mcl_furnaces.tpl_furnace_node = {
after_dig_node = mcl_util.drop_items_from_meta_container({"src","dst","fuel","sorter"}),
on_destruct = function(pos)
mcl_particles.delete_node_particlespawners(pos)
mcl_furnaces.give_xp(pos)
end,
@ -605,11 +556,6 @@ mcl_furnaces.tpl_furnace_node_active = table.merge(mcl_furnaces.tpl_furnace_node
groups = { pickaxey = 1, container = 4, deco_block = 1, material_stone = 1, furnace = 1, furnace_active = 1, not_in_creative_inventory = 1 },
_doc_items_create_entry = false,
light_source = LIGHT_ACTIVE_FURNACE,
on_construct = function(pos)
local node = minetest.get_node(pos)
mcl_furnaces.spawn_flames(pos, node.param2)
end,
after_rotate = mcl_furnaces.after_rotate_active,
})
function mcl_furnaces.register_furnace(nodename, def)
@ -680,16 +626,6 @@ if minetest.get_modpath("doc") then
doc.add_entry_alias("nodes", "mcl_furnaces:furnace", "nodes", "mcl_furnaces:furnace_active")
end
minetest.register_lbm({
label = "Active furnace flame particles",
name = "mcl_furnaces:flames",
nodenames = { "group:furnace_active" },
run_at_every_load = true,
action = function(pos, node)
mcl_furnaces.spawn_flames(pos, node.param2)
end,
})
minetest.register_lbm({
label = "Update Furnace formspecs and invs to allow new sneak+click behavior",
name = "mcl_furnaces:update_coolsneak",

View File

@ -1,100 +1,3 @@
local flame_texture = {"mcl_particles_flame.png", "mcl_particles_soul_fire_flame.png"}
local smoke_pdef = {
amount = 0.5,
maxexptime = 2.0,
minvel = { x = 0.0, y = 0.5, z = 0.0 },
maxvel = { x = 0.0, y = 0.6, z = 0.0 },
minsize = 1.5,
maxsize = 1.5,
minrelpos = { x = -1/16, y = 0.04, z = -1/16 },
maxrelpos = { x = 1/16, y = 0.06, z = 1/16 },
}
local function spawn_flames_floor(pos, flame_type)
-- Flames
mcl_particles.add_node_particlespawner(pos, {
amount = 8,
time = 0,
minpos = vector.add(pos, { x = -0.1, y = 0.05, z = -0.1 }),
maxpos = vector.add(pos, { x = 0.1, y = 0.15, z = 0.1 }),
minvel = { x = -0.01, y = 0, z = -0.01 },
maxvel = { x = 0.01, y = 0.1, z = 0.01 },
minexptime = 0.3,
maxexptime = 0.6,
minsize = 0.7,
maxsize = 2,
texture = flame_texture[flame_type],
glow = minetest.registered_nodes[minetest.get_node(pos).name].light_source,
}, "low")
-- Smoke
mcl_particles.spawn_smoke(pos, "torch", smoke_pdef)
end
local function spawn_flames_wall(pos, flame_type)
--local minrelpos, maxrelpos
local node = minetest.get_node(pos)
local dir = minetest.wallmounted_to_dir(node.param2)
local smoke_pdef = table.copy(smoke_pdef)
if dir.x < 0 then
smoke_pdef.minrelpos = { x = -0.38, y = 0.24, z = -0.1 }
smoke_pdef.maxrelpos = { x = -0.2, y = 0.34, z = 0.1 }
elseif dir.x > 0 then
smoke_pdef.minrelpos = { x = 0.2, y = 0.24, z = -0.1 }
smoke_pdef.maxrelpos = { x = 0.38, y = 0.34, z = 0.1 }
elseif dir.z < 0 then
smoke_pdef.minrelpos = { x = -0.1, y = 0.24, z = -0.38 }
smoke_pdef.maxrelpos = { x = 0.1, y = 0.34, z = -0.2 }
elseif dir.z > 0 then
smoke_pdef.minrelpos = { x = -0.1, y = 0.24, z = 0.2 }
smoke_pdef.maxrelpos = { x = 0.1, y = 0.34, z = 0.38 }
else
return
end
-- Flames
mcl_particles.add_node_particlespawner(pos, {
amount = 8,
time = 0,
minpos = vector.add(pos, smoke_pdef.minrelpos),
maxpos = vector.add(pos, smoke_pdef.maxrelpos),
minvel = { x = -0.01, y = 0, z = -0.01 },
maxvel = { x = 0.01, y = 0.1, z = 0.01 },
minexptime = 0.3,
maxexptime = 0.6,
minsize = 0.7,
maxsize = 2,
texture = flame_texture[flame_type],
glow = minetest.registered_nodes[node.name].light_source,
}, "low")
-- Smoke
mcl_particles.spawn_smoke(pos, "torch", smoke_pdef)
end
local function set_flames(pos, flame_type, attached_to)
if attached_to == "wall" then
return function(pos)
spawn_flames_wall(pos, flame_type)
end
end
return function(pos)
spawn_flames_floor(pos, flame_type)
end
end
local function remove_flames(pos)
mcl_particles.delete_node_particlespawners(pos)
end
--
-- 3d torch part
--
-- Check if placement at given node is allowed
local function check_placement_allowed(node, wdir)
-- Torch placement rules: Disallow placement on some nodes. General rule: Solid, opaque, full cube collision box nodes are allowed.
@ -241,12 +144,6 @@ function mcl_torches.register_torch(def)
return itemstack
end,
on_rotate = false,
on_construct = function(pos)
if def.particles then
set_flames(pos, def.flame_type, "floor")
end
end,
on_destruct = def.particles and remove_flames,
}
minetest.register_node(itemstring, floordef)
@ -272,12 +169,6 @@ function mcl_torches.register_torch(def)
},
sounds = def.sounds,
on_rotate = false,
on_construct = function(pos)
if def.particles then
set_flames(pos, def.flame_type, "wall")
end
end,
on_destruct = def.particles and remove_flames,
}
minetest.register_node(itemstring_wall, walldef)
@ -286,18 +177,3 @@ function mcl_torches.register_torch(def)
doc.add_entry_alias("nodes", itemstring, "nodes", itemstring_wall)
end
end
minetest.register_lbm({
label = "Torch flame particles",
name = "mcl_torches:flames",
nodenames = {"group:torch_particles"},
run_at_every_load = true,
action = function(pos, node)
local torch_group = minetest.get_item_group(node.name, "torch")
if torch_group == 1 then
spawn_flames_floor(pos, minetest.get_item_group(node.name, "flame_type"))
elseif torch_group == 2 then
spawn_flames_wall(pos, minetest.get_item_group(node.name, "flame_type"))
end
end,
})

View File

@ -204,13 +204,6 @@ mcl_villages_allow_water_villages (Spawn village buildings on top of water) bool
# Note that mob icons does not exist for all mobs.
mcl_old_spawn_icons (Old spawn icons instead of eggs) bool false
# Make some blocks emit decorative particles like flames. This setting
# specifies the detail level of particles, with higher levels being
# more CPU demanding.
# WARNING: This setting has quite poor performance and can slow down your
# game by a lot.
mcl_node_particles (Block particles detail level) enum none high,medium,low,none
[Debugging]
# If enabled mapgen timings will be dumped to log
mcl_logging_mapgen (Log chunk generation) bool false