mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-11-23 23:23:44 +01:00
Transport items; do not remove carts in walls
This commit is contained in:
parent
5373a05c9a
commit
a59864dd74
25
init.lua
25
init.lua
@ -29,7 +29,8 @@ boost_cart.cart = {
|
|||||||
velocity = {x=0, y=0, z=0}, -- only used on punch
|
velocity = {x=0, y=0, z=0}, -- only used on punch
|
||||||
old_dir = {x=0, y=0, z=0},
|
old_dir = {x=0, y=0, z=0},
|
||||||
old_pos = nil,
|
old_pos = nil,
|
||||||
old_switch = nil
|
old_switch = nil,
|
||||||
|
attached_items = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function boost_cart.cart:on_rightclick(clicker)
|
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 puncher:get_player_control().sneak then
|
||||||
if self.driver then
|
if self.driver then
|
||||||
|
if self.old_pos then
|
||||||
|
self.object:setpos(self.old_pos)
|
||||||
|
end
|
||||||
default.player_attached[self.driver] = nil
|
default.player_attached[self.driver] = nil
|
||||||
local player = minetest.get_player_by_name(self.driver)
|
local player = minetest.get_player_by_name(self.driver)
|
||||||
if player then
|
if player then
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for _,obj_ in ipairs(self.attached_items) do
|
||||||
|
if obj_ then
|
||||||
|
obj_:set_detach()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
puncher:get_inventory():add_item("main", "carts:cart")
|
puncher:get_inventory():add_item("main", "carts:cart")
|
||||||
return
|
return
|
||||||
@ -143,7 +153,6 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
pos = vector.new(expected_pos)
|
pos = vector.new(expected_pos)
|
||||||
self.punch = true
|
self.punch = true
|
||||||
end
|
end
|
||||||
--minetest.log("action", "Cart moving too fast at "..minetest.pos_to_string(expected_pos))
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -241,7 +250,7 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
if dir.x < 0 then
|
if dir.x < 0 then
|
||||||
yaw = 0.5
|
yaw = 0.5
|
||||||
elseif dir.x > 0 then
|
elseif dir.x > 0 then
|
||||||
yaw = 3 / 2
|
yaw = 1.5
|
||||||
elseif dir.z < 0 then
|
elseif dir.z < 0 then
|
||||||
yaw = 1
|
yaw = 1
|
||||||
end
|
end
|
||||||
@ -258,6 +267,16 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
if self.punch then
|
if self.punch then
|
||||||
self.object:setvelocity(vel)
|
self.object:setvelocity(vel)
|
||||||
self.object:setpos(pos)
|
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
|
end
|
||||||
self.punch = false
|
self.punch = false
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user