First Commit by TenPlus1
This commit is contained in:
commit
e6647ab67e
32
README.txt
Normal file
32
README.txt
Normal file
@ -0,0 +1,32 @@
|
||||
Minetest 0.4 mod: fire
|
||||
======================
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
Copyright (C) 2012 Perttu Ahola (celeron55) <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
|
||||
License of media (textures and sounds)
|
||||
--------------------------------------
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
Authors of media files
|
||||
-----------------------
|
||||
Everything not listed in here:
|
||||
Copyright (C) 2012 Perttu Ahola (celeron55) <celeron55@gmail.com>
|
||||
|
||||
fire_small.ogg sampled from:
|
||||
http://www.freesound.org/people/dobroide/sounds/4211/
|
||||
|
||||
fire_large.ogg sampled from:
|
||||
http://www.freesound.org/people/Dynamicell/sounds/17548/
|
||||
|
||||
fire_basic_flame_animated.png:
|
||||
Muadtralk
|
137
init.lua
Normal file
137
init.lua
Normal file
@ -0,0 +1,137 @@
|
||||
-- minetest/fire/init.lua
|
||||
|
||||
minetest.register_node("fire:basic_flame", {
|
||||
description = "Fire",
|
||||
drawtype = "plantlike",
|
||||
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",
|
||||
light_source = 14,
|
||||
groups = {igniter=2,dig_immediate=3,hot=3},
|
||||
drop = "",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
damage_per_second = 4,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
fire.update_sounds_around(pos) -- add
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
fire.update_sounds_around(pos) --remove
|
||||
end,
|
||||
})
|
||||
|
||||
fire = {}
|
||||
fire.D = 6
|
||||
-- key: position hash of low corner of area
|
||||
-- value: {handle=sound handle, name=sound name}
|
||||
fire.sounds = {}
|
||||
|
||||
function fire.update_sounds_around(pos)
|
||||
|
||||
local p0 = {
|
||||
x=math.floor(pos.x/fire.D)*fire.D,
|
||||
y=math.floor(pos.y/fire.D)*fire.D,
|
||||
z=math.floor(pos.z/fire.D)*fire.D,
|
||||
}
|
||||
local p1 = {
|
||||
x=p0.x+fire.D-1,
|
||||
y=p0.y+fire.D-1,
|
||||
z=p0.z+fire.D-1
|
||||
}
|
||||
|
||||
local cp = {x=(p0.x+p1.x)/2, y=(p0.y+p1.y)/2, z=(p0.z+p1.z)/2}
|
||||
local flames_p = minetest.find_nodes_in_area(p0, p1, {"fire:basic_flame"})
|
||||
local should_have_sound = (#flames_p > 0)
|
||||
local wanted_sound = nil
|
||||
|
||||
if #flames_p >= 9 then
|
||||
wanted_sound = {name="fire_large", gain=1.5}
|
||||
elseif #flames_p > 0 then
|
||||
wanted_sound = {name="fire_small", gain=1.5}
|
||||
end
|
||||
|
||||
local p0_hash = minetest.hash_node_position(p0)
|
||||
local sound = fire.sounds[p0_hash]
|
||||
if not sound then
|
||||
if should_have_sound then
|
||||
fire.sounds[p0_hash] = {
|
||||
handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
|
||||
name = wanted_sound.name,
|
||||
}
|
||||
end
|
||||
else
|
||||
if not wanted_sound then
|
||||
minetest.sound_stop(sound.handle)
|
||||
fire.sounds[p0_hash] = nil
|
||||
elseif sound.name ~= wanted_sound.name then
|
||||
minetest.sound_stop(sound.handle)
|
||||
fire.sounds[p0_hash] = {
|
||||
handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
|
||||
name = wanted_sound.name,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fire.flame_should_extinguish(pos)
|
||||
if minetest.setting_getbool("disable_fire") then return true end
|
||||
local ps = minetest.find_nodes_in_area( {x=pos.x-1, y=pos.y, z=pos.z-1}, -- all 1's were 2
|
||||
{x=pos.x+1, y=pos.y, z=pos.z+1},
|
||||
{"group:puts_out_fire"})
|
||||
return (#ps ~= 0)
|
||||
end
|
||||
|
||||
-- Ignite neighboring nodes
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:flammable"},
|
||||
neighbors = {"group:igniter"},
|
||||
interval = 2, -- 1
|
||||
chance = 2,
|
||||
action = function(p0, node, _, _)
|
||||
-- If there is water or stuff like that around flame, don't ignite
|
||||
if fire.flame_should_extinguish(p0) then return end
|
||||
local p = minetest.find_node_near(p0, 1, {"air"})
|
||||
if p then
|
||||
minetest.set_node(p, {name="fire:basic_flame"})
|
||||
fire.update_sounds_around(p) --add
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Remove flammable nodes and flame
|
||||
minetest.register_abm({
|
||||
nodenames = {"fire:basic_flame"},
|
||||
interval = 2, -- 1
|
||||
chance = 2,
|
||||
action = function(p0, node, _, _)
|
||||
|
||||
-- If no flammable nodes around flame (or are extinguishers), remove flame
|
||||
if not minetest.find_node_near(p0, 1, {"group:flammable"})
|
||||
or fire.flame_should_extinguish(p0) then
|
||||
minetest.env:set_node(p0, {name="air"})
|
||||
fire.update_sounds_around(p0) --remove
|
||||
return
|
||||
end
|
||||
|
||||
if math.random(1,4) == 1 then
|
||||
-- remove a flammable node around flame
|
||||
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
|
||||
if p then
|
||||
-- If there is water or stuff like that around flame, don't remove
|
||||
if fire.flame_should_extinguish(p0) then
|
||||
return
|
||||
end
|
||||
minetest.env:set_node(p, {name="air"})
|
||||
-- nodeupdate(p)
|
||||
end
|
||||
else
|
||||
-- remove flame
|
||||
minetest.env:set_node(p0, {name="air"})
|
||||
fire.update_sounds_around(p0) --remove
|
||||
end
|
||||
end,
|
||||
})
|
BIN
sounds/fire_large.ogg
Normal file
BIN
sounds/fire_large.ogg
Normal file
Binary file not shown.
BIN
sounds/fire_small.ogg
Normal file
BIN
sounds/fire_small.ogg
Normal file
Binary file not shown.
BIN
textures/fire_basic_flame.png
Normal file
BIN
textures/fire_basic_flame.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 785 B |
BIN
textures/fire_basic_flame_animated.png
Normal file
BIN
textures/fire_basic_flame_animated.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Loading…
x
Reference in New Issue
Block a user