Allow only boat driver to be detached from boat (fixes #276)
authorBlockMen <nmuelll@web.de>
Fri, 3 Oct 2014 01:20:31 +0000 (03:20 +0200)
committerBlockMen <nmuelll@web.de>
Fri, 3 Oct 2014 01:20:31 +0000 (03:20 +0200)
mods/boats/init.lua

index 121269886c082d7fd545c17107765fcefe4f5b74..0c6572070cbbc73280d62af6aea042ed8e8d16ef 100644 (file)
@@ -80,16 +80,20 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d
        if not puncher or not puncher:is_player() or self.removed then
                return
        end
-       puncher:set_detach()
-       default.player_attached[puncher:get_player_name()] = false
-
-       self.removed = true
-       -- delay remove to ensure player is detached
-       minetest.after(0.1, function()
-               self.object:remove()
-       end)
-       if not minetest.setting_getbool("creative_mode") then
-               puncher:get_inventory():add_item("main", "boats:boat")
+       if self.driver and puncher == self.driver then
+               self.driver = nil
+               puncher:set_detach()
+               default.player_attached[puncher:get_player_name()] = false
+       end
+       if not self.driver then
+               self.removed = true
+               -- delay remove to ensure player is detached
+               minetest.after(0.1, function()
+                       self.object:remove()
+               end)
+               if not minetest.setting_getbool("creative_mode") then
+                       puncher:get_inventory():add_item("main", "boats:boat")
+               end
        end
 end