Boats: Prevent entering 'ignore' nodes
authorparamat <paramat@users.noreply.github.com>
Fri, 9 Feb 2018 04:52:54 +0000 (04:52 +0000)
committerparamat <mat.gregory@virginmedia.com>
Sat, 17 Feb 2018 09:37:22 +0000 (09:37 +0000)
At world edge make boat bounce back into world by inverting speed.
At world base avoid falling into ignore by setting y velocity to 0.

mods/boats/init.lua

index 72ca478f8dc6a61a9e63023b9c0898f7daf58ddf..9e4e5b3024f90855bbb53c597b923dab68d386ef 100644 (file)
@@ -172,15 +172,23 @@ function boat.on_step(self, dtime)
        local new_velo
        local new_acce = {x = 0, y = 0, z = 0}
        if not is_water(p) then
-               local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
-               if (not nodedef) or nodedef.walkable then
+               local nodename = minetest.get_node(p).name
+               local nodedef = minetest.registered_nodes[nodename]
+               if nodename == "ignore" then
+                       -- at world edge bounce boat back into world
+                       self.v = -self.v
+                       -- at world base avoid falling into ignore
+                       new_velo = get_velocity(self.v, self.object:getyaw(), 0)
+               elseif (not nodedef) or nodedef.walkable then
                        self.v = 0
                        new_acce = {x = 0, y = 1, z = 0}
+                       new_velo = get_velocity(self.v, self.object:getyaw(),
+                               self.object:getvelocity().y)
                else
                        new_acce = {x = 0, y = -9.8, z = 0}
+                       new_velo = get_velocity(self.v, self.object:getyaw(),
+                               self.object:getvelocity().y)
                end
-               new_velo = get_velocity(self.v, self.object:getyaw(),
-                       self.object:getvelocity().y)
                self.object:setpos(self.object:getpos())
        else
                p.y = p.y + 1