make item drop by tubes nicer (#168)

* make item drop by tubes nicer
This commit is contained in:
DS 2017-04-09 07:19:40 +02:00 committed by Vanessa Ezekowitz
parent c2a288303f
commit c9c4b4cd15

View File

@ -231,15 +231,13 @@ luaentity.register_entity("pipeworks:tubed_item", {
end,
on_step = function(self, dtime)
local pos = self:getpos()
if self.start_pos == nil then
local pos = self:getpos()
self.start_pos = vector.round(pos)
self:setpos(pos)
end
local pos = self:getpos()
local stack = ItemStack(self.itemstring)
local drop_pos
local velocity = self:getvelocity()
@ -284,28 +282,19 @@ luaentity.register_entity("pipeworks:tubed_item", {
local rev_node = minetest.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
local tube_present = minetest.get_item_group(rev_node.name,"tubedevice") == 1
if not found_next then
local drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
if pipeworks.drop_on_routing_fail or not tube_present then
if drop_pos then
-- Using add_item instead of item_drop since this makes pipeworks backward
-- compatible with Minetest 0.4.13.
-- Using item_drop here makes Minetest 0.4.13 crash.
minetest.add_item(drop_pos, stack)
self:remove()
return
end
if pipeworks.drop_on_routing_fail or not tube_present or
minetest.get_item_group(rev_node.name,"tube") ~= 1 then
-- Using add_item instead of item_drop since this makes pipeworks backward
-- compatible with Minetest 0.4.13.
-- Using item_drop here makes Minetest 0.4.13 crash.
local dropped_item = minetest.add_item(self.start_pos, stack)
dropped_item:setvelocity(vector.multiply(velocity, 5))
self:remove()
return
else
if minetest.get_item_group(rev_node.name,"tube") == 1 then
velocity = vector.multiply(velocity, -1)
self:setpos(vector.subtract(self.start_pos, vector.multiply(vel, moved_by - 1)))
self:setvelocity(velocity)
else
if drop_pos then
minetest.add_item(drop_pos, stack)
self:remove()
return
end
end
velocity = vector.multiply(velocity, -1)
self:setpos(vector.subtract(self.start_pos, vector.multiply(vel, moved_by - 1)))
self:setvelocity(velocity)
end
end