2021-05-24 22:48:46 +00:00
|
|
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
2021-01-01 18:25:47 +00:00
|
|
|
|
|
|
|
mcl_burning = {
|
2022-03-02 14:40:29 +00:00
|
|
|
-- the storage table holds a list of objects (players,luaentities) and tables
|
|
|
|
-- associated with these objects. These tables have the following attributes:
|
|
|
|
-- burn_time:
|
|
|
|
-- Remaining time that object will burn.
|
|
|
|
-- fire_damage_timer:
|
|
|
|
-- Timer for dealing damage every second while burning.
|
|
|
|
-- fire_hud_id:
|
|
|
|
-- HUD id of the flames animation on a burning player's HUD.
|
|
|
|
-- animation_frame:
|
|
|
|
-- The HUD's current animation frame, used by update_hud().
|
|
|
|
-- collisionbox_cache:
|
|
|
|
-- Used by mcl_burning.get_collisionbox() to avoid recalculations.
|
2022-03-02 13:57:20 +00:00
|
|
|
storage = {}
|
2021-01-01 18:25:47 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 09:55:14 +00:00
|
|
|
dofile(modpath .. "/api.lua")
|
2021-01-01 18:25:47 +00:00
|
|
|
|
2022-03-02 14:25:03 +00:00
|
|
|
local pairs = pairs
|
|
|
|
local get_connected_players = minetest.get_connected_players
|
|
|
|
local get_item_group = minetest.get_item_group
|
|
|
|
|
2021-04-25 11:09:20 +00:00
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-05-29 14:12:33 +00:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2021-04-25 11:09:20 +00: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 14:12:33 +00:00
|
|
|
if get_item_group(node.name, "puts_out_fire") > 0 then
|
2021-04-25 11:09:20 +00:00
|
|
|
burn_time = 0
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2021-05-29 14:12:33 +00:00
|
|
|
local value = get_item_group(node.name, "set_on_fire")
|
2021-04-25 11:09:20 +00: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)
|
|
|
|
|
2022-03-02 13:57:20 +00:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local storage = {}
|
|
|
|
local burn_data = player:get_meta():get_string("mcl_burning:data")
|
|
|
|
if burn_data ~= "" then
|
2022-03-03 09:14:35 +00:00
|
|
|
storage = minetest.deserialize(burn_data) or storage
|
2021-04-25 11:09:20 +00:00
|
|
|
end
|
2022-03-02 13:57:20 +00:00
|
|
|
mcl_burning.storage[player] = storage
|
2022-03-02 16:15:05 +00:00
|
|
|
if storage.burn_time and storage.burn_time > 0 then
|
|
|
|
mcl_burning.update_hud(player)
|
|
|
|
end
|
2022-03-02 13:57:20 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
local function on_leaveplayer(player)
|
|
|
|
local storage = mcl_burning.storage[player]
|
2022-03-29 10:06:00 +00:00
|
|
|
if not storage then
|
|
|
|
-- For some unexplained reasons, mcl_burning.storage can be `nil` here.
|
|
|
|
-- Logging this exception to assist in finding the cause of this.
|
|
|
|
minetest.log("warning", "on_leaveplayer: missing mcl_burning.storage "
|
2022-03-29 23:31:38 +00:00
|
|
|
.. "for player " .. player:get_player_name())
|
2022-03-29 10:06:00 +00:00
|
|
|
storage = {}
|
|
|
|
end
|
2022-03-02 13:57:20 +00:00
|
|
|
storage.fire_hud_id = nil
|
|
|
|
player:get_meta():set_string("mcl_burning:data", minetest.serialize(storage))
|
|
|
|
mcl_burning.storage[player] = nil
|
2021-11-13 02:46:16 +00:00
|
|
|
end
|
|
|
|
|
2022-03-02 13:57:20 +00:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
on_leaveplayer(player)
|
2021-04-25 11:09:20 +00:00
|
|
|
end)
|
|
|
|
|
2022-03-02 13:57:20 +00:00
|
|
|
minetest.register_on_shutdown(function()
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
|
|
|
on_leaveplayer(player)
|
|
|
|
end
|
2021-04-25 11:09:20 +00:00
|
|
|
end)
|
|
|
|
|
2022-03-02 13:57:20 +00:00
|
|
|
local animation_frames = tonumber(minetest.settings:get("fire_animation_frames")) or 8
|
2021-04-25 11:09:20 +00:00
|
|
|
|
2021-01-01 18:25:47 +00:00
|
|
|
minetest.register_entity("mcl_burning:fire", {
|
|
|
|
initial_properties = {
|
|
|
|
physical = false,
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
2021-09-18 20:28:20 +00:00
|
|
|
visual = "upright_sprite",
|
|
|
|
textures = {
|
2022-03-02 09:47:46 +00:00
|
|
|
"mcl_burning_entity_flame_animated.png",
|
|
|
|
"mcl_burning_entity_flame_animated.png"
|
2021-09-18 20:28:20 +00:00
|
|
|
},
|
2022-03-02 13:57:20 +00:00
|
|
|
spritediv = {x = 1, y = animation_frames},
|
2021-01-01 18:25:47 +00:00
|
|
|
pointable = false,
|
|
|
|
glow = -1,
|
2021-05-21 18:45:53 +00:00
|
|
|
backface_culling = false,
|
2021-01-01 18:25:47 +00:00
|
|
|
},
|
2022-03-03 08:38:59 +00:00
|
|
|
_mcl_animation_timer = 0,
|
2021-09-18 20:28:20 +00:00
|
|
|
on_activate = function(self)
|
2022-03-02 13:57:20 +00:00
|
|
|
self.object:set_sprite({x = 0, y = 0}, animation_frames, 1.0 / animation_frames)
|
2021-09-18 20:28:20 +00:00
|
|
|
end,
|
2022-03-02 13:57:20 +00:00
|
|
|
on_step = function(self, dtime)
|
2021-04-25 11:09:20 +00:00
|
|
|
local parent = self.object:get_attach()
|
|
|
|
if not parent then
|
2022-03-02 13:57:20 +00:00
|
|
|
self.object:remove()
|
|
|
|
return
|
2021-04-25 11:09:20 +00:00
|
|
|
end
|
|
|
|
local storage = mcl_burning.get_storage(parent)
|
|
|
|
if not storage or not storage.burn_time then
|
2022-03-02 13:57:20 +00:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if parent:is_player() then
|
2022-03-03 08:38:59 +00:00
|
|
|
self._mcl_animation_timer = self._mcl_animation_timer + dtime
|
|
|
|
if self._mcl_animation_timer >= 0.1 then
|
|
|
|
self._mcl_animation_timer = 0
|
2022-03-02 13:57:20 +00:00
|
|
|
mcl_burning.update_hud(parent)
|
|
|
|
end
|
2021-04-25 11:09:20 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|