From 2a1273b7e3f81e626e1a992d548dc90196d5f515 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 19 Aug 2020 16:29:20 +0200 Subject: [PATCH] Add flame particles to torches and furnaces --- mods/CORE/mcl_particles/init.lua | 35 +++++++ .../textures/mcl_particles_flame.png | Bin 0 -> 145 bytes mods/ITEMS/mcl_furnaces/depends.txt | 1 + mods/ITEMS/mcl_furnaces/init.lua | 63 +++++++++++- mods/ITEMS/mcl_torches/depends.txt | 1 + mods/ITEMS/mcl_torches/init.lua | 97 +++++++++++++++++- 6 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 mods/CORE/mcl_particles/textures/mcl_particles_flame.png diff --git a/mods/CORE/mcl_particles/init.lua b/mods/CORE/mcl_particles/init.lua index e69de29bb..f4ebd85e5 100644 --- a/mods/CORE/mcl_particles/init.lua +++ b/mods/CORE/mcl_particles/init.lua @@ -0,0 +1,35 @@ +local particle_nodes = {} + +mcl_particles = {} + +-- Add a particlespawner that is assigned to a given node position. +-- * pos: Node positon. MUST use rounded 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 +function mcl_particles.add_node_particlespawner(pos, particlespawner_definition) + 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 + 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) + local poshash = minetest.hash_node_position(pos) + local id = particle_nodes[poshash] + if id then + minetest.delete_particlespawner(id) + return true + end + return false +end diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_flame.png b/mods/CORE/mcl_particles/textures/mcl_particles_flame.png new file mode 100644 index 0000000000000000000000000000000000000000..92efed2900df9263e78e43c7dd8df18c42b57de1 GIT binary patch literal 145 zcmeAS@N?(olHy`uVBq!ia0vp^93afX3?$7I7w-U4q5(c3u89QOl|geZ%dOL4hT%Y644$rjF6*2UngD*~EkFPO literal 0 HcmV?d00001 diff --git a/mods/ITEMS/mcl_furnaces/depends.txt b/mods/ITEMS/mcl_furnaces/depends.txt index 365076c1f..ca05945f1 100644 --- a/mods/ITEMS/mcl_furnaces/depends.txt +++ b/mods/ITEMS/mcl_furnaces/depends.txt @@ -4,5 +4,6 @@ mcl_core mcl_sounds mcl_craftguide mcl_achievements +mcl_particles doc? screwdriver? diff --git a/mods/ITEMS/mcl_furnaces/init.lua b/mods/ITEMS/mcl_furnaces/init.lua index cb797ff91..b2d69ad1d 100644 --- a/mods/ITEMS/mcl_furnaces/init.lua +++ b/mods/ITEMS/mcl_furnaces/init.lua @@ -1,6 +1,8 @@ local S = minetest.get_translator("mcl_furnaces") +local LIGHT_ACTIVE_FURNACE = 13 + -- -- Formspecs -- @@ -346,9 +348,48 @@ local function furnace_node_timer(pos, elapsed) return result end -local on_rotate +local function 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, + }) +end + +local on_rotate, after_rotate_active 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) + spawn_flames(pos, node.param2) + end end minetest.register_node("mcl_furnaces:furnace", { @@ -431,7 +472,7 @@ minetest.register_node("mcl_furnaces:furnace_active", { }, paramtype2 = "facedir", paramtype = "light", - light_source = 13, + light_source = LIGHT_ACTIVE_FURNACE, drop = "mcl_furnaces:furnace", groups = {pickaxey=1, container=4, deco_block=1, not_in_creative_inventory=1, material_stone=1}, is_ground_content = false, @@ -453,6 +494,13 @@ minetest.register_node("mcl_furnaces:furnace_active", { meta:from_table(meta2:to_table()) end, + on_construct = function(pos) + local node = minetest.get_node(pos) + spawn_flames(pos, node.param2) + end, + on_destruct = function(pos) + mcl_particles.delete_node_particlespawner(pos) + end, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_move = allow_metadata_inventory_move, @@ -462,6 +510,7 @@ minetest.register_node("mcl_furnaces:furnace_active", { _mcl_blast_resistance = 3.5, _mcl_hardness = 3.5, on_rotate = on_rotate, + after_rotate = after_rotate_active, }) minetest.register_craft({ @@ -478,6 +527,16 @@ 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 = {"mcl_furnaces:furnace_active"}, + run_at_every_load = true, + action = function(pos, node) + spawn_flames(pos, node.param2) + end, +}) + -- Legacy minetest.register_lbm({ label = "Update furnace formspecs (0.60.0", diff --git a/mods/ITEMS/mcl_torches/depends.txt b/mods/ITEMS/mcl_torches/depends.txt index cbc0405cc..d15228bce 100644 --- a/mods/ITEMS/mcl_torches/depends.txt +++ b/mods/ITEMS/mcl_torches/depends.txt @@ -1,3 +1,4 @@ mcl_core mcl_sounds +mcl_particles doc? diff --git a/mods/ITEMS/mcl_torches/init.lua b/mods/ITEMS/mcl_torches/init.lua index 86cb917b9..c9ec1370c 100644 --- a/mods/ITEMS/mcl_torches/init.lua +++ b/mods/ITEMS/mcl_torches/init.lua @@ -1,4 +1,60 @@ 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, { + 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 = "mcl_particles_flame.png", + glow = LIGHT_TORCH, + }) +end + +local spawn_flames_wall = function(pos, param2) + local minrelpos, maxrelpos + local dir = minetest.wallmounted_to_dir(param2) + if dir.x < 0 then + minrelpos = { x = -0.38, y = 0.04, z = -0.1 } + maxrelpos = { x = -0.2, y = 0.14, z = 0.1 } + elseif dir.x > 0 then + minrelpos = { x = 0.2, y = 0.04, z = -0.1 } + maxrelpos = { x = 0.38, y = 0.14, z = 0.1 } + elseif dir.z < 0 then + minrelpos = { x = -0.1, y = 0.04, z = -0.38 } + maxrelpos = { x = 0.1, y = 0.14, z = -0.2 } + elseif dir.z > 0 then + minrelpos = { x = -0.1, y = 0.04, z = 0.2 } + maxrelpos = { x = 0.1, y = 0.14, z = 0.38 } + else + return + end + return mcl_particles.add_node_particlespawner(pos, { + amount = 8, + 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.7, + maxsize = 2, + texture = "mcl_particles_flame.png", + glow = LIGHT_TORCH, + }) +end + +local remove_flames = function(pos) + mcl_particles.delete_node_particlespawner(pos) +end -- -- 3d torch part @@ -43,7 +99,7 @@ end mcl_torches = {} -mcl_torches.register_torch = function(substring, description, doc_items_longdesc, doc_items_usagehelp, icon, mesh_floor, mesh_wall, tiles, light, groups, sounds, moredef) +mcl_torches.register_torch = function(substring, description, doc_items_longdesc, doc_items_usagehelp, icon, mesh_floor, mesh_wall, tiles, light, groups, sounds, moredef, moredef_floor, moredef_wall) local itemstring = minetest.get_current_modname()..":"..substring local itemstring_wall = minetest.get_current_modname()..":"..substring.."_wall" @@ -138,6 +194,11 @@ mcl_torches.register_torch = function(substring, description, doc_items_longdesc floordef[k] = v end end + if moredef_floor ~= nil then + for k,v in pairs(moredef_floor) do + floordef[k] = v + end + end minetest.register_node(itemstring, floordef) local groups_wall = table.copy(groups) @@ -169,6 +230,11 @@ mcl_torches.register_torch = function(substring, description, doc_items_longdesc walldef[k] = v end end + if moredef_wall ~= nil then + for k,v in pairs(moredef_wall) do + walldef[k] = v + end + end minetest.register_node(itemstring_wall, walldef) @@ -189,11 +255,20 @@ mcl_torches.register_torch("torch", name = "default_torch_on_floor_animated.png", animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3} }}, - minetest.LIGHT_MAX, + LIGHT_TORCH, {dig_immediate=3, torch=1, deco_block=1}, mcl_sounds.node_sound_wood_defaults(), - {_doc_items_hidden = false}) - + {_doc_items_hidden = false, + on_destruct = function(pos) + remove_flames(pos) + end}, + {on_construct = function(pos) + spawn_flames_floor(pos) + end}, + {on_construct = function(pos) + local node = minetest.get_node(pos) + spawn_flames_wall(pos, node.param2) + end}) minetest.register_craft({ output = "mcl_torches:torch 4", @@ -203,3 +278,17 @@ minetest.register_craft({ } }) +minetest.register_lbm({ + label = "Torch flame particles", + name = "mcl_torches:flames", + nodenames = {"mcl_torches:torch", "mcl_torches:torch_wall"}, + run_at_every_load = true, + action = function(pos, node) + if node.name == "mcl_torches:torch" then + spawn_flames_floor(pos) + elseif node.name == "mcl_torches:torch_wall" then + spawn_flames_wall(pos, node.param2) + end + end, +}) +