Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Show flames only when player in range
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Jan 16, 2014
1 parent 7b4178b commit 5e4294a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local VIEW_DISTANCE = 13 -- if player is near that distance flames are shown

local null = {x=0, y=0, z=0}
--fire_particles
local function add_fire(pos)
Expand Down Expand Up @@ -32,14 +34,26 @@ function check_attached_node_fdir(p, n)
return true
end

local function player_near(pos)
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, VIEW_DISTANCE)) do
if object:is_player() then
return true
end
end

return false
end

minetest.register_abm({
nodenames = {"torches:wand"},
interval = 1,
chance = 1,
action = function(pos)
add_fire(pos)
if player_near(pos) then
add_fire(pos)
end
if not check_attached_node_fdir(pos, minetest.env:get_node(pos)) then
minetest.env:dig_node(pos)
minetest.dig_node(pos)
end
end
})
Expand All @@ -49,13 +63,15 @@ minetest.register_abm({
interval = 1,
chance = 1,
action = function(pos)
add_fire(pos)
if player_near(pos) then
add_fire(pos)
end
pos.y = pos.y-1
local nn = minetest.env:get_node(pos).name
local def2 = minetest.registered_nodes[nn]
if def2 and not def2.walkable then
pos.y = pos.y+1
minetest.env:dig_node(pos)
minetest.dig_node(pos)
end
end
})
Expand Down

0 comments on commit 5e4294a

Please sign in to comment.