Skip to content
This repository was archived by the owner on Dec 14, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 06ef070

Browse files
committedJul 1, 2014
Update only moving boats
1 parent f4594af commit 06ef070

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed
 

Diff for: ‎mods/boats/init.lua

+28-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
--
55

66
local function is_water(pos)
7-
local nn = minetest.env:get_node(pos).name
7+
local nn = minetest.get_node(pos).name
88
return minetest.get_item_group(nn, "water") ~= 0
99
end
1010

@@ -39,6 +39,7 @@ local boat = {
3939

4040
driver = nil,
4141
v = 0,
42+
last_v = 0,
4243
}
4344

4445
function boat:on_rightclick(clicker)
@@ -67,6 +68,7 @@ function boat:on_activate(staticdata, dtime_s)
6768
if staticdata then
6869
self.v = tonumber(staticdata)
6970
end
71+
self.last_v = self.v
7072
end
7173

7274
function boat:get_staticdata()
@@ -75,7 +77,7 @@ end
7577

7678
function boat:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
7779
self.object:remove()
78-
if puncher and puncher:is_player() then
80+
if puncher and puncher:is_player() and not minetest.setting_getbool("creative_mode") then
7981
puncher:get_inventory():add_item("main", "boats:boat")
8082
end
8183
end
@@ -84,6 +86,7 @@ function boat:on_step(dtime)
8486
self.v = get_v(self.object:getvelocity())*get_sign(self.v)
8587
if self.driver then
8688
local ctrl = self.driver:get_player_control()
89+
local yaw = self.object:getyaw()
8790
if ctrl.up then
8891
self.v = self.v+0.1
8992
end
@@ -92,19 +95,23 @@ function boat:on_step(dtime)
9295
end
9396
if ctrl.left then
9497
if ctrl.down then
95-
self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
98+
self.object:setyaw(yaw-math.pi/120-dtime*math.pi/120)
9699
else
97-
self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
100+
self.object:setyaw(yaw+math.pi/120+dtime*math.pi/120)
98101
end
99102
end
100103
if ctrl.right then
101104
if ctrl.down then
102-
self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
105+
self.object:setyaw(yaw+math.pi/120+dtime*math.pi/120)
103106
else
104-
self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
107+
self.object:setyaw(yaw-math.pi/120-dtime*math.pi/120)
105108
end
106109
end
107110
end
111+
local velo = self.object:getvelocity()
112+
if self.v == 0 and velo.x == 0 and velo.z == 0 then
113+
return
114+
end
108115
local s = get_sign(self.v)
109116
self.v = self.v - 0.02*s
110117
if s ~= get_sign(self.v) then
@@ -118,36 +125,40 @@ function boat:on_step(dtime)
118125

119126
local p = self.object:getpos()
120127
p.y = p.y-0.5
128+
local new_velo = {x=0,y=0,z=0}
129+
local new_acce = {x=0,y=0,z=0}
121130
if not is_water(p) then
122131
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
123132
self.v = 0
124133
end
125-
self.object:setacceleration({x=0, y=-10, z=0})
126-
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
134+
new_acce = {x=0, y=-10, z=0}
135+
new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
127136
else
128137
p.y = p.y+1
129138
if is_water(p) then
130-
self.object:setacceleration({x=0, y=3, z=0})
139+
new_acce = {x=0, y=3, z=0}
131140
local y = self.object:getvelocity().y
132141
if y > 2 then
133142
y = 2
134143
end
135144
if y < 0 then
136145
self.object:setacceleration({x=0, y=10, z=0})
137146
end
138-
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), y))
147+
new_velo = get_velocity(self.v, self.object:getyaw(), y)
139148
else
140-
self.object:setacceleration({x=0, y=0, z=0})
149+
new_acce = {x=0, y=0, z=0}
141150
if math.abs(self.object:getvelocity().y) < 1 then
142151
local pos = self.object:getpos()
143152
pos.y = math.floor(pos.y)+0.5
144153
self.object:setpos(pos)
145-
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
154+
new_velo = get_velocity(self.v, self.object:getyaw(), 0)
146155
else
147-
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
156+
new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
148157
end
149158
end
150159
end
160+
self.object:setvelocity(new_velo)
161+
self.object:setacceleration(new_acce)
151162
end
152163

153164
minetest.register_entity("boats:boat", boat)
@@ -168,8 +179,10 @@ minetest.register_craftitem("boats:boat", {
168179
return
169180
end
170181
pointed_thing.under.y = pointed_thing.under.y+0.5
171-
minetest.env:add_entity(pointed_thing.under, "boats:boat")
172-
itemstack:take_item()
182+
minetest.add_entity(pointed_thing.under, "boats:boat")
183+
if not minetest.setting_getbool("creative_mode") then
184+
itemstack:take_item()
185+
end
173186
return itemstack
174187
end,
175188
})

0 commit comments

Comments
 (0)
This repository has been archived.