forked from VoxeLibre/VoxeLibre
222 lines
6.7 KiB
Lua
222 lines
6.7 KiB
Lua
-- ||||||||||||||||||||||||||||||||
|
|
-- ||||||||||| CAMPFIRES ||||||||||
|
|
-- ||||||||||||||||||||||||||||||||
|
|
|
|
-- TO-DO:
|
|
-- * Add Spark Particles
|
|
-- * Add Cooking Meat
|
|
-- * Add Working Sounds
|
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
mcl_campfires = {}
|
|
|
|
function mcl_campfires.register_smoke(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
-- delete existing spawner
|
|
local existing_spawner = meta:get_int("smoke_particlespawner")
|
|
if existing_spawner ~= 0 then
|
|
minetest.delete_particlespawner(existing_spawner)
|
|
end
|
|
|
|
-- velocity: 0.5
|
|
-- acceleration: 0.1
|
|
------------------------
|
|
-- 7 seconds ~= 10 nodes
|
|
-- 12 seconds ~= 20 nodes
|
|
|
|
local time = 7
|
|
if minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name == "mcl_farming:hay_block" then
|
|
time = 12
|
|
end
|
|
|
|
-- create new spawner
|
|
local smokeID = minetest.add_particlespawner({
|
|
time = 0,
|
|
ammount = 0.2,
|
|
collisiondetection = true,
|
|
texture = "mcl_campfires_smoke_4.png",
|
|
texpool = {
|
|
{ name = "mcl_campfires_smoke_0.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_2.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_3.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_4.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_5.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_7.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_8.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_9.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_1.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_10.png", alpha_tween = {1, 0}},
|
|
{ name = "mcl_campfires_smoke_11.png", alpha_tween = {1, 0}},
|
|
},
|
|
|
|
minpos = {x=pos.x - 0.25, y=pos.y + 0.25, z=pos.z - 0.25},
|
|
maxpos = {x=pos.x + 0.25, y=pos.y + 0.25, z=pos.z + 0.25},
|
|
minvel = {x=0, y=1, z=0},
|
|
maxvel = {x=0, y=1, z=0},
|
|
minacc = {x=0, y=0.1, z=0},
|
|
maxacc = {x=0, y=0.1, z=0},
|
|
minexptime = time,
|
|
maxexptime = time,
|
|
minsize = 12,
|
|
maxsize = 12,
|
|
})
|
|
|
|
-- save the id in meta
|
|
meta:set_int("smoke_particlespawner", smokeID)
|
|
|
|
return smokeID
|
|
end
|
|
|
|
function mcl_campfires.remove_smoke(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
local smokeID = meta:get_int("smoke_particlespawner")
|
|
|
|
-- end function if smoke doesnt exist
|
|
if not smokeID then return 0 end
|
|
|
|
return minetest.delete_particlespawner(smokeID)
|
|
end
|
|
|
|
|
|
local campfires = {
|
|
{ name = "Campfire", lightlevel = 14, techname = "campfire", damage = 1, drops = "mcl_core:charcoal_lump 2" },
|
|
{ name = "Soul Campfire", lightlevel = 10, techname = "soul_campfire", damage = 2, drops = "mcl_blackstone:soul_soil" },
|
|
}
|
|
|
|
for _, campfire in pairs(campfires) do
|
|
-- Define Campfire
|
|
minetest.register_node("mcl_campfires:" .. campfire.techname, {
|
|
description = S(campfire.name),
|
|
_tt_help = S("Cooks food and keeps bees happy."),
|
|
_doc_items_longdesc = S("Campfires have multiple uses, including keeping bees happy, cooking raw meat and fish, and as a trap."),
|
|
inventory_image = "mcl_campfires_" .. campfire.techname .. "_inv.png",
|
|
drawtype = "mesh",
|
|
mesh = "mcl_campfires_campfire.obj",
|
|
tiles = {{name="mcl_campfires_log.png"},},
|
|
use_texture_alpha = "clip",
|
|
groups = { handy=1, axey=1, material_wood=1, not_in_creative_inventory=1, campfire=1, },
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
|
|
if player:get_wielded_item():get_name() == "mcl_fire:flint_and_steel" then
|
|
node.name = "mcl_campfires:" .. campfire.techname .. "_lit"
|
|
minetest.set_node(pos, node)
|
|
end
|
|
end,
|
|
drop = campfire.drops,
|
|
_mcl_silk_touch_drop = {"mcl_campfires:" .. campfire.techname},
|
|
mcl_sounds.node_sound_wood_defaults(),
|
|
selection_box = {
|
|
type = 'fixed',
|
|
fixed = {-.5, -.5, -.5, .5, -.05, .5}, --left, bottom, front, right, top
|
|
},
|
|
collision_box = {
|
|
type = 'fixed',
|
|
fixed = {-.5, -.5, -.5, .5, -.05, .5},
|
|
},
|
|
_mcl_blast_resistance = 2,
|
|
_mcl_hardness = 2,
|
|
})
|
|
|
|
--Define Lit Campfire
|
|
minetest.register_node("mcl_campfires:" .. campfire.techname .. "_lit", {
|
|
description = S(campfire.name),
|
|
_tt_help = S("Cooks food and keeps bees happy."),
|
|
_doc_items_longdesc = S("Campfires have multiple uses, including keeping bees happy, cooking raw meat and fish, and as a trap."),
|
|
inventory_image = "mcl_campfires_" .. campfire.techname .. "_inv.png",
|
|
drawtype = "mesh",
|
|
mesh = "mcl_campfires_campfire_lit.obj",
|
|
tiles = {{
|
|
name="mcl_campfires_" .. campfire.techname .. "_fire.png",
|
|
animation={
|
|
type="vertical_frames",
|
|
aspect_w=16,
|
|
aspect_h=16,
|
|
length=2.0
|
|
}},
|
|
{name="mcl_campfires_" .. campfire.techname .. "_log_lit.png",
|
|
animation={
|
|
type="vertical_frames",
|
|
aspect_w=16,
|
|
aspect_h=16,
|
|
length=2.0
|
|
}}
|
|
},
|
|
use_texture_alpha = "clip",
|
|
groups = { handy=1, axey=1, material_wood=1, campfire=1, lit_campfire=1 },
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
on_construct = mcl_campfires.register_smoke,
|
|
on_destruct = mcl_campfires.remove_smoke,
|
|
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
|
|
if player:get_wielded_item():get_name():find("shovel") then
|
|
node.name = "mcl_campfires:" .. campfire.techname
|
|
minetest.set_node(pos, node)
|
|
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true)
|
|
mcl_campfires.remove_smoke(pos)
|
|
end
|
|
end,
|
|
drop = campfire.drops,
|
|
_mcl_silk_touch_drop = {"mcl_campfires:" .. campfire.techname .. "_lit"},
|
|
light_source = campfire.lightlevel,
|
|
mcl_sounds.node_sound_wood_defaults(),
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = {-.5, -.5, -.5, .5, -.05, .5}, --left, bottom, front, right, top
|
|
},
|
|
collision_box = {
|
|
type = "fixed",
|
|
fixed = {-.5, -.5, -.5, .5, -.05, .5},
|
|
},
|
|
_mcl_blast_resistance = 2,
|
|
_mcl_hardness = 2,
|
|
damage_per_second = campfire.damage,
|
|
})
|
|
end
|
|
|
|
minetest.register_craft({
|
|
output = "mcl_campfires:campfire_lit",
|
|
recipe = {
|
|
{ "", "mcl_core:stick", "" },
|
|
{ "mcl_core:stick", "group:coal", "mcl_core:stick" },
|
|
{ "group:tree", "group:tree", "group:tree" },
|
|
}
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mcl_campfires:soul_campfire_lit",
|
|
recipe = {
|
|
{ "", "mcl_core:stick", "" },
|
|
{ "mcl_core:stick", "group:soul_block", "mcl_core:stick" },
|
|
{ "group:tree", "group:tree", "group:tree" },
|
|
}
|
|
})
|
|
|
|
local function burn_in_campfire(obj)
|
|
local p = obj:get_pos()
|
|
if p then
|
|
local n = minetest.find_node_near(p,0.4,{"group:lit_campfire"},true)
|
|
if n then
|
|
mcl_burning.set_on_fire(obj, 5)
|
|
end
|
|
end
|
|
end
|
|
|
|
local etime = 0
|
|
minetest.register_globalstep(function(dtime)
|
|
etime = dtime + etime
|
|
if etime < 0.5 then return end
|
|
etime = 0
|
|
for _,pl in pairs(minetest.get_connected_players()) do
|
|
burn_in_campfire(pl)
|
|
end
|
|
for _,ent in pairs(minetest.luaentities) do
|
|
if ent.is_mob then
|
|
burn_in_campfire(ent.object)
|
|
end
|
|
end
|
|
end)
|