4 local init
= os
.clock()
6 local function is_water(pos
)
7 local nn
= minetest
.get_node(pos
).name
8 return minetest
.get_item_group(nn
, "water") ~= 0
11 local function get_velocity(v
, yaw
, y
)
12 local x
= -math
.sin(yaw
)*v
13 local z
= math
.cos(yaw
)*v
14 return {x
=x
, y
=y
, z
=z
}
22 collisionbox
= {-1,-0.5,-1, 1,0.5,1},
25 textures
= {"boat_texture.png"},
32 function boat
.on_rightclick(self
, clicker
)
33 if not clicker
or not clicker
:is_player() then
36 if self
.driver
and clicker
== self
.driver
then
39 elseif not self
.driver
then
41 clicker
:set_attach(self
.object
, "", {x
=0,y
=5,z
=0}, {x
=0,y
=0,z
=0})
42 self
.object
:setyaw(clicker
:get_look_yaw())
46 function boat
.on_activate(self
, staticdata
, dtime_s
)
47 self
.object
:set_armor_groups({immortal
=1})
49 self
.v
= tonumber(staticdata
)
53 function boat
.get_staticdata()
57 function boat
.on_punch(self
, puncher
, time_from_last_punch
, tool_capabilities
, direction
)
60 self
.driver
:set_detach()
62 boat
.schedule_removal(self
)
63 if not minetest
.setting_getbool("creative_mode") then
64 puncher
:get_inventory():add_item("main", "boat:boat")
68 boat
.schedule_removal(self
)
69 if not minetest
.setting_getbool("creative_mode") then
70 puncher
:get_inventory():add_item("main", "boat:boat")
76 function boat
.on_step(self
, dtime
)
78 self
.stepcount
=self
.stepcount
+1
79 if self
.stepcount
>9 then
84 local ctrl
= self
.driver
:get_player_control()
88 local yaw
= self
.object
:getyaw()
90 if ctrl
.up
and self
.v
<3 then
94 if ctrl
.down
and self
.v
>=-1 then
100 self
.object
:setyaw(yaw
-math
.pi
/12-dtime
*math
.pi
/12)
102 self
.object
:setyaw(yaw
+math
.pi
/12+dtime
*math
.pi
/12)
107 self
.object
:setyaw(yaw
+math
.pi
/12+dtime
*math
.pi
/12)
109 self
.object
:setyaw(yaw
-math
.pi
/12-dtime
*math
.pi
/12)
114 local tmp_velocity
= get_velocity(self
.v
, self
.object
:getyaw(), 0)
116 local tmp_pos
= self
.object
:getpos()
120 if is_water(tmp_pos
) then
124 tmp_pos
.y
=tmp_pos
.y
-0.5
126 if minetest
.get_node(tmp_pos
).name
=="air" then
130 self
.object
:setvelocity(tmp_velocity
)
136 function boat
.schedule_removal(self
)
138 minetest
.after(0.25,function()
145 minetest
.register_entity("boat:boat", boat
)
147 minetest
.register_craftitem("boat:boat", {
148 description
= "Boat",
149 inventory_image
= "boat_inventory.png",
150 liquids_pointable
= true,
152 on_place
= function(itemstack
, placer
, pointed_thing
)
153 if pointed_thing
.type ~= "node" then
156 if not is_water(pointed_thing
.under
) then
159 pointed_thing
.under
.y
= pointed_thing
.under
.y
+0.5
160 minetest
.add_entity(pointed_thing
.under
, "boat:boat")
161 if not minetest
.setting_getbool("creative_mode") then
162 itemstack
:take_item()
168 minetest
.register_craft({
169 output
= "boat:boat",
173 {"default:wood", "", ""},
177 local time_to_load
= os
.clock() - init
178 print(string.format("[MOD] "..minetest
.get_current_modname().." loaded in %.4f s", time_to_load
))