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

Commit

Permalink
Fix crashes by unknown nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Apr 9, 2014
1 parent 4cd14d9 commit be0d2a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Minetest mod "Torches"
=======================
version: 1.3.1
version: 1.3.2

License of source code and textures: WTFPL
-----------------------------------------
Expand Down Expand Up @@ -35,3 +35,6 @@ Changelog:
1.3.1:
- fix dropping torches when digging a block next to it
- all torches attached to a block get droped when dug

1.3.2:
- fix crashes by unknown nodes
31 changes: 18 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local VIEW_DISTANCE = 13 -- if player is near that distance flames are shown

local null = {x=0, y=0, z=0}

local dirs = {{-1,0,-1},{-1,0,0},{0,0,-1},
{1,0,1},{1,0,0},{0,0,1},{0,1,0}}

--fire_particles
local function add_fire(pos)
pos.y = pos.y+0.19
Expand Down Expand Up @@ -119,9 +123,11 @@ minetest.register_craftitem(":default:torch", {
local under = pointed_thing.under
local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z})
local u_n = minetest.get_node(under)
if u_n and not minetest.registered_nodes[u_n.name].walkable then above = under end
local u_n = minetest.get_node(above)
if u_n and minetest.registered_nodes[u_n.name].walkable then return itemstack end
local udef = minetest.registered_nodes[u_n.name]
if u_n and udef and not udef.walkable then above = under end
u_n = minetest.get_node(above)
udef = minetest.registered_nodes[u_n.name]
if u_n and udef and udef.walkable then return itemstack end
if wdir == 1 then
minetest.env:add_node(above, {name = "torches:floor"})
else
Expand Down Expand Up @@ -219,17 +225,16 @@ minetest.register_node("torches:wand", {
})

minetest.register_on_dignode(function(pos, oldnode, digger)
for ix=-1,1 do
for iz=-1,1 do
for iy=0,1 do
if ix ~=0 and iz ~= 0 then iy=0 end
local p = {x=pos.x+ix,y=pos.y+iy,z=pos.z+iz}
if minetest.find_node_near(pos, 1, {"group:torch"}) == nil then return end
for i=1,#dirs do
local v = dirs[i]
local p = {x=pos.x+v[1],y=pos.y+v[2],z=pos.z+v[3]}
local n = minetest.get_node_or_nil(p)
local fd = minetest.registered_nodes[n.name].update or nil
if fd ~= nil then
fd(p, n, pos)
if n and n.name then
local def = minetest.registered_nodes[n.name]
if def and def.update then
def.update(p, n, pos)
end
end
end
end
end
end)

0 comments on commit be0d2a5

Please sign in to comment.