2021-05-25 01:48:46 +03:00
|
|
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
2021-01-01 20:25:47 +02:00
|
|
|
|
2021-05-29 17:12:33 +03:00
|
|
|
local pairs = pairs
|
|
|
|
|
|
|
|
local get_connected_players = minetest.get_connected_players
|
|
|
|
local get_item_group = minetest.get_item_group
|
|
|
|
|
2021-01-01 20:25:47 +02:00
|
|
|
mcl_burning = {
|
2021-04-25 14:09:20 +03:00
|
|
|
storage = {},
|
2021-09-18 23:28:20 +03:00
|
|
|
channels = {},
|
2021-01-01 20:25:47 +02:00
|
|
|
animation_frames = tonumber(minetest.settings:get("fire_animation_frames")) or 8
|
|
|
|
}
|
|
|
|
|
2021-02-22 11:55:14 +02:00
|
|
|
dofile(modpath .. "/api.lua")
|
2021-01-01 20:25:47 +02:00
|
|
|
|
2021-04-25 14:09:20 +03:00
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-05-29 17:12:33 +03:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2021-04-25 14:09:20 +03:00
|
|
|
local storage = mcl_burning.storage[player]
|
|
|
|
if not mcl_burning.tick(player, dtime, storage) and not mcl_burning.is_affected_by_rain(player) then
|
|
|
|
local nodes = mcl_burning.get_touching_nodes(player, {"group:puts_out_fire", "group:set_on_fire"}, storage)
|
|
|
|
local burn_time = 0
|
|
|
|
|
|
|
|
for _, pos in pairs(nodes) do
|
|
|
|
local node = minetest.get_node(pos)
|
2021-05-29 17:12:33 +03:00
|
|
|
if get_item_group(node.name, "puts_out_fire") > 0 then
|
2021-04-25 14:09:20 +03:00
|
|
|
burn_time = 0
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2021-05-29 17:12:33 +03:00
|
|
|
local value = get_item_group(node.name, "set_on_fire")
|
2021-04-25 14:09:20 +03:00
|
|
|
if value > burn_time then
|
|
|
|
burn_time = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if burn_time > 0 then
|
|
|
|
mcl_burning.set_on_fire(player, burn_time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_respawnplayer(function(player)
|
|
|
|
mcl_burning.extinguish(player)
|
|
|
|
end)
|
|
|
|
|
2021-11-13 04:46:16 +02:00
|
|
|
function mcl_burning.init_player(player)
|
|
|
|
local meta = player:get_meta()
|
|
|
|
-- NOTE: mcl_burning:data may be "return nil" (which deserialize into nil) for reasons unknown.
|
|
|
|
if meta:get_string("mcl_burning:data"):find("return nil", 1, true) then
|
|
|
|
minetest.log("warning", "[mcl_burning] 'mcl_burning:data' player meta field is invalid! Please report this bug")
|
2021-04-25 14:09:20 +03:00
|
|
|
end
|
2021-11-13 04:46:16 +02:00
|
|
|
mcl_burning.storage[player] = meta:contains("mcl_burning:data") and minetest.deserialize(meta:get_string("mcl_burning:data")) or {}
|
2021-09-18 23:28:20 +03:00
|
|
|
mcl_burning.channels[player] = minetest.mod_channel_join("mcl_burning:" .. player:get_player_name())
|
2021-11-13 04:46:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
mcl_burning.init_player(player)
|
2021-04-25 14:09:20 +03:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
2021-09-18 23:28:20 +03:00
|
|
|
player:get_meta():set_string("mcl_burning:data", minetest.serialize(mcl_burning.storage[player]))
|
2021-04-25 14:09:20 +03:00
|
|
|
mcl_burning.storage[player] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2021-01-01 20:25:47 +02:00
|
|
|
minetest.register_entity("mcl_burning:fire", {
|
|
|
|
initial_properties = {
|
|
|
|
physical = false,
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
2021-09-18 23:28:20 +03:00
|
|
|
visual = "upright_sprite",
|
|
|
|
textures = {
|
2022-03-02 11:47:46 +02:00
|
|
|
"mcl_burning_entity_flame_animated.png",
|
|
|
|
"mcl_burning_entity_flame_animated.png"
|
2021-09-18 23:28:20 +03:00
|
|
|
},
|
|
|
|
spritediv = {x = 1, y = mcl_burning.animation_frames},
|
2021-01-01 20:25:47 +02:00
|
|
|
pointable = false,
|
|
|
|
glow = -1,
|
2021-05-21 21:45:53 +03:00
|
|
|
backface_culling = false,
|
2021-01-01 20:25:47 +02:00
|
|
|
},
|
|
|
|
animation_frame = 0,
|
|
|
|
animation_timer = 0,
|
2021-09-18 23:28:20 +03:00
|
|
|
on_activate = function(self)
|
|
|
|
self.object:set_sprite({x = 0, y = 0}, mcl_burning.animation_frames, 1.0 / mcl_burning.animation_frames)
|
|
|
|
end,
|
|
|
|
on_step = function(self)
|
|
|
|
if not self:sanity_check() then
|
2021-04-25 14:09:20 +03:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
sanity_check = function(self)
|
|
|
|
local parent = self.object:get_attach()
|
2020-12-24 18:48:40 +02:00
|
|
|
|
2021-04-25 14:09:20 +03:00
|
|
|
if not parent then
|
2021-09-18 23:28:20 +03:00
|
|
|
return false
|
2021-04-25 14:09:20 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local storage = mcl_burning.get_storage(parent)
|
|
|
|
|
|
|
|
if not storage or not storage.burn_time then
|
2021-09-18 23:28:20 +03:00
|
|
|
return false
|
2021-04-25 14:09:20 +03:00
|
|
|
end
|
|
|
|
|
2021-09-18 23:28:20 +03:00
|
|
|
return true
|
2021-04-25 14:09:20 +03:00
|
|
|
end,
|
|
|
|
})
|