Boats: Avoid crash if boat pos over limit 0.4.15
authorparamat <mat.gregory@virginmedia.com>
Wed, 21 Dec 2016 07:38:27 +0000 (07:38 +0000)
committerparamat <mat.gregory@virginmedia.com>
Wed, 21 Dec 2016 13:42:23 +0000 (13:42 +0000)
If the boat pos is over limit, 'add entity' will not add an entity,
causing 'boat' to be nil.

mods/boats/init.lua

index 9f1264b12d204ea41369ad643baafbca75e0d2fa..0591ef24f692eb827c5e688983edabd352ab7af0 100644 (file)
@@ -233,9 +233,11 @@ minetest.register_craftitem("boats:boat", {
                end
                pointed_thing.under.y = pointed_thing.under.y + 0.5
                boat = minetest.add_entity(pointed_thing.under, "boats:boat")
-               boat:setyaw(placer:get_look_horizontal())
-               if not minetest.setting_getbool("creative_mode") then
-                       itemstack:take_item()
+               if boat then
+                       boat:setyaw(placer:get_look_horizontal())
+                       if not minetest.setting_getbool("creative_mode") then
+                               itemstack:take_item()
+                       end
                end
                return itemstack
        end,