From 03c9aed2212099c764912e4c7b1c86679237f00d Mon Sep 17 00:00:00 2001 From: Maksim Date: Mon, 6 Apr 2020 22:09:39 +0200 Subject: [PATCH] Fire mod: Code cleanup, compress textures --- mods/fire/init.lua | 165 ++++++------------ mods/fire/textures/fire_basic_flame.png | Bin 646 -> 594 bytes .../textures/fire_basic_flame_animated.png | Bin 1051 -> 1029 bytes mods/fire/textures/fire_flint_steel.png | Bin 459 -> 205 bytes 4 files changed, 54 insertions(+), 111 deletions(-) diff --git a/mods/fire/init.lua b/mods/fire/init.lua index c35207e2..298063e5 100644 --- a/mods/fire/init.lua +++ b/mods/fire/init.lua @@ -1,15 +1,12 @@ -- fire/init.lua -- Global namespace for functions - fire = {} -- Load support for MT game translation. local S = minetest.get_translator("fire") - -- 'Enable fire' setting - local fire_enabled = minetest.settings:get_bool("enable_fire") if fire_enabled == nil then -- enable_fire setting not specified, check for disable_fire @@ -27,12 +24,9 @@ end -- -- Flood flame function - -local function flood_flame(pos, oldnode, newnode) +local function flood_flame(pos, _, newnode) -- Play flame extinguish sound if liquid is not an 'igniter' - local nodedef = minetest.registered_items[newnode.name] - if not (nodedef and nodedef.groups and - nodedef.groups.igniter and nodedef.groups.igniter > 0) then + if minetest.get_item_group(newnode.name, "igniter") == 0 then minetest.sound_play("fire_extinguish_flame", {pos = pos, max_hear_distance = 16, gain = 0.15}, true) end @@ -41,19 +35,16 @@ local function flood_flame(pos, oldnode, newnode) end -- Flame nodes - -minetest.register_node("fire:basic_flame", { +local fire_node = { drawtype = "firelike", - tiles = { - { - name = "fire_basic_flame_animated.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1 - }, - }, + tiles = {{ + name = "fire_basic_flame_animated.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1 + }} }, inventory_image = "fire_basic_flame.png", paramtype = "light", @@ -63,61 +54,35 @@ minetest.register_node("fire:basic_flame", { sunlight_propagates = true, floodable = true, damage_per_second = 4, - groups = {igniter = 2, dig_immediate = 3, not_in_creative_inventory = 1}, + groups = {igniter = 2, dig_immediate = 3, fire = 1}, drop = "", + on_flood = flood_flame +} - on_timer = function(pos) - local f = minetest.find_node_near(pos, 1, {"group:flammable"}) - if not fire_enabled or not f then - minetest.remove_node(pos) - return - end - -- Restart timer - return true - end, +-- Basic flame node +local flame_fire_node = table.copy(fire_node) +flame_fire_node.groups.not_in_creative_inventory = 1 +flame_fire_node.on_timer = function(pos) + if not minetest.find_node_near(pos, 1, {"group:flammable"}) then + minetest.remove_node(pos) + return + end + -- Restart timer + return true +end +flame_fire_node.on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(30, 60)) +end - on_construct = function(pos) - if not fire_enabled then - minetest.remove_node(pos) - else - minetest.get_node_timer(pos):start(math.random(30, 60)) - end - end, +minetest.register_node("fire:basic_flame", flame_fire_node) - on_flood = flood_flame, -}) +-- Permanent flame node +local permanent_fire_node = table.copy(fire_node) +permanent_fire_node.description = S("Permanent Flame") -minetest.register_node("fire:permanent_flame", { - description = S("Permanent Flame"), - drawtype = "firelike", - tiles = { - { - name = "fire_basic_flame_animated.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1 - }, - }, - }, - inventory_image = "fire_basic_flame.png", - paramtype = "light", - light_source = 13, - walkable = false, - buildable_to = true, - sunlight_propagates = true, - floodable = true, - damage_per_second = 4, - groups = {igniter = 2, dig_immediate = 3}, - drop = "", - - on_flood = flood_flame, -}) - - --- Flint and steel +minetest.register_node("fire:permanent_flame", permanent_fire_node) +-- Flint and Steel minetest.register_tool("fire:flint_and_steel", { description = S("Flint and Steel"), inventory_image = "fire_flint_steel.png", @@ -125,11 +90,8 @@ minetest.register_tool("fire:flint_and_steel", { on_use = function(itemstack, user, pointed_thing) local sound_pos = pointed_thing.above or user:get_pos() - minetest.sound_play( - "fire_flint_and_steel", - {pos = sound_pos, gain = 0.5, max_hear_distance = 8}, - true - ) + minetest.sound_play("fire_flint_and_steel", + {pos = sound_pos, gain = 0.5, max_hear_distance = 8}, true) local player_name = user:get_player_name() if pointed_thing.type == "node" then local node_under = minetest.get_node(pointed_thing.under).name @@ -153,10 +115,11 @@ minetest.register_tool("fire:flint_and_steel", { -- Wear tool local wdef = itemstack:get_definition() itemstack:add_wear(1000) + -- Tool break sound if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then - minetest.sound_play(wdef.sound.breaks, {pos = sound_pos, - gain = 0.5}, true) + minetest.sound_play(wdef.sound.breaks, + {pos = sound_pos, gain = 0.5}, true) end return itemstack end @@ -170,23 +133,21 @@ minetest.register_craft({ } }) - -- Override coalblock to enable permanent flame above -- Coalblock is non-flammable to avoid unwanted basic_flame nodes - minetest.override_item("default:coalblock", { - after_destruct = function(pos, oldnode) + after_destruct = function(pos) pos.y = pos.y + 1 if minetest.get_node(pos).name == "fire:permanent_flame" then minetest.remove_node(pos) end end, - on_ignite = function(pos, igniter) + on_ignite = function(pos) local flame_pos = {x = pos.x, y = pos.y + 1, z = pos.z} if minetest.get_node(flame_pos).name == "air" then minetest.set_node(flame_pos, {name = "fire:permanent_flame"}) end - end, + end }) @@ -194,24 +155,18 @@ minetest.override_item("default:coalblock", { -- Sound -- -local flame_sound = minetest.settings:get_bool("flame_sound") -if flame_sound == nil then - -- Enable if no setting present - flame_sound = true -end +-- Enable if no setting present +local flame_sound = minetest.settings:get_bool("flame_sound", true) if flame_sound then - local handles = {} local timer = 0 -- Parameters - local radius = 8 -- Flame node search radius around player local cycle = 3 -- Cycle time for sound updates -- Update sound for player - function fire.update_player_sound(player) local player_name = player:get_player_name() -- Search for flame nodes in radius around player @@ -263,16 +218,13 @@ if flame_sound then fposmid = vector.divide(vector.add(fposmin, fposmax), 2) end -- Play sound - local handle = minetest.sound_play( - "fire_fire", - { - pos = fposmid, - to_player = player_name, - gain = math.min(0.06 * (1 + flames * 0.125), 0.18), - max_hear_distance = 32, - loop = true, -- In case of lag - } - ) + local handle = minetest.sound_play("fire_fire", { + pos = fposmid, + to_player = player_name, + gain = math.min(0.06 * (1 + flames * 0.125), 0.18), + max_hear_distance = 32, + loop = true -- In case of lag + }) -- Store sound handle for this player if handle then handles[player_name] = handle @@ -281,7 +233,6 @@ if flame_sound then end -- Cycle for updating players sounds - minetest.register_globalstep(function(dtime) timer = timer + dtime if timer < cycle then @@ -296,7 +247,6 @@ if flame_sound then end) -- Stop sound and clear handle on player leave - minetest.register_on_leaveplayer(function(player) local player_name = player:get_player_name() if handles[player_name] then @@ -308,19 +258,14 @@ end -- Deprecated function kept temporarily to avoid crashes if mod fire nodes call it - -function fire.update_sounds_around(pos) -end - +function fire.update_sounds_around() end -- -- ABMs -- if fire_enabled then - -- Ignite neighboring nodes, add basic flames - minetest.register_abm({ label = "Ignite flame", nodenames = {"group:flammable"}, @@ -333,11 +278,10 @@ if fire_enabled then if p then minetest.set_node(p, {name = "fire:basic_flame"}) end - end, + end }) -- Remove flammable nodes around basic flame - minetest.register_abm({ label = "Remove flammable nodes", nodenames = {"fire:basic_flame"}, @@ -358,7 +302,6 @@ if fire_enabled then minetest.remove_node(p) minetest.check_for_falling(p) end - end, + end }) - end diff --git a/mods/fire/textures/fire_basic_flame.png b/mods/fire/textures/fire_basic_flame.png index 1da0702d85369becb732573b894c97f198246fa9..484bcb1957b80a64bdd670241c8e08b464545a3d 100644 GIT binary patch delta 580 zcmV-K0=xZ&1=0kN8Gix*005AYXf^-<00wkYPE!B?00000Zl(v300069Nkl>MB-sIFQUib-Fc3^_+wP&Z zZQHhO+qP}vZQHhO8~c+pVhn;sd!|htzIv%;B?aP2qbeZm>wi#tWz&Y*K3}`mYDnRc=O=+LNWq?dVuSb3F=^ZtBQL~$>PIFcZla{vipV$aODU156Ze_3Pn7OSh zqYHh}<*je8V1gqZc#WQC38o#%YIuR(i0~^N zfuqu0;SM9RT_>>YgB|ctK;XEApL$5qbW?!)z|C~F37aM{@*n25B#o9|I0@H z-bDPWKmNo$|Diqo$u{!1HTK0Z|AR2}n=kfT%#5)<~VHDOx5n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8UEIJ#(O#0my9tUmRGZ4{rc$wzEH>833Qe!f8ME;}R(qodaOC{&HXF z3UVBx7l76B=-oJ9e*gCKF%oB{{OayI?$Pw*yZRN);^HXz@ch7r$1us#lD?kJH*z>I zH}Yt2>K@QM*2zQ80_0=#Xki@5%skx8!xlt_fPW+@k|Gbk?%`td?^1l&*R-cgrP_5v z^We!NqQq`D1t+*xy#k69W>uX9*`nTsA;#`YG_d7 z@pyRfp?wkx)*1~e=2QG$*cVFY(@JT38+H_t=i@uY{o7$cA)rcS{>Eyx?iA2hhFeZ2 zQ0a6)K$hMHc?eFZ=nP*da=IhK(S+5KSqmwiAKxJVpP!x2d= rMosqr|Ks;Y%a76WW3>DrxBLJAts&A)NM9EG00000NkvXXu0mjfDL(rU diff --git a/mods/fire/textures/fire_flint_steel.png b/mods/fire/textures/fire_flint_steel.png index c262ebc096f471c95e66b33ca3cd44a14494419d..9d32d85b001c0836b969989ffeb7bc16856eb71c 100644 GIT binary patch delta 189 zcmX@je3o&7L_G^L0|Ud`yN`l^lx~1ei0l9V|7~n+qQe3*Q({F#M9PbDyj<*@oSZCx zz*u+f+O<=rOfl8htgf!k&(D`SlRFWpk+CGmFPOpM*^M+H$IsKnF{FYq`2d?lB99{D ziiU~IQv{zKxOa~sg~Q$N<*itTl#Y3G_H7e8A}~ABZ0p?jRudjh+qkW9FVl&H!ux!t p?aA-CIhyxAvO4pIYfTt4!*n*mIRyeM-vW(h@O1TaS?83{1ORHON4Nk0 delta 445 zcmV;u0Yd)G0m}oB7=H)`0000V^Z#K0000DMK}|sb0I`n?{9y$E0004VQb$4o*~u(_ z0000WV@Og>004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006VoOIv z0RI600RN!9r;`8x0XIoRK~y-)#go5F!%z^%Kd)x#4as7Lx_=ZQg9r%@B4o~=(>edv z`w!y!KuVDa($P*C0u~{hAi{I7scp4l>EJE*IPShbj(f&?&oMDLY8nXoM}D1s6^D_3 ze|<3kZdxCvAQ(n|e0EAOjQ-?pusfVyoC7eQ&kwWEM;Jydo)!Q|6jKxhfLB#SgjF_G zRc!-ovOh1EB!A-(bzS=;Nhr&brfC4M*6z0uh7q?bWPmKoD9e)BY=*UV4YC*Dp{_Xz zg0=j~WJ1$4IOhON*LCE14zOOZ=?^K6V}EmX`DvkhTQgTxg@~9{zXwoNoO5Pt2g!J3 z?(QFbFTH2p7zQu^BJ$mWo7S{#YudIostQ1!=cH-sRW^0+O$0v`MFeXts!CB5Ta3Rh naYw2V5#yYrSM+1!zyHP$nva4h^9C`w00000NkvXXu0mjfj*zl<