summaryrefslogtreecommitdiff
path: root/railcart/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'railcart/init.lua')
-rw-r--r--railcart/init.lua35
1 files changed, 26 insertions, 9 deletions
diff --git a/railcart/init.lua b/railcart/init.lua
index 07edea3..c72db24 100644
--- a/railcart/init.lua
+++ b/railcart/init.lua
@@ -68,6 +68,11 @@ minetest.register_entity("railcart:cart_entity", {
if puncher:get_player_control().sneak then
if self.cart then
if self.cart.id then
+ if self.cart.inv then
+ if not self.cart.inv:is_empty("main") then
+ return
+ end
+ end
railcart:remove_cart(self.cart.id)
end
end
@@ -83,6 +88,17 @@ minetest.register_entity("railcart:cart_entity", {
return
end
if self.cart and direction then
+ if self.driver then
+ direction = {x=0, y=0, z=0}
+ local ld = self.driver:get_look_dir()
+ if ld.y > -0.99 then
+ direction = {
+ x = railtrack:get_sign(ld.x),
+ z = railtrack:get_sign(ld.z),
+ y = self.cart.dir.y
+ }
+ end
+ end
local pos = vector.round(self.object:getpos())
local dir = vector.round(vector.normalize(direction))
local speed = railcart:velocity_to_speed(self.cart.vel)
@@ -154,26 +170,27 @@ minetest.register_craftitem("railcart:cart", {
if not name or pointed_thing.type ~= "node" then
return
end
- local pos = pointed_thing.under
- if not railtrack:is_railnode(pos) then
- return
- end
if not minetest.is_singleplayer() then
if not minetest.check_player_privs(name, {carts=true}) then
minetest.chat_send_player(name, "Requires carts privilege")
return
end
end
- local cons = railtrack:get_connections(pos)
+ local pos = pointed_thing.under
+ if not railtrack:is_railnode(pos) then
+ return
+ end
+ local carts = railcart:get_carts_in_radius(pos, 0.9)
+ if #carts > 0 then
+ return
+ end
local cart = railcart.cart:new()
cart.id = railcart:get_new_id()
cart.inv = railcart:create_detached_inventory(cart.id)
- cart.pos = pos
+ cart.pos = vector.new(pos)
cart.prev = vector.new(pos)
cart.accel = railtrack:get_acceleration(pos)
- if cons[1] then
- cart.target = cons[1]
- end
+ cart.dir = railcart:get_rail_direction(pos)
table.insert(railcart.allcarts, cart)
railcart:save()
if not minetest.setting_getbool("creative_mode") then