summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstujones11 <stujones111@gmail.com>2016-01-29 19:56:16 +0000
committerstujones11 <stujones111@gmail.com>2016-01-29 20:11:53 +0000
commit99f5ffddfb603068249d1ac0b9682d8531213842 (patch)
treed2fe5d1da0c4a2661551b7abfaefd58fcf2e7065
parent7c967dc6de05975a933576ccf82dbabfd7cb3eb7 (diff)
Prevent carts from travelling through nodes
-rw-r--r--railcart/railcart.lua18
-rw-r--r--railtrack/railtrack.lua2
2 files changed, 14 insertions, 6 deletions
diff --git a/railcart/railcart.lua b/railcart/railcart.lua
index 8f89649..6a3a22b 100644
--- a/railcart/railcart.lua
+++ b/railcart/railcart.lua
@@ -135,6 +135,9 @@ function railcart:get_rail_direction(pos)
end
end
if target then
+ if #cons == 1 then
+ target.y = pos.y
+ end
return railtrack:get_direction(target, pos)
end
return {x=0, y=0, z=0}
@@ -283,11 +286,7 @@ function railcart:update(cart, time, object)
end
local speed = railcart:velocity_to_speed(cart.vel)
if cart.target then
- if vector.equals(cart.target, cart.pos) then
- cart.dir = railcart:get_rail_direction(cart.pos)
- else
- cart.dir = railtrack:get_direction(cart.target, cart.pos)
- end
+ cart.dir = railtrack:get_direction(cart.target, cart.pos)
else
speed = 0
end
@@ -300,6 +299,14 @@ function railcart:update(cart, time, object)
blocked = true
end
end
+ local p1 = vector.add(cart.pos, {x=0, y=1, z=0})
+ local p2 = vector.add(cart.target, {x=0, y=1, z=0})
+ local los, bp = minetest.line_of_sight(p1, p2)
+ if los == false then
+ bp.y = bp.y - 1
+ cart.target = vector.subtract(bp, cart.dir)
+ blocked = true
+ end
local d1 = railtrack:get_distance(cart.prev, cart.target)
local d2 = railtrack:get_distance(cart.prev, cart.pos)
local dist = d1 - d2
@@ -344,6 +351,7 @@ function railcart:update(cart, time, object)
end
end
else
+ cart.dir = railcart:get_rail_direction(cart.pos)
cart.vel = {x=0, y=0, z=0}
cart.acc = {x=0, y=0, z=0}
end
diff --git a/railtrack/railtrack.lua b/railtrack/railtrack.lua
index a72898f..75a62a6 100644
--- a/railtrack/railtrack.lua
+++ b/railtrack/railtrack.lua
@@ -192,7 +192,7 @@ end
function railtrack:get_connections(pos)
local connections = {}
- for y = -1, 1 do
+ for y = 1, -1, -1 do
for x = -1, 1 do
for z = -1, 1 do
if math.abs(x) ~= math.abs(z) then