From c9c4b4cd150dade811793c0795e7f6c875a5dd59 Mon Sep 17 00:00:00 2001 From: DS Date: Sun, 9 Apr 2017 07:19:40 +0200 Subject: [PATCH] make item drop by tubes nicer (#168) * make item drop by tubes nicer --- item_transport.lua | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/item_transport.lua b/item_transport.lua index bbdf003..43adeea 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -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