1
-
2
1
--
3
2
-- Helper functions
4
3
--
@@ -8,6 +7,7 @@ local function is_water(pos)
8
7
return minetest .get_item_group (nn , " water" ) ~= 0
9
8
end
10
9
10
+
11
11
local function get_sign (i )
12
12
if i == 0 then
13
13
return 0
@@ -16,12 +16,14 @@ local function get_sign(i)
16
16
end
17
17
end
18
18
19
+
19
20
local function get_velocity (v , yaw , y )
20
21
local x = - math.sin (yaw ) * v
21
22
local z = math.cos (yaw ) * v
22
23
return {x = x , y = y , z = z }
23
24
end
24
25
26
+
25
27
local function get_v (v )
26
28
return math.sqrt (v .x ^ 2 + v .z ^ 2 )
27
29
end
32
34
33
35
local boat = {
34
36
physical = true ,
35
- collisionbox = {- 0.5 , - 0.4 , - 0.5 , 0.5 , 0.3 , 0.5 },
37
+ collisionbox = {- 0.5 , - 0.35 , - 0.5 , 0.5 , 0.3 , 0.5 },
36
38
visual = " mesh" ,
37
39
mesh = " boat.obj" ,
38
40
textures = {" default_wood.png" },
@@ -43,6 +45,7 @@ local boat = {
43
45
removed = false
44
46
}
45
47
48
+
46
49
function boat .on_rightclick (self , clicker )
47
50
if not clicker or not clicker :is_player () then
48
51
return
@@ -53,9 +56,15 @@ function boat.on_rightclick(self, clicker)
53
56
clicker :set_detach ()
54
57
default .player_attached [name ] = false
55
58
default .player_set_animation (clicker , " stand" , 30 )
59
+ local pos = clicker :getpos ()
60
+ pos = {x = pos .x , y = pos .y + 0.2 , z = pos .z }
61
+ minetest .after (0.1 , function ()
62
+ clicker :setpos (pos )
63
+ end )
56
64
elseif not self .driver then
57
65
self .driver = clicker
58
- clicker :set_attach (self .object , " " , {x = 0 , y = 11 , z = - 3 }, {x = 0 , y = 0 , z = 0 })
66
+ clicker :set_attach (self .object , " " ,
67
+ {x = 0 , y = 11 , z = - 3 }, {x = 0 , y = 0 , z = 0 })
59
68
default .player_attached [name ] = true
60
69
minetest .after (0.2 , function ()
61
70
default .player_set_animation (clicker , " sit" , 30 )
@@ -64,6 +73,7 @@ function boat.on_rightclick(self, clicker)
64
73
end
65
74
end
66
75
76
+
67
77
function boat .on_activate (self , staticdata , dtime_s )
68
78
self .object :set_armor_groups ({immortal = 1 })
69
79
if staticdata then
@@ -72,11 +82,14 @@ function boat.on_activate(self, staticdata, dtime_s)
72
82
self .last_v = self .v
73
83
end
74
84
85
+
75
86
function boat .get_staticdata (self )
76
87
return tostring (self .v )
77
88
end
78
89
79
- function boat .on_punch (self , puncher , time_from_last_punch , tool_capabilities , direction )
90
+
91
+ function boat .on_punch (self , puncher , time_from_last_punch ,
92
+ tool_capabilities , direction )
80
93
if not puncher or not puncher :is_player () or self .removed then
81
94
return
82
95
end
@@ -97,6 +110,7 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d
97
110
end
98
111
end
99
112
113
+
100
114
function boat .on_step (self , dtime )
101
115
self .v = get_v (self .object :getvelocity ()) * get_sign (self .v )
102
116
if self .driver then
@@ -149,7 +163,8 @@ function boat.on_step(self, dtime)
149
163
else
150
164
new_acce = {x = 0 , y = - 9.8 , z = 0 }
151
165
end
152
- new_velo = get_velocity (self .v , self .object :getyaw (), self .object :getvelocity ().y )
166
+ new_velo = get_velocity (self .v , self .object :getyaw (),
167
+ self .object :getvelocity ().y )
153
168
self .object :setpos (self .object :getpos ())
154
169
else
155
170
p .y = p .y + 1
@@ -172,7 +187,8 @@ function boat.on_step(self, dtime)
172
187
self .object :setpos (pos )
173
188
new_velo = get_velocity (self .v , self .object :getyaw (), 0 )
174
189
else
175
- new_velo = get_velocity (self .v , self .object :getyaw (), self .object :getvelocity ().y )
190
+ new_velo = get_velocity (self .v , self .object :getyaw (),
191
+ self .object :getvelocity ().y )
176
192
self .object :setpos (self .object :getpos ())
177
193
end
178
194
end
@@ -181,8 +197,10 @@ function boat.on_step(self, dtime)
181
197
self .object :setacceleration (new_acce )
182
198
end
183
199
200
+
184
201
minetest .register_entity (" boats:boat" , boat )
185
202
203
+
186
204
minetest .register_craftitem (" boats:boat" , {
187
205
description = " Boat" ,
188
206
inventory_image = " boat_inventory.png" ,
@@ -206,6 +224,7 @@ minetest.register_craftitem("boats:boat", {
206
224
end ,
207
225
})
208
226
227
+
209
228
minetest .register_craft ({
210
229
output = " boats:boat" ,
211
230
recipe = {
@@ -214,4 +233,3 @@ minetest.register_craft({
214
233
{" group:wood" , " group:wood" , " group:wood" },
215
234
},
216
235
})
217
-
0 commit comments