]> git.lizzy.rs Git - crafter_client.git/blob - fire_handling.lua
Update README.md
[crafter_client.git] / fire_handling.lua
1 local minetest,name = minetest,minetest.localplayer:get_name()
2 local fire_handling_channel = minetest.mod_channel_join(name..":fire_state")
3
4 local on_fire = 0
5 local fire_id = nil
6 local fire_animation_timer = 0
7 local fire_animation_tile = 0
8 --receive the server states
9 minetest.register_on_modchannel_message(function(channel_name, sender, message)
10         if sender == "" and channel_name == name..":fire_state" then
11         on_fire = tonumber(message)
12         end
13 end)
14
15 minetest.register_globalstep(function(dtime)
16     if on_fire == 0 then 
17         if fire_id then
18             minetest.localplayer:hud_remove(fire_id)
19             fire_id = nil
20         end
21     elseif on_fire == 1 then
22         if fire_id == nil then
23             fire_id = minetest.localplayer:hud_add({
24                                 hud_elem_type = "image", -- see HUD element types, default "text"
25                                 position = {x=0.5, y=0.5},
26                                 name = "",    -- default ""
27                                 scale = {x=-100, y=-100}, -- default {x=0,y=0}
28                                 text = "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile,
29             })
30         else
31             fire_animation_timer = fire_animation_timer + dtime
32             if fire_animation_timer >= 0.05 then
33                 fire_animation_timer = 0
34                 fire_animation_tile = fire_animation_tile + 1
35                 if fire_animation_tile > 7 then
36                     fire_animation_tile = 0
37                 end
38                 minetest.localplayer:hud_change(fire_id, "text", "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile)
39             end
40         end
41     end
42 end)