-
--
-- Helper functions
--
return minetest.get_item_group(nn, "water") ~= 0
end
+
local function get_sign(i)
if i == 0 then
return 0
end
end
+
local function get_velocity(v, yaw, y)
local x = -math.sin(yaw) * v
local z = math.cos(yaw) * v
return {x = x, y = y, z = z}
end
+
local function get_v(v)
return math.sqrt(v.x ^ 2 + v.z ^ 2)
end
local boat = {
physical = true,
- collisionbox = {-0.5, -0.4, -0.5, 0.5, 0.3, 0.5},
+ collisionbox = {-0.5, -0.35, -0.5, 0.5, 0.3, 0.5},
visual = "mesh",
mesh = "boat.obj",
textures = {"default_wood.png"},
removed = false
}
+
function boat.on_rightclick(self, clicker)
if not clicker or not clicker:is_player() then
return
clicker:set_detach()
default.player_attached[name] = false
default.player_set_animation(clicker, "stand" , 30)
+ local pos = clicker:getpos()
+ pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
+ minetest.after(0.1, function()
+ clicker:setpos(pos)
+ end)
elseif not self.driver then
self.driver = clicker
- clicker:set_attach(self.object, "", {x = 0, y = 11, z = -3}, {x = 0, y = 0, z = 0})
+ clicker:set_attach(self.object, "",
+ {x = 0, y = 11, z = -3}, {x = 0, y = 0, z = 0})
default.player_attached[name] = true
minetest.after(0.2, function()
default.player_set_animation(clicker, "sit" , 30)
end
end
+
function boat.on_activate(self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
if staticdata then
self.last_v = self.v
end
+
function boat.get_staticdata(self)
return tostring(self.v)
end
-function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction)
+
+function boat.on_punch(self, puncher, time_from_last_punch,
+ tool_capabilities, direction)
if not puncher or not puncher:is_player() or self.removed then
return
end
end
end
+
function boat.on_step(self, dtime)
self.v = get_v(self.object:getvelocity()) * get_sign(self.v)
if self.driver then
else
new_acce = {x = 0, y = -9.8, z = 0}
end
- new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
+ 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
self.object:setpos(pos)
new_velo = get_velocity(self.v, self.object:getyaw(), 0)
else
- new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
+ new_velo = get_velocity(self.v, self.object:getyaw(),
+ self.object:getvelocity().y)
self.object:setpos(self.object:getpos())
end
end
self.object:setacceleration(new_acce)
end
+
minetest.register_entity("boats:boat", boat)
+
minetest.register_craftitem("boats:boat", {
description = "Boat",
inventory_image = "boat_inventory.png",
end,
})
+
minetest.register_craft({
output = "boats:boat",
recipe = {
{"group:wood", "group:wood", "group:wood"},
},
})
-