Updated from new defaults

This commit is contained in:
TenPlus1 2016-08-20 10:29:22 +01:00
parent 26b4cafb7d
commit 7c8147e35a

204
init.lua
View File

@ -5,10 +5,11 @@
fire = {} fire = {}
fire.mod = "redo" fire.mod = "redo"
-- Register flame nodes -- Register flame nodes
minetest.register_node("fire:basic_flame", { minetest.register_node("fire:basic_flame", {
drawtype = "plantlike", --"firelike", drawtype = "plantlike", -- changed from 'firelike' for drawing speed
tiles = { tiles = {
{ {
name = "fire_basic_flame_animated.png", name = "fire_basic_flame_animated.png",
@ -27,29 +28,26 @@ minetest.register_node("fire:basic_flame", {
buildable_to = true, buildable_to = true,
sunlight_propagates = true, sunlight_propagates = true,
damage_per_second = 4, damage_per_second = 4,
groups = {igniter = 2, dig_immediate = 3}, groups = {igniter = 2, dig_immediate = 3, not_in_creative_inventory = 1},
drop = "",
on_timer = function(pos) on_timer = function(pos)
local f = minetest.find_node_near(pos, 1, {"group:flammable"}) local f = minetest.find_node_near(pos, 1, {"group:flammable"})
if not f then if not f then
-- minetest.remove_node(pos)
minetest.swap_node(pos, {name = "air"}) minetest.swap_node(pos, {name = "air"})
return return
end end
-- restart timer -- restart timer
return true return true
end, end,
drop = "",
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start(math.random(30, 60)) minetest.get_node_timer(pos):start(math.random(30, 60))
-- minetest.after(0, fire.on_flame_add_at, pos) -- minetest.after(0, fire.update_sounds_around, pos)
end, end,
-- on_destruct = function(pos) -- on_destruct = function(pos)
-- minetest.after(0, fire.on_flame_remove_at, pos) -- minetest.after(0, fire.update_sounds_around, pos)
-- end, -- end,
on_blast = function() on_blast = function()
@ -84,6 +82,7 @@ minetest.register_node("fire:permanent_flame", {
end, end,
}) })
-- Flint and steel -- Flint and steel
minetest.register_tool("fire:flint_and_steel", { minetest.register_tool("fire:flint_and_steel", {
@ -95,28 +94,32 @@ minetest.register_tool("fire:flint_and_steel", {
if pt.type == "node" then if pt.type == "node" then
local node_under = minetest.get_node(pt.under).name local node_under = minetest.get_node(pt.under).name
local is_coalblock = node_under == "default:coalblock" local is_coalblock = node_under == "default:coalblock"
local is_gunpowder = node_under == "tnt:gunpowder"
local is_tnt = node_under == "tnt:tnt" local is_tnt = node_under == "tnt:tnt"
if minetest.get_item_group(node_under, "flammable") >= 1 local is_gunpowder = node_under == "tnt:gunpowder"
or is_coalblock or is_gunpowder or is_tnt then if minetest.get_item_group(node_under, "flammable") >= 1 or
is_coalblock or is_tnt or is_gunpowder then
local flame_pos = pt.above local flame_pos = pt.above
if is_coalblock then if is_coalblock then
flame_pos = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z} flame_pos = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
end elseif is_tnt or is_gunpowder then
if is_gunpowder or is_tnt then
flame_pos = pt.under flame_pos = pt.under
end end
if minetest.get_node(flame_pos).name == "air" or is_gunpowder or is_tnt then if minetest.get_node(flame_pos).name == "air" or
is_tnt or is_gunpowder then
local player_name = user:get_player_name() local player_name = user:get_player_name()
if not minetest.is_protected(flame_pos, player_name) then if not minetest.is_protected(flame_pos, player_name) then
if is_coalblock then if is_coalblock then
minetest.set_node(flame_pos, {name = "fire:permanent_flame"}) minetest.set_node(flame_pos,
elseif is_gunpowder then {name = "fire:permanent_flame"})
minetest.set_node(flame_pos, {name = "tnt:gunpowder_burning"})
elseif is_tnt then elseif is_tnt then
minetest.set_node(flame_pos, {name = "tnt:tnt_burning"}) minetest.set_node(flame_pos,
{name = "tnt:tnt_burning"})
elseif is_gunpowder then
minetest.set_node(flame_pos,
{name = "tnt:gunpowder_burning"})
else else
minetest.set_node(flame_pos, {name = "fire:basic_flame"}) minetest.set_node(flame_pos,
{name = "fire:basic_flame"})
end end
else else
minetest.chat_send_player(player_name, "This area is protected") minetest.chat_send_player(player_name, "This area is protected")
@ -137,6 +140,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)
pos.y = pos.y + 1
if minetest.get_node(pos).name == "fire:permanent_flame" then
-- minetest.remove_node(pos)
minetest.swap_node(pos, {name = "air"})
end
end,
})
-- Get sound area of position -- Get sound area of position
fire.D = 6 -- size of sound areas fire.D = 6 -- size of sound areas
@ -147,13 +165,11 @@ function fire.get_area_p0p1(pos)
y = math.floor(pos.y / fire.D) * fire.D, y = math.floor(pos.y / fire.D) * fire.D,
z = math.floor(pos.z / fire.D) * fire.D, z = math.floor(pos.z / fire.D) * fire.D,
} }
local p1 = { local p1 = {
x = p0.x + fire.D - 1, x = p0.x + fire.D - 1,
y = p0.y + fire.D - 1, y = p0.y + fire.D - 1,
z = p0.z + fire.D - 1 z = p0.z + fire.D - 1
} }
return p0, p1 return p0, p1
end end
@ -167,30 +183,22 @@ fire.sounds = {}
-- Update fire sounds in sound area of position -- Update fire sounds in sound area of position
function fire.update_sounds_around(pos) function fire.update_sounds_around(pos)
local p0, p1 = fire.get_area_p0p1(pos) local p0, p1 = fire.get_area_p0p1(pos)
local cp = {x = (p0.x + p1.x) / 2, y = (p0.y + p1.y) / 2, z = (p0.z + p1.z) / 2} 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 flames_p = minetest.find_nodes_in_area(p0, p1, {"fire:basic_flame"})
--print("number of flames at "..minetest.pos_to_string(p0).."/" --print("number of flames at "..minetest.pos_to_string(p0).."/"
-- ..minetest.pos_to_string(p1)..": "..#flames_p) -- ..minetest.pos_to_string(p1)..": "..#flames_p)
local should_have_sound = (#flames_p > 0) local should_have_sound = (#flames_p > 0)
local wanted_sound = nil local wanted_sound = nil
if #flames_p >= 9 then if #flames_p >= 9 then
wanted_sound = {name = "fire_large", gain = 0.7} wanted_sound = {name = "fire_large", gain = 0.7}
elseif #flames_p > 0 then elseif #flames_p > 0 then
wanted_sound = {name = "fire_small", gain = 0.9} wanted_sound = {name = "fire_small", gain = 0.9}
end end
local p0_hash = minetest.hash_node_position(p0) local p0_hash = minetest.hash_node_position(p0)
local sound = fire.sounds[p0_hash] local sound = fire.sounds[p0_hash]
if not sound then if not sound then
if should_have_sound then if should_have_sound then
fire.sounds[p0_hash] = { fire.sounds[p0_hash] = {
handle = minetest.sound_play(wanted_sound, handle = minetest.sound_play(wanted_sound,
{pos = cp, max_hear_distance = 16, loop = true}), {pos = cp, max_hear_distance = 16, loop = true}),
@ -199,14 +207,10 @@ function fire.update_sounds_around(pos)
end end
else else
if not wanted_sound then if not wanted_sound then
minetest.sound_stop(sound.handle) minetest.sound_stop(sound.handle)
fire.sounds[p0_hash] = nil fire.sounds[p0_hash] = nil
elseif sound.name ~= wanted_sound.name then elseif sound.name ~= wanted_sound.name then
minetest.sound_stop(sound.handle) minetest.sound_stop(sound.handle)
fire.sounds[p0_hash] = { fire.sounds[p0_hash] = {
handle = minetest.sound_play(wanted_sound, handle = minetest.sound_play(wanted_sound,
{pos = cp, max_hear_distance = 16, loop = true}), {pos = cp, max_hear_distance = 16, loop = true}),
@ -217,105 +221,93 @@ function fire.update_sounds_around(pos)
end end
-- Update fire sounds on flame node construct or destruct
function fire.on_flame_add_at(pos)
fire.update_sounds_around(pos)
end
function fire.on_flame_remove_at(pos)
fire.update_sounds_around(pos)
end
-- Return positions for flames around a burning node
function fire.find_pos_for_flame_around(pos)
return minetest.find_node_near(pos, 1, {"air"})
end
-- Detect nearby extinguishing nodes
function fire.flame_should_extinguish(pos)
return minetest.find_node_near(pos, 1, {"group:puts_out_fire"})
end
-- Extinguish all flames quickly with water, snow, ice -- Extinguish all flames quickly with water, snow, ice
minetest.register_abm({ minetest.register_abm({
label = "Extinguish flame",
nodenames = {"fire:basic_flame", "fire:permanent_flame"}, nodenames = {"fire:basic_flame", "fire:permanent_flame"},
neighbors = {"group:puts_out_fire"}, neighbors = {"group:puts_out_fire"},
interval = 3, interval = 3,
chance = 1, chance = 1,
catch_up = false, catch_up = false,
action = function(p0, node, _, _) action = function(pos, node, active_object_count, active_object_count_wider)
minetest.swap_node(p0, {name = "air"}) -- minetest.remove_node(pos)
minetest.swap_node(pos, {name = "air"})
minetest.sound_play("fire_extinguish_flame", minetest.sound_play("fire_extinguish_flame",
{pos = p0, max_hear_distance = 16, gain = 0.25}) {pos = pos, max_hear_distance = 16, gain = 0.25})
end, end,
}) })
-- Enable the following ABMs according to 'disable fire' setting -- Enable the following ABMs according to 'enable fire' setting
if minetest.setting_getbool("disable_fire") then local fire_enabled = minetest.setting_getbool("enable_fire")
if fire_enabled == nil then
-- New setting not specified, check for old setting.
-- If old setting is also not specified, 'not nil' is true.
fire_enabled = not minetest.setting_getbool("disable_fire")
end
if not fire_enabled then
-- Remove basic flames only -- Remove basic flames only
minetest.register_abm({ minetest.register_abm({
label = "Remove disabled fire",
nodenames = {"fire:basic_flame"}, nodenames = {"fire:basic_flame"},
interval = 7, interval = 7,
chance = 1, chance = 1,
catch_up = false, catch_up = false,
action = function(p0, node, _, _) action = function(pos, node, active_object_count, active_object_count_wider)
minetest.swap_node(p0, {name = "air"}) -- minetest.remove_node(pos)
minetest.swap_node(pos, {name = "air"})
end, end,
}) })
else else -- Fire enabled
-- Ignite neighboring nodes, add basic flames -- Ignite neighboring nodes, add basic flames
minetest.register_abm({ minetest.register_abm({
label = "Ignite flame",
nodenames = {"group:flammable"}, nodenames = {"group:flammable"},
neighbors = {"group:igniter"}, neighbors = {"group:igniter"},
interval = 7, interval = 7,
chance = 8, chance = 12,
catch_up = false, catch_up = false,
action = function(p0, node, _, _) action = function(pos, node, active_object_count, active_object_count_wider)
-- If there is water or stuff like that around node, don't ignite -- If there is water or stuff like that around node, don't ignite
if fire.flame_should_extinguish(p0) then if minetest.find_node_near(pos, 1, {"group:puts_out_fire"}) then
return return
end end
local p = fire.find_pos_for_flame_around(p0) local p = minetest.find_node_near(pos, 1, {"air"})
if p then if p then
minetest.swap_node(p, {name = "fire:basic_flame"}) minetest.swap_node(p, {name = "fire:basic_flame"})
-- minetest.set_node(p, {name = "fire:basic_flame"})
end end
end, end,
}) })
-- Remove basic flames and flammable nodes -- Remove flammable nodes
minetest.register_abm({ minetest.register_abm({
label = "Remove flammable nodes",
nodenames = {"fire:basic_flame"}, nodenames = {"fire:basic_flame"},
neighbors = "group:flammable",
interval = 5, interval = 5,
chance = 4, chance = 18,
catch_up = false, catch_up = false,
action = function(p0, node, _, _) action = function(pos, node, active_object_count, active_object_count_wider)
-- If there are no flammable nodes around flame, remove flame local p = minetest.find_node_near(pos, 1, {"group:flammable"})
local p = minetest.find_node_near(p0, 1, {"group:flammable"}) if p then
if p and math.random(1, 3) == 1 then
-- remove flammable nodes around flame -- remove flammable nodes around flame
local node = minetest.get_node(p) local flammable_node = minetest.get_node(p)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[flammable_node.name]
if def.on_burn then if def.on_burn then
def.on_burn(p) def.on_burn(p)
else else
minetest.remove_node(p) -- minetest.remove_node(p)
minetest.swap_node(p, {name = "air"})
nodeupdate(p) nodeupdate(p)
end end
end end
@ -325,6 +317,38 @@ else
end end
-- Rarely ignite things from far
--[[ Currently disabled to reduce the chance of uncontrollable spreading
fires that disrupt servers. Also for less lua processing load.
minetest.register_abm({
nodenames = {"group:igniter"},
neighbors = {"air"},
interval = 5,
chance = 10,
action = function(pos, node, active_object_count, active_object_count_wider)
local reg = minetest.registered_nodes[node.name]
if not reg or not reg.groups.igniter or reg.groups.igniter < 2 then
return
end
local d = reg.groups.igniter
local p = minetest.find_node_near(pos, d, {"group:flammable"})
if p then
-- If there is water or stuff like that around flame, don't ignite
if fire.flame_should_extinguish(p) then
return
end
local p2 = fire.find_pos_for_flame_around(p)
if p2 then
minetest.set_node(p2, {name = "fire:basic_flame"})
end
end
end,
})
--]]
-- used to drop items inside a chest or container -- used to drop items inside a chest or container
function fire.drop_items(pos, invstring) function fire.drop_items(pos, invstring)
@ -337,10 +361,9 @@ function fire.drop_items(pos, invstring)
local obj = minetest.add_item(pos, m_stack) local obj = minetest.add_item(pos, m_stack)
if obj then if obj then
obj:setvelocity({ obj:setvelocity({
x = math.random(-10, 10) / 9, x = math.random(-10, 10) / 9,
y = 3, y = 1,
z = math.random(-10, 10) / 9 z = math.random(-10, 10) / 9
}) })
end end
@ -360,16 +383,3 @@ minetest.override_item("default:chest", {
end, end,
}) })
-- Override coalblock to enable lighting a permanent flame above
minetest.override_item("default:coalblock", {
after_destruct = function(pos, oldnode)
pos.y = pos.y + 1
if minetest.get_node(pos).name == "fire:permanent_flame" then
minetest.swap_node(pos, {name = "air"})
end
end,
})