From be0d2a5a83df023396e64e084da74c19ab207926 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Wed, 9 Apr 2014 13:00:41 +0200 Subject: [PATCH] Fix crashes by unknown nodes --- README.txt | 5 ++++- init.lua | 31 ++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.txt b/README.txt index 7e9f14e..ef1b16d 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,6 @@ Minetest mod "Torches" ======================= -version: 1.3.1 +version: 1.3.2 License of source code and textures: WTFPL ----------------------------------------- @@ -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 diff --git a/init.lua b/init.lua index e554734..e4c2d34 100644 --- a/init.lua +++ b/init.lua @@ -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 @@ -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 @@ -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)