1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-22 15:00:18 +01:00

Update only moving boats

This commit is contained in:
BlockMen 2014-07-01 14:25:43 +02:00
parent 7ea81f0906
commit e0673908bf

View File

@ -4,7 +4,7 @@
--
local function is_water(pos)
local nn = minetest.env:get_node(pos).name
local nn = minetest.get_node(pos).name
return minetest.get_item_group(nn, "water") ~= 0
end
@ -39,6 +39,7 @@ local boat = {
driver = nil,
v = 0,
last_v = 0,
}
function boat:on_rightclick(clicker)
@ -67,6 +68,7 @@ function boat:on_activate(staticdata, dtime_s)
if staticdata then
self.v = tonumber(staticdata)
end
self.last_v = self.v
end
function boat:get_staticdata()
@ -75,7 +77,7 @@ end
function boat:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove()
if puncher and puncher:is_player() then
if puncher and puncher:is_player() and not minetest.setting_getbool("creative_mode") then
puncher:get_inventory():add_item("main", "boats:boat")
end
end
@ -84,6 +86,7 @@ function boat:on_step(dtime)
self.v = get_v(self.object:getvelocity())*get_sign(self.v)
if self.driver then
local ctrl = self.driver:get_player_control()
local yaw = self.object:getyaw()
if ctrl.up then
self.v = self.v+0.1
end
@ -92,19 +95,23 @@ function boat:on_step(dtime)
end
if ctrl.left then
if ctrl.down then
self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
self.object:setyaw(yaw-math.pi/120-dtime*math.pi/120)
else
self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
self.object:setyaw(yaw+math.pi/120+dtime*math.pi/120)
end
end
if ctrl.right then
if ctrl.down then
self.object:setyaw(self.object:getyaw()+math.pi/120+dtime*math.pi/120)
self.object:setyaw(yaw+math.pi/120+dtime*math.pi/120)
else
self.object:setyaw(self.object:getyaw()-math.pi/120-dtime*math.pi/120)
self.object:setyaw(yaw-math.pi/120-dtime*math.pi/120)
end
end
end
local velo = self.object:getvelocity()
if self.v == 0 and velo.x == 0 and velo.z == 0 then
return
end
local s = get_sign(self.v)
self.v = self.v - 0.02*s
if s ~= get_sign(self.v) then
@ -118,16 +125,18 @@ function boat:on_step(dtime)
local p = self.object:getpos()
p.y = p.y-0.5
local new_velo = {x=0,y=0,z=0}
local new_acce = {x=0,y=0,z=0}
if not is_water(p) then
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
self.v = 0
end
self.object:setacceleration({x=0, y=-10, z=0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
new_acce = {x=0, y=-10, z=0}
new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
else
p.y = p.y+1
if is_water(p) then
self.object:setacceleration({x=0, y=3, z=0})
new_acce = {x=0, y=3, z=0}
local y = self.object:getvelocity().y
if y > 2 then
y = 2
@ -135,19 +144,21 @@ function boat:on_step(dtime)
if y < 0 then
self.object:setacceleration({x=0, y=10, z=0})
end
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), y))
new_velo = get_velocity(self.v, self.object:getyaw(), y)
else
self.object:setacceleration({x=0, y=0, z=0})
new_acce = {x=0, y=0, z=0}
if math.abs(self.object:getvelocity().y) < 1 then
local pos = self.object:getpos()
pos.y = math.floor(pos.y)+0.5
self.object:setpos(pos)
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
new_velo = get_velocity(self.v, self.object:getyaw(), 0)
else
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
new_velo = get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)
end
end
end
self.object:setvelocity(new_velo)
self.object:setacceleration(new_acce)
end
minetest.register_entity("boats:boat", boat)
@ -168,8 +179,10 @@ minetest.register_craftitem("boats:boat", {
return
end
pointed_thing.under.y = pointed_thing.under.y+0.5
minetest.env:add_entity(pointed_thing.under, "boats:boat")
itemstack:take_item()
minetest.add_entity(pointed_thing.under, "boats:boat")
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
})