mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-06-06 05:44:26 -04:00
Merge 907c22a401
into 76471dd137
This commit is contained in:
commit
b057c94831
2 changed files with 59 additions and 31 deletions
11
game_api.txt
11
game_api.txt
|
@ -145,6 +145,17 @@ farming.register_plant(name, Plant definition)
|
||||||
maxlight = default.LIGHT_MAX -- Maximum light to grow
|
maxlight = default.LIGHT_MAX -- Maximum light to grow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fire API
|
||||||
|
--------
|
||||||
|
The fire API supports nodes with groups.flammable set, with an optional callback function:
|
||||||
|
|
||||||
|
on_burn(position, igniter_node_name, action)
|
||||||
|
^ Optionally return true to prevent node being removed
|
||||||
|
-> position: "Burn position"
|
||||||
|
-> igniter_node_name: "Igniting node's name"
|
||||||
|
-> action: "Action in progress"
|
||||||
|
^ Current <action> passed to, is "remove"
|
||||||
|
|
||||||
Screwdriver API
|
Screwdriver API
|
||||||
---------------
|
---------------
|
||||||
The screwdriver API allows you to control a node's behaviour when a screwdriver is used on it.
|
The screwdriver API allows you to control a node's behaviour when a screwdriver is used on it.
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
-- Global namespace for functions
|
-- Global namespace for functions
|
||||||
|
|
||||||
fire = {}
|
fire = {}
|
||||||
|
fire.features = {
|
||||||
|
on_burn_callback = true, -- When groups.flammable node about to be burnt, calls:
|
||||||
|
-- node.on_burn(position, source_node_name, action_string)
|
||||||
|
-- `action_string` = "remove"
|
||||||
|
-- Return: true, stops the node being removed.
|
||||||
|
}
|
||||||
|
|
||||||
-- Register flame nodes
|
-- Register flame nodes
|
||||||
|
|
||||||
|
@ -172,10 +177,10 @@ minetest.register_abm({
|
||||||
interval = 3,
|
interval = 3,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(p0, node, _, _)
|
action = function(position, node, _, _)
|
||||||
minetest.remove_node(p0)
|
minetest.remove_node(position)
|
||||||
minetest.sound_play("fire_extinguish_flame",
|
minetest.sound_play("fire_extinguish_flame",
|
||||||
{pos = p0, max_hear_distance = 16, gain = 0.25})
|
{pos = position, max_hear_distance = 16, gain = 0.25})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -191,13 +196,11 @@ if minetest.setting_getbool("disable_fire") then
|
||||||
interval = 7,
|
interval = 7,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(p0, node, _, _)
|
action = function(position, node, _, _)
|
||||||
minetest.remove_node(p0)
|
minetest.remove_node(position)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
-- Ignite neighboring nodes, add basic flames
|
-- Ignite neighboring nodes, add basic flames
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
@ -206,14 +209,15 @@ else
|
||||||
interval = 7,
|
interval = 7,
|
||||||
chance = 16,
|
chance = 16,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(p0, node, _, _)
|
action = function(position, node, _, _)
|
||||||
-- 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 fire.flame_should_extinguish(position) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local p = fire.find_pos_for_flame_around(p0)
|
|
||||||
if p then
|
local air_position = fire.find_pos_for_flame_around(position)
|
||||||
minetest.set_node(p, {name = "fire:basic_flame"})
|
if air_position then
|
||||||
|
minetest.set_node(air_position, {name = "fire:basic_flame"})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -225,18 +229,29 @@ else
|
||||||
interval = 5,
|
interval = 5,
|
||||||
chance = 16,
|
chance = 16,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(p0, node, _, _)
|
action = function(position, node, _, _)
|
||||||
-- If there are no flammable nodes around flame, remove flame
|
-- If there are no flammable nodes around flame, remove flame
|
||||||
if not minetest.find_node_near(p0, 1, {"group:flammable"}) then
|
local flammable_position = minetest.find_node_near(position, 1, {"group:flammable"})
|
||||||
minetest.remove_node(p0)
|
if not flammable_position then
|
||||||
|
minetest.remove_node(position)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.random(1, 4) == 1 then
|
if math.random(1, 4) == 1 then
|
||||||
-- remove flammable nodes around flame
|
local node_def = minetest.registered_nodes[minetest.get_node(flammable_position).name]
|
||||||
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
|
local remove = node_def -- Used as later check to not remove Unknown nodes!
|
||||||
if p then
|
|
||||||
minetest.remove_node(p)
|
if node_def and node_def.on_burn then
|
||||||
nodeupdate(p)
|
-- Allow node to handle, if it returns true, no removal
|
||||||
|
-- Note: "not" reversing result, so nil/false defaults to remove
|
||||||
|
remove = not node_def.on_burn(flammable_position, node.name, "remove")
|
||||||
|
end
|
||||||
|
if remove then
|
||||||
|
-- Remove flammable nodes around flame
|
||||||
|
minetest.remove_node(flammable_position)
|
||||||
|
|
||||||
|
-- Trigger any falling nodes supported
|
||||||
|
nodeupdate(flammable_position)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -255,21 +270,23 @@ minetest.register_abm({
|
||||||
neighbors = {"air"},
|
neighbors = {"air"},
|
||||||
interval = 5,
|
interval = 5,
|
||||||
chance = 10,
|
chance = 10,
|
||||||
action = function(p0, node, _, _)
|
action = function(position, node, _, _)
|
||||||
local reg = minetest.registered_nodes[node.name]
|
local node_def = minetest.registered_nodes[node.name]
|
||||||
if not reg or not reg.groups.igniter or reg.groups.igniter < 2 then
|
if not node_def or not node_def.groups.igniter or node_def.groups.igniter < 2 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local d = reg.groups.igniter
|
|
||||||
local p = minetest.find_node_near(p0, d, {"group:flammable"})
|
local igniter_radius = node_def.groups.igniter
|
||||||
if p then
|
local flammable_position = minetest.find_node_near(position, igniter_radius, {"group:flammable"})
|
||||||
|
if flammable_position then
|
||||||
-- If there is water or stuff like that around flame, don't ignite
|
-- If there is water or stuff like that around flame, don't ignite
|
||||||
if fire.flame_should_extinguish(p) then
|
if fire.flame_should_extinguish(flammable_position) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local p2 = fire.find_pos_for_flame_around(p)
|
|
||||||
if p2 then
|
local air_position = fire.find_pos_for_flame_around(flammable_position)
|
||||||
minetest.set_node(p2, {name = "fire:basic_flame"})
|
if air_position then
|
||||||
|
minetest.set_node(air_position, {name = "fire:basic_flame"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Add table
Reference in a new issue