Transport items; do not remove carts in walls

This commit is contained in:
SmallJoker 2014-10-25 18:49:28 +02:00
parent 5373a05c9a
commit a59864dd74
1 changed files with 22 additions and 3 deletions

View File

@ -29,7 +29,8 @@ boost_cart.cart = {
velocity = {x=0, y=0, z=0}, -- only used on punch
old_dir = {x=0, y=0, z=0},
old_pos = nil,
old_switch = nil
old_switch = nil,
attached_items = {}
}
function boost_cart.cart:on_rightclick(clicker)
@ -57,12 +58,21 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti
if puncher:get_player_control().sneak then
if self.driver then
if self.old_pos then
self.object:setpos(self.old_pos)
end
default.player_attached[self.driver] = nil
local player = minetest.get_player_by_name(self.driver)
if player then
player:set_detach()
end
end
for _,obj_ in ipairs(self.attached_items) do
if obj_ then
obj_:set_detach()
end
end
self.object:remove()
puncher:get_inventory():add_item("main", "carts:cart")
return
@ -143,7 +153,6 @@ function boost_cart.cart:on_step(dtime)
pos = vector.new(expected_pos)
self.punch = true
end
--minetest.log("action", "Cart moving too fast at "..minetest.pos_to_string(expected_pos))
break
end
end
@ -241,7 +250,7 @@ function boost_cart.cart:on_step(dtime)
if dir.x < 0 then
yaw = 0.5
elseif dir.x > 0 then
yaw = 3 / 2
yaw = 1.5
elseif dir.z < 0 then
yaw = 1
end
@ -258,6 +267,16 @@ function boost_cart.cart:on_step(dtime)
if self.punch then
self.object:setvelocity(vel)
self.object:setpos(pos)
for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
if not obj_:is_player() and
obj_:get_luaentity() and
not obj_:get_luaentity().physical_state and
obj_:get_luaentity().name == "__builtin:item" then
obj_:set_attach(self.object, "", {x=0, y=0, z=0}, {x=0, y=0, z=0})
self.attached_items[#self.attached_items + 1] = obj_
end
end
end
self.punch = false
end