Added campfire life time

This commit is contained in:
Pavel Litvinoff 2017-03-15 18:09:42 +02:00
parent ef990ee389
commit a4b62156b5
3 changed files with 61 additions and 12 deletions

View File

@ -1,6 +1,6 @@
Minetest mod "New Campfire" Minetest mod "New Campfire"
====================== ======================
Version: 0.2.0 Version: 0.2.3
# License of source code: # License of source code:
- Copyright (C) 2017 Pavel Litvinoff <googolgl@gmail.com> - Copyright (C) 2017 Pavel Litvinoff <googolgl@gmail.com>
@ -36,6 +36,10 @@ group:stone default:stick group:stone
#### [0.2.0] - 2017-02-13 #### [0.2.0] - 2017-02-13
- added animation particles of fire and smoke - added animation particles of fire and smoke
#### [0.2.3] - 2017-03-15
- added: sound file, new textures, changed model, config_file
- added campfire life time
# Links: # Links:
- Forum Topic: - Forum Topic:
- <https://forum.minetest.net/viewtopic.php?f=9&t=16611> - <https://forum.minetest.net/viewtopic.php?f=9&t=16611>

View File

@ -1,3 +1,5 @@
-- config.lua -- config.lua
campfire_limit = 1 --Values: 0 - no limit, 1 - limit new_campfire_limit = 1; -- Values: 0 - unlimit campfire, 1 - limit
new_campfire_ttl = 90; -- Time in sec
new_campfire_stick_time = new_campfire_ttl/2; -- How long does the stick increase. In sec.

View File

@ -6,7 +6,6 @@ new_campfire = {}
local S, NS = dofile(MP.."/intllib.lua") local S, NS = dofile(MP.."/intllib.lua")
dofile(MP.."/config.lua") dofile(MP.."/config.lua")
-- FUNCTIONS -- FUNCTIONS
local function fire_particles_on(pos) -- 3 layers of fire local function fire_particles_on(pos) -- 3 layers of fire
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -85,6 +84,22 @@ local function fire_particles_off(pos)
minetest.delete_particlespawner(id_3) minetest.delete_particlespawner(id_3)
end end
local function indicator(maxVal, curVal)
local percent_val = math.floor(curVal / maxVal * 100)
local progress = ""
local v = percent_val / 10
for k=1,10 do
if v > 0 then
progress = progress..""
else
progress = progress..""
end
v = v - 1
end
-- print(progress.." "..percent_val.."%")
return "\n"..progress.." "..percent_val.."%"
end
-- NODES -- NODES
minetest.register_node('new_campfire:campfire', { minetest.register_node('new_campfire:campfire', {
@ -154,14 +169,34 @@ minetest.register_node('new_campfire:campfire_active', {
on_rightclick = function(pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if itemstack:get_name() == "default:stick" then if itemstack:get_name() == "default:stick" then
print("=================") local meta = minetest.get_meta(pos)
print(campfire_limit) local it_val = meta:get_int("it_val") + (new_campfire_stick_time);
meta:set_int('it_val', it_val);
local id = minetest.add_particle({
pos = {x = pos.x, y = pos.y+0.5, z = pos.z},
velocity = {x=0, y=-1, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 1,
size = 4,
collisiondetection = true,
vertical = true,
texture = "default_stick.png",
})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
return itemstack
end
end end
end, end,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string('infotext', S("Active campfire").."\n▓▓▓▓▓▓▓▒▒▒ 70% "); if new_campfire_limit == 1 and new_campfire_ttl > 0 then
meta:set_int('it_val', new_campfire_ttl);
meta:set_string('infotext', S("Active campfire")..indicator(1, 1));
else
meta:set_string('infotext', S("Active campfire"));
end
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end, end,
@ -197,8 +232,16 @@ minetest.register_abm({
minetest.set_node(pos, {name = 'new_campfire:campfire'}) minetest.set_node(pos, {name = 'new_campfire:campfire'})
minetest.sound_play("fire_extinguish_flame",{pos = pos, max_hear_distance = 16, gain = 0.15}) minetest.sound_play("fire_extinguish_flame",{pos = pos, max_hear_distance = 16, gain = 0.15})
else else
local meta = minetest.get_meta(pos) if new_campfire_limit == 1 and new_campfire_ttl > 0 then
-- local id_1 = meta:get_int("layer_1") local meta = minetest.get_meta(pos)
local it_val = meta:get_int("it_val") - 3;
if it_val <= 0 then
minetest.remove_node(pos)
return
end
meta:set_int('it_val', it_val);
meta:set_string('infotext', S("Active campfire")..indicator(new_campfire_ttl, it_val));
end
fire_particles_on(pos) fire_particles_on(pos)
end end
end end
@ -208,8 +251,8 @@ minetest.register_abm({
minetest.register_craft({ minetest.register_craft({
output = "new_campfire:campfire", output = "new_campfire:campfire",
recipe = { recipe = {
{'', 'default:stick', ''}, {'', 'default:stick', ''},
{'group:stone','default:stick', 'group:stone'}, {'group:stone','default:stick', 'group:stone'},
{'', 'group:stone', ''}, {'', 'group:stone', ''},
} }
}) })