@@ -12,18 +12,18 @@ local function get_sign(i)
12
12
if i == 0 then
13
13
return 0
14
14
else
15
- return i / math.abs (i )
15
+ return i / math.abs (i )
16
16
end
17
17
end
18
18
19
19
local function get_velocity (v , yaw , y )
20
- local x = - math.sin (yaw )* v
21
- local z = math.cos (yaw )* v
22
- return {x = x , y = y , z = z }
20
+ local x = - math.sin (yaw ) * v
21
+ local z = math.cos (yaw ) * v
22
+ return {x = x , y = y , z = z }
23
23
end
24
24
25
25
local function get_v (v )
26
- return math.sqrt (v .x ^ 2 + v .z ^ 2 )
26
+ return math.sqrt (v .x ^ 2 + v .z ^ 2 )
27
27
end
28
28
29
29
--
32
32
33
33
local boat = {
34
34
physical = true ,
35
- collisionbox = {- 0.6 ,- 0.4 ,- 0.6 , 0.6 ,0.3 ,0.6 },
35
+ collisionbox = {- 0.6 , - 0.4 , - 0.6 , 0.6 , 0.3 , 0.6 },
36
36
visual = " mesh" ,
37
37
mesh = " boat.x" ,
38
38
textures = {" default_wood.png" },
@@ -55,25 +55,25 @@ function boat.on_rightclick(self, clicker)
55
55
default .player_set_animation (clicker , " stand" , 30 )
56
56
elseif not self .driver then
57
57
self .driver = clicker
58
- clicker :set_attach (self .object , " " , {x = 0 , y = 11 ,z = -3 }, {x = 0 , y = 0 , z = 0 })
58
+ clicker :set_attach (self .object , " " , {x = 0 , y = 11 , z = - 3 }, {x = 0 , y = 0 , z = 0 })
59
59
default .player_attached [name ] = true
60
60
minetest .after (0.2 , function ()
61
61
default .player_set_animation (clicker , " sit" , 30 )
62
62
end )
63
- self .object :setyaw (clicker :get_look_yaw ()- math.pi / 2 )
63
+ self .object :setyaw (clicker :get_look_yaw () - math.pi / 2 )
64
64
end
65
65
end
66
66
67
67
function boat .on_activate (self , staticdata , dtime_s )
68
- self .object :set_armor_groups ({immortal = 1 })
68
+ self .object :set_armor_groups ({immortal = 1 })
69
69
if staticdata then
70
70
self .v = tonumber (staticdata )
71
71
end
72
72
self .last_v = self .v
73
73
end
74
74
75
- function boat .get_staticdata ()
76
- return tostring (v )
75
+ function boat .get_staticdata (self )
76
+ return tostring (self . v )
77
77
end
78
78
79
79
function boat .on_punch (self , puncher , time_from_last_punch , tool_capabilities , direction )
@@ -85,7 +85,7 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d
85
85
86
86
self .removed = true
87
87
-- delay remove to ensure player is detached
88
- minetest .after (0.1 ,function ()
88
+ minetest .after (0.1 , function ()
89
89
self .object :remove ()
90
90
end )
91
91
if not minetest .setting_getbool (" creative_mode" ) then
@@ -94,28 +94,28 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d
94
94
end
95
95
96
96
function boat .on_step (self , dtime )
97
- self .v = get_v (self .object :getvelocity ())* get_sign (self .v )
97
+ self .v = get_v (self .object :getvelocity ()) * get_sign (self .v )
98
98
if self .driver then
99
99
local ctrl = self .driver :get_player_control ()
100
100
local yaw = self .object :getyaw ()
101
101
if ctrl .up then
102
- self .v = self .v + 0.1
102
+ self .v = self .v + 0.1
103
103
end
104
104
if ctrl .down then
105
- self .v = self .v - 0.08
105
+ self .v = self .v - 0.08
106
106
end
107
107
if ctrl .left then
108
108
if ctrl .down then
109
- self .object :setyaw (yaw - math.pi / 120 - dtime * math.pi / 120 )
109
+ self .object :setyaw (yaw - math.pi / 120 - dtime * math.pi / 120 )
110
110
else
111
- self .object :setyaw (yaw + math.pi / 120 + dtime * math.pi / 120 )
111
+ self .object :setyaw (yaw + math.pi / 120 + dtime * math.pi / 120 )
112
112
end
113
113
end
114
114
if ctrl .right then
115
115
if ctrl .down then
116
- self .object :setyaw (yaw + math.pi / 120 + dtime * math.pi / 120 )
116
+ self .object :setyaw (yaw + math.pi / 120 + dtime * math.pi / 120 )
117
117
else
118
- self .object :setyaw (yaw - math.pi / 120 - dtime * math.pi / 120 )
118
+ self .object :setyaw (yaw - math.pi / 120 - dtime * math.pi / 120 )
119
119
end
120
120
end
121
121
end
@@ -124,43 +124,44 @@ function boat.on_step(self, dtime)
124
124
return
125
125
end
126
126
local s = get_sign (self .v )
127
- self .v = self .v - 0.02 * s
127
+ self .v = self .v - 0.02 * s
128
128
if s ~= get_sign (self .v ) then
129
- self .object :setvelocity ({x = 0 , y = 0 , z = 0 })
129
+ self .object :setvelocity ({x = 0 , y = 0 , z = 0 })
130
130
self .v = 0
131
131
return
132
132
end
133
133
if math.abs (self .v ) > 4.5 then
134
- self .v = 4.5 * get_sign (self .v )
134
+ self .v = 4.5 * get_sign (self .v )
135
135
end
136
136
137
137
local p = self .object :getpos ()
138
- p .y = p .y - 0.5
139
- local new_velo = {x = 0 , y = 0 , z = 0 }
140
- local new_acce = {x = 0 , y = 0 , z = 0 }
138
+ p .y = p .y - 0.5
139
+ local new_velo = {x = 0 , y = 0 , z = 0 }
140
+ local new_acce = {x = 0 , y = 0 , z = 0 }
141
141
if not is_water (p ) then
142
- if minetest .registered_nodes [minetest .env :get_node (p ).name ].walkable then
142
+ local nodedef = minetest .registered_nodes [minetest .get_node (p ).name ]
143
+ if (not nodedef ) or nodedef .walkable then
143
144
self .v = 0
144
145
end
145
- new_acce = {x = 0 , y = -10 , z = 0 }
146
+ new_acce = {x = 0 , y = - 10 , z = 0 }
146
147
new_velo = get_velocity (self .v , self .object :getyaw (), self .object :getvelocity ().y )
147
148
else
148
- p .y = p .y + 1
149
+ p .y = p .y + 1
149
150
if is_water (p ) then
150
- new_acce = {x = 0 , y = 3 , z = 0 }
151
+ new_acce = {x = 0 , y = 3 , z = 0 }
151
152
local y = self .object :getvelocity ().y
152
153
if y > 2 then
153
154
y = 2
154
155
end
155
156
if y < 0 then
156
- self .object :setacceleration ({x = 0 , y = 10 , z = 0 })
157
+ self .object :setacceleration ({x = 0 , y = 10 , z = 0 })
157
158
end
158
159
new_velo = get_velocity (self .v , self .object :getyaw (), y )
159
160
else
160
- new_acce = {x = 0 , y = 0 , z = 0 }
161
+ new_acce = {x = 0 , y = 0 , z = 0 }
161
162
if math.abs (self .object :getvelocity ().y ) < 1 then
162
163
local pos = self .object :getpos ()
163
- pos .y = math.floor (pos .y )+ 0.5
164
+ pos .y = math.floor (pos .y ) + 0.5
164
165
self .object :setpos (pos )
165
166
new_velo = get_velocity (self .v , self .object :getyaw (), 0 )
166
167
else
@@ -179,7 +180,7 @@ minetest.register_craftitem("boats:boat", {
179
180
description = " Boat" ,
180
181
inventory_image = " boat_inventory.png" ,
181
182
wield_image = " boat_wield.png" ,
182
- wield_scale = {x = 2 , y = 2 , z = 1 },
183
+ wield_scale = {x = 2 , y = 2 , z = 1 },
183
184
liquids_pointable = true ,
184
185
185
186
on_place = function (itemstack , placer , pointed_thing )
@@ -189,7 +190,7 @@ minetest.register_craftitem("boats:boat", {
189
190
if not is_water (pointed_thing .under ) then
190
191
return
191
192
end
192
- pointed_thing .under .y = pointed_thing .under .y + 0.5
193
+ pointed_thing .under .y = pointed_thing .under .y + 0.5
193
194
minetest .add_entity (pointed_thing .under , " boats:boat" )
194
195
if not minetest .setting_getbool (" creative_mode" ) then
195
196
itemstack :take_item ()
@@ -201,8 +202,8 @@ minetest.register_craftitem("boats:boat", {
201
202
minetest .register_craft ({
202
203
output = " boats:boat" ,
203
204
recipe = {
204
- {" " , " " , " " },
205
- {" group:wood" , " " , " group:wood" },
205
+ {" " , " " , " " },
206
+ {" group:wood" , " " , " group:wood" },
206
207
{" group:wood" , " group:wood" , " group:wood" },
207
208
},
208
209
})
0 commit comments