forked from mtcontrib/pipeworks
fix crash caused by deprecated usage of minetest.item_drop, fixes #122
This commit is contained in:
parent
17a83d0474
commit
352e23cfb1
@ -78,7 +78,7 @@ local function go_next(pos, velocity, stack)
|
|||||||
if not next_positions[1] then
|
if not next_positions[1] then
|
||||||
return false, nil
|
return false, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local n = (cmeta:get_int("tubedir") % (#next_positions)) + 1
|
local n = (cmeta:get_int("tubedir") % (#next_positions)) + 1
|
||||||
if pipeworks.enable_cyclic_mode then
|
if pipeworks.enable_cyclic_mode then
|
||||||
cmeta:set_int("tubedir", n)
|
cmeta:set_int("tubedir", n)
|
||||||
@ -183,7 +183,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
|||||||
self.itemstring = itemstring
|
self.itemstring = itemstring
|
||||||
self.item_entity = self:add_attached_entity("pipeworks:tubed_item", itemstring)
|
self.item_entity = self:add_attached_entity("pipeworks:tubed_item", itemstring)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
set_color = function(self, color)
|
set_color = function(self, color)
|
||||||
if self.color == color then
|
if self.color == color then
|
||||||
return
|
return
|
||||||
@ -205,13 +205,13 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
|||||||
self.start_pos = vector.round(pos)
|
self.start_pos = vector.round(pos)
|
||||||
self:setpos(pos)
|
self:setpos(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = self:getpos()
|
local pos = self:getpos()
|
||||||
local stack = ItemStack(self.itemstring)
|
local stack = ItemStack(self.itemstring)
|
||||||
local drop_pos
|
local drop_pos
|
||||||
|
|
||||||
local velocity = self:getvelocity()
|
local velocity = self:getvelocity()
|
||||||
|
|
||||||
local moved = false
|
local moved = false
|
||||||
local speed = math.abs(velocity.x + velocity.y + velocity.z)
|
local speed = math.abs(velocity.x + velocity.y + velocity.z)
|
||||||
if speed == 0 then
|
if speed == 0 then
|
||||||
@ -219,12 +219,12 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
|||||||
moved = true
|
moved = true
|
||||||
end
|
end
|
||||||
local vel = {x = velocity.x / speed, y = velocity.y / speed, z = velocity.z / speed, speed = speed}
|
local vel = {x = velocity.x / speed, y = velocity.y / speed, z = velocity.z / speed, speed = speed}
|
||||||
|
|
||||||
if vector.distance(pos, self.start_pos) >= 1 then
|
if vector.distance(pos, self.start_pos) >= 1 then
|
||||||
self.start_pos = vector.add(self.start_pos, vel)
|
self.start_pos = vector.add(self.start_pos, vel)
|
||||||
moved = true
|
moved = true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.load_position(self.start_pos)
|
minetest.load_position(self.start_pos)
|
||||||
local node = minetest.get_node(self.start_pos)
|
local node = minetest.get_node(self.start_pos)
|
||||||
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
||||||
@ -243,18 +243,18 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
|||||||
self:set_item(leftover:to_string())
|
self:set_item(leftover:to_string())
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if moved then
|
if moved then
|
||||||
local found_next, new_velocity = go_next(self.start_pos, velocity, stack) -- todo: color
|
local found_next, new_velocity = go_next(self.start_pos, velocity, stack) -- todo: color
|
||||||
if not found_next then
|
if not found_next then
|
||||||
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
|
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
|
||||||
if drop_pos then
|
if drop_pos then
|
||||||
minetest.item_drop(stack, "", drop_pos)
|
minetest.item_drop(stack, nil, drop_pos)
|
||||||
self:remove()
|
self:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if new_velocity and not vector.equals(velocity, new_velocity) then
|
if new_velocity and not vector.equals(velocity, new_velocity) then
|
||||||
self:setpos(self.start_pos)
|
self:setpos(self.start_pos)
|
||||||
self:setvelocity(new_velocity)
|
self:setvelocity(new_velocity)
|
||||||
|
Loading…
Reference in New Issue
Block a user