From 38cf151806444812e03d92a49c857fc34654d91d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 29 Jun 2017 13:02:53 +0200 Subject: [PATCH] Fix many crashes when placing item on unknown node --- mods/CORE/mcl_util/init.lua | 3 +++ mods/ITEMS/REDSTONE/mesecons_button/init.lua | 1 + mods/ITEMS/bucket/init.lua | 4 ++-- mods/ITEMS/mcl_beds/api.lua | 3 ++- mods/ITEMS/mcl_core/nodes.lua | 4 ++++ mods/ITEMS/mcl_doors/api_doors.lua | 10 ++++++---- mods/ITEMS/mcl_fire/flint_and_steel.lua | 2 +- mods/ITEMS/mcl_flowers/init.lua | 9 +++++++++ mods/ITEMS/mcl_hoppers/init.lua | 8 +++++++- mods/ITEMS/mcl_potions/init.lua | 4 +++- mods/ITEMS/mcl_stairs/api.lua | 2 +- mods/ITEMS/mcl_throwing/throwable.lua | 2 +- mods/ITEMS/mcl_torches/init.lua | 1 + 13 files changed, 41 insertions(+), 12 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 79fe633f9..5883e4648 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -252,6 +252,9 @@ function mcl_util.generate_on_place_plant_function(condition) local place_pos local def_under = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name] local def_above = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name] + if not def_under or not def_above then + return itemstack + end if def_under.buildable_to then place_pos = pointed_thing.under elseif def_above.buildable_to then diff --git a/mods/ITEMS/REDSTONE/mesecons_button/init.lua b/mods/ITEMS/REDSTONE/mesecons_button/init.lua index 4c8997a2e..4db6b3750 100644 --- a/mods/ITEMS/REDSTONE/mesecons_button/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_button/init.lua @@ -52,6 +52,7 @@ local on_button_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under local node = minetest.get_node(under) local def = minetest.registered_nodes[node.name] + if not def then return end local groups = def.groups -- Check special rightclick action of pointed node diff --git a/mods/ITEMS/bucket/init.lua b/mods/ITEMS/bucket/init.lua index cd87ca6b4..d696b8754 100644 --- a/mods/ITEMS/bucket/init.lua +++ b/mods/ITEMS/bucket/init.lua @@ -103,7 +103,7 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name sound_place("mcl_core:water_source", pos) elseif item == "bucket:bucket_water" and nn == "mcl_cauldrons:cauldron_3" then sound_place("mcl_core:water_source", pos) - elseif minetest.registered_nodes[nn].buildable_to then + elseif minetest.registered_nodes[nn] and minetest.registered_nodes[nn].buildable_to then -- buildable; replace the node local pns = user:get_player_name() if minetest.is_protected(pointed_thing.under, pns) then @@ -117,7 +117,7 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name -- not buildable to; place the liquid above -- check if the node above can be replaced local abovenode = minetest.get_node(pointed_thing.above) - if minetest.registered_nodes[abovenode.name].buildable_to then + if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then local pn = user:get_player_name() if minetest.is_protected(pointed_thing.above, pn) then return itemstack diff --git a/mods/ITEMS/mcl_beds/api.lua b/mods/ITEMS/mcl_beds/api.lua index 6952ddac8..9e4c8e04a 100644 --- a/mods/ITEMS/mcl_beds/api.lua +++ b/mods/ITEMS/mcl_beds/api.lua @@ -78,7 +78,8 @@ function mcl_beds.register_bed(name, def) end local pos - if minetest.registered_items[minetest.get_node(under).name].buildable_to then + local undername = minetest.get_node(under).name + if minetest.registered_items[undername] and minetest.registered_items[undername].buildable_to then pos = under else pos = pointed_thing.above diff --git a/mods/ITEMS/mcl_core/nodes.lua b/mods/ITEMS/mcl_core/nodes.lua index 3e2f2e00e..3d709a488 100644 --- a/mods/ITEMS/mcl_core/nodes.lua +++ b/mods/ITEMS/mcl_core/nodes.lua @@ -1409,6 +1409,9 @@ minetest.register_node("mcl_core:ladder", { local under = pointed_thing.under local node = minetest.get_node(under) local def = minetest.registered_nodes[node.name] + if not def then + return itemstack + end local groups = def.groups -- Don't allow to place the ladder at particular nodes @@ -1483,6 +1486,7 @@ minetest.register_node("mcl_core:vine", { local under = pointed_thing.under local node = minetest.get_node(under) local def = minetest.registered_nodes[node.name] + if not def then return itemstack end local groups = def.groups -- Check special rightclick action of pointed node diff --git a/mods/ITEMS/mcl_doors/api_doors.lua b/mods/ITEMS/mcl_doors/api_doors.lua index 3ef6b4666..ca1b753bd 100644 --- a/mods/ITEMS/mcl_doors/api_doors.lua +++ b/mods/ITEMS/mcl_doors/api_doors.lua @@ -79,21 +79,23 @@ function mcl_doors:register_door(name, def) local ptu = pointed_thing.under local nu = minetest.get_node(ptu) -- Pointed thing's rightclick action takes precedence, unless player holds down the sneak key - if minetest.registered_nodes[nu.name].on_rightclick and not placer:get_player_control().sneak then + if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].on_rightclick and not placer:get_player_control().sneak then return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack) end local pt - if minetest.registered_nodes[minetest.get_node(ptu).name].buildable_to then + if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].buildable_to then pt = pointed_thing.under else pt = pointed_thing.above end local pt2 = {x=pt.x, y=pt.y, z=pt.z} pt2.y = pt2.y+1 + local ptname = minetest.get_node(pt).name + local pt2name = minetest.get_node(pt2).name if - (not minetest.registered_nodes[minetest.get_node(pt).name].buildable_to) or - (not minetest.registered_nodes[minetest.get_node(pt2).name].buildable_to) + (minetest.registered_nodes[ptname] and not minetest.registered_nodes[ptname].buildable_to) or + (minetest.registered_nodes[pt2name] and not minetest.registered_nodes[pt2name].buildable_to) then return itemstack end diff --git a/mods/ITEMS/mcl_fire/flint_and_steel.lua b/mods/ITEMS/mcl_fire/flint_and_steel.lua index eeee640e5..8cb37b8f9 100644 --- a/mods/ITEMS/mcl_fire/flint_and_steel.lua +++ b/mods/ITEMS/mcl_fire/flint_and_steel.lua @@ -16,7 +16,7 @@ minetest.register_tool("mcl_fire:flint_and_steel", { local used = false if pointed_thing.type == "node" then local nodedef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name] - if nodedef._on_ignite then + if nodedef and nodedef._on_ignite then nodedef._on_ignite(pointed_thing.under, user) else mcl_fire.set_fire(pointed_thing) diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index af77001a2..0b9f1a2d2 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -186,15 +186,24 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im -- Check for a floor and a space of 1×2×1 local ptu_node = minetest.get_node(pointed_thing.under) local bottom + if not minetest.registered_nodes[ptu_node.name] then + return itemstack + end if minetest.registered_nodes[ptu_node.name].buildable_to then bottom = pointed_thing.under else bottom = pointed_thing.above end + if not minetest.registered_nodes[minetest.get_node(bottom).name] then + return itemstack + end local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } local bottom_buildable = minetest.registered_nodes[minetest.get_node(bottom).name].buildable_to local top_buildable = minetest.registered_nodes[minetest.get_node(top).name].buildable_to local floorname = minetest.get_node({x=bottom.x, y=bottom.y-1, z=bottom.z}).name + if not minetest.registered_nodes[floorname] then + return itemstack + end local light_night = minetest.get_node_light(bottom, 0.0) local light_day = minetest.get_node_light(bottom, 0.5) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 1bd2dd973..b4a82d3ac 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -59,7 +59,7 @@ Hoppers interact with containers the following way: local uposnode = minetest.get_node(upos) local uposnodedef = minetest.registered_nodes[uposnode.name] - + if not uposnodedef then return itemstack end -- Use pointed node's on_rightclick function first, if present if placer and not placer:get_player_control().sneak then if uposnodedef and uposnodedef.on_rightclick then @@ -72,6 +72,7 @@ Hoppers interact with containers the following way: bpos = upos else local aposnodedef = minetest.registered_nodes[minetest.get_node(apos).name] + if not aposnodedef then return itemstack end if aposnodedef.buildable_to then bpos = apos end @@ -207,6 +208,7 @@ minetest.register_abm({ chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) local abovenode = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) + if not minetest.registered_items[abovenode.name] then return end -- Don't bother checking item enties if node above is a container (should save some CPU) if minetest.registered_items[abovenode.name].groups.container then return @@ -281,6 +283,7 @@ minetest.register_abm({ -- Suck an item from the container above into the hopper local upnode = minetest.get_node(uppos) + if not minetest.registered_nodes[upnode.name] then return end local g = minetest.registered_nodes[upnode.name].groups.container if g == 2 or g == 3 then -- Typical container inventory @@ -298,6 +301,7 @@ minetest.register_abm({ -- Move an item from the hopper into container below local downnode = minetest.get_node(downpos) + if not minetest.registered_nodes[downnode.name] then return end g = minetest.registered_nodes[downnode.name].groups.container local slot_id = -1 if g == 3 then @@ -338,9 +342,11 @@ minetest.register_abm({ local above = {x=pos.x,y=pos.y+1,z=pos.z} local frontnode = minetest.get_node(front) + if not minetest.registered_nodes[frontnode.name] then return end -- Suck an item from the container above into the hopper local abovenode = minetest.get_node(above) + if not minetest.registered_nodes[abovenode.name] then return end local g = minetest.registered_nodes[abovenode.name].groups.container if g == 2 or g == 3 then -- Typical container inventory diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index 6d2c272d1..f6a796f84 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -37,7 +37,9 @@ minetest.register_craftitem("mcl_potions:glass_bottle", { -- Try to fill glass bottle with water local get_water = false - if def.groups and def.groups.water and def.liquidtype == "source" then + if not def then + -- Unknown node: no-op + elseif def.groups and def.groups.water and def.liquidtype == "source" then -- Water source get_water = true -- Or reduce water level of cauldron by 1 diff --git a/mods/ITEMS/mcl_stairs/api.lua b/mods/ITEMS/mcl_stairs/api.lua index de8f0af33..cacf65dbc 100644 --- a/mods/ITEMS/mcl_stairs/api.lua +++ b/mods/ITEMS/mcl_stairs/api.lua @@ -158,7 +158,7 @@ function mcl_stairs.register_slab(subname, recipeitem, groups, images, descripti -- combine two slabs if possible -- Requirements: Same slab material, must be placed on top of lower slab, or on bottom of upper slab - if (wield_item == under.name or wield_item == minetest.registered_nodes[under.name]._mcl_other_slab_half) and + if (wield_item == under.name or (minetest.registered_nodes[under.name] and wield_item == minetest.registered_nodes[under.name]._mcl_other_slab_half)) and not ((dir.y >= 0 and minetest.get_item_group(under.name, "slab_top") == 1) or (dir.y <= 0 and minetest.get_item_group(under.name, "slab_top") == 0)) then diff --git a/mods/ITEMS/mcl_throwing/throwable.lua b/mods/ITEMS/mcl_throwing/throwable.lua index f1810748c..c589b15a6 100644 --- a/mods/ITEMS/mcl_throwing/throwable.lua +++ b/mods/ITEMS/mcl_throwing/throwable.lua @@ -243,7 +243,7 @@ local pearl_on_step = function(self, dtime) --[[ It may be possible that telepos is walkable due to the algorithm. Especially when the ender pearl is faster horizontally than vertical. This applies final fixing, just to be sure we're not in a walkable node ]] - if minetest.registered_nodes[telenode.name].walkable then + if not minetest.registered_nodes[telenode.name] or minetest.registered_nodes[telenode.name].walkable then if v.y < 0 then telepos.y = telepos.y + 0.5 else diff --git a/mods/ITEMS/mcl_torches/init.lua b/mods/ITEMS/mcl_torches/init.lua index 6723203e7..742cc0c0b 100644 --- a/mods/ITEMS/mcl_torches/init.lua +++ b/mods/ITEMS/mcl_torches/init.lua @@ -54,6 +54,7 @@ mcl_torches.register_torch = function(substring, description, doc_items_longdesc local under = pointed_thing.under local node = minetest.get_node(under) local def = minetest.registered_nodes[node.name] + if not def then return itemstack end -- Call on_rightclick if the pointed node defines it if placer and not placer:get_player_control().sneak then