campfire v .0.0.1

master
hunterdelyx1 2014-02-03 14:56:50 +04:00
parent ce34ab4d42
commit c842c401e1
7 changed files with 216 additions and 0 deletions

2
campfire/depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
fire

2
campfire/depends.txt~ Normal file
View File

@ -0,0 +1,2 @@
default
fire

106
campfire/init.lua Normal file
View File

@ -0,0 +1,106 @@
-- fire definition (distance from entity to center(x, y and z) and angle of rotation)
local fire_struct ={
[1]={0, -0.2, 0.29, 0},
[2]={0.29, -0.2, 0, math.pi/2},
[3]={-0.29, -0.2, 0, 3*math.pi/2},
[4]={0, -0.2, -0.29, math.pi},
[5]={0, 0, 0, -math.pi/4},
[6]={0, 0, 0, math.pi/4}
}
--
minetest.register_node("campfire:fireplace", {
tiles = { "default_cobble.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, -0.3, -0.3, 0.3},
{-0.3, -0.5, 0.5, 0.3, -0.3, 0.3},
{0.3, -0.5, 0.3, 0.5, -0.3, -0.3},
{-0.3, -0.5, -0.3, 0.3, -0.3, -0.5},
},
},
groups = {dig_immediate=2},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
for _, v in ipairs(fire_struct) do
minetest.add_entity({x=pos.x+v[1],y=pos.y+v[2],z=pos.z+v[3]}, "campfire:fire"):setyaw(v[4])
end
minetest.swap_node(pos, {name="campfire:fireplace_fire"})
end,
})
minetest.register_node("campfire:fireplace_fire", {
tiles = { "default_cobble.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, -0.3, -0.3, 0.3},
{-0.3, -0.5, 0.5, 0.3, -0.3, 0.3},
{0.3, -0.5, 0.3, 0.5, -0.3, -0.3},
{-0.3, -0.5, -0.3, 0.3, -0.3, -0.5},
},
},
groups = {dig_immediate=2, hot=1},
light_source = 50,
damage_per_second = 4,
on_destruct = function(pos)
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do
if v:get_entity_name() == "campfire:fire" then
v:remove()
end
end
end
})
local frame_max = 2 -- amount of frames in fire animation
local frame_speed = 1 -- animation speed: seconds on frame
local frame = 1
local frame_time = 0
-- Global function, which control frame changing
minetest.register_globalstep(
function(dtime)
if frame_time > frame_speed then
if frame < frame_max then
frame=frame+1
else
frame=1
end
frame_time=0
end
frame_time = frame_time + dtime
end
)
minetest.register_entity("campfire:fire", {
collisionbox = {0,0,0,0,0,0},
visual = "upright_sprite",
visual_size = {x=0.6, y=0.8},
textures = {"fire_basic_flame.png"},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = true,
-- Updating fire texture for animation. DONT TOUCH, MAZAFUCKER! I know that it can be crutch. I'll sleep and fix it by myself.
on_step = function(self, dtime)
if frame_time > frame_speed then
self.object:set_properties({textures ={"campfire_fire_"..frame ..".png"}})
end
end
--
})

106
campfire/init.lua~ Normal file
View File

@ -0,0 +1,106 @@
-- fire definition (distance from entity to center(x, y and z) and angle of rotation)
local fire_struct ={
[1]={0, -0.2, 0.29, 0},
[2]={0.29, -0.2, 0, math.pi/2},
[3]={-0.29, -0.2, 0, 3*math.pi/2},
[4]={0, -0.2, -0.29, math.pi},
[5]={0, 0, 0, -math.pi/4},
[6]={0, 0, 0, math.pi/4}
}
--
minetest.register_node("campfire:fireplace", {
tiles = { "default_cobble.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, -0.3, -0.3, 0.3},
{-0.3, -0.5, 0.5, 0.3, -0.3, 0.3},
{0.3, -0.5, 0.3, 0.5, -0.3, -0.3},
{-0.3, -0.5, -0.3, 0.3, -0.3, -0.5},
},
},
groups = {dig_immediate=2},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
for _, v in ipairs(fire_struct) do
minetest.add_entity({x=pos.x+v[1],y=pos.y+v[2],z=pos.z+v[3]}, "campfire:fire"):setyaw(v[4])
end
minetest.swap_node(pos, {name="campfire:fireplace_fire"})
end,
})
minetest.register_node("campfire:fireplace_fire", {
tiles = { "default_cobble.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, -0.3, -0.3, 0.3},
{-0.3, -0.5, 0.5, 0.3, -0.3, 0.3},
{0.3, -0.5, 0.3, 0.5, -0.3, -0.3},
{-0.3, -0.5, -0.3, 0.3, -0.3, -0.5},
},
},
groups = {dig_immediate=2, hot=1},
light_source = 50,
damage_per_second = 4,
on_destruct = function(pos)
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do
if v:get_entity_name() == "campfire:fire" then
v:remove()
end
end
end
})
local frame_max = 2 -- amount of frames in fire animation
local frame_speed = 1 -- animation speed: seconds on frame
local frame = 1
local frame_time = 0
-- Global function, which control frame changing
minetest.register_globalstep(
function(dtime)
if frame_time > frame_speed then
if frame < frame_max then
frame=frame+1
else
frame=1
end
frame_time=0
end
frame_time = frame_time + dtime
end
)
minetest.register_entity("campfire:fire", {
collisionbox = {0,0,0,0,0,0},
visual = "upright_sprite",
visual_size = {x=0.6, y=0.8},
textures = {"fire_basic_flame.png"},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = true,
-- Updating fire texture for animation. DONT TOUCH, MAZAFUCKER! I know that it can be crutch. I'll sleep and fix it by myself.
on_step = function(self, dtime)
if frame_time > frame_speed then
self.object:set_properties({textures ={"campfire_fire_"..frame ..".png"}})
end
end
--
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB