1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2024-12-27 03:10:24 +01:00

Fix detector tube item counting

A detector tube would sometimes miss a decrement, due to the pos structure
passed to can_go being modified by the tubed-item entity while it's also
sitting in the timer queue as an argument to item_exit.  As the can_go
API actually depends on being able to mutate the pos structure (see the
teleporter tube), we can't just start passing in a never-mutated copy
of pos.  So for now just fix in the detector tube's can_go, by copying the
structure there.  Incidentally, make the decrement mechanism consistent
between the two forms of increment.
This commit is contained in:
Zefram 2014-07-14 19:34:15 +01:00 committed by Vanessa Ezekowitz
parent 8aea4b1a13
commit ce1505d008

View File

@ -357,7 +357,6 @@ if pipeworks.enable_detector_tube then
local detector_plain_textures = {"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", local detector_plain_textures = {"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png",
"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png"} "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png"}
local detector_inv_texture = "pipeworks_detector_tube_inv.png" local detector_inv_texture = "pipeworks_detector_tube_inv.png"
local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step"))
pipeworks.register_tube("pipeworks:detector_tube_on", "Detecting Pneumatic Tube Segment on (you hacker you)", detector_plain_textures, noctr_textures, pipeworks.register_tube("pipeworks:detector_tube_on", "Detecting Pneumatic Tube Segment on (you hacker you)", detector_plain_textures, noctr_textures,
end_textures, short_texture, detector_inv_texture, end_textures, short_texture, detector_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack) {tube = {can_go = function(pos, node, velocity, stack)
@ -365,7 +364,12 @@ if pipeworks.enable_detector_tube then
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
local nitems = meta:get_int("nitems")+1 local nitems = meta:get_int("nitems")+1
meta:set_int("nitems", nitems) meta:set_int("nitems", nitems)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, pos) local saved_pos = { x = pos.x, y = pos.y, z = pos.z }
minetest.after(0, function ()
minetest.after(0, function ()
minetest.after(0, minetest.registered_nodes[name].item_exit, saved_pos)
end)
end)
return pipeworks.notvel(pipeworks.meseadjlist,velocity) return pipeworks.notvel(pipeworks.meseadjlist,velocity)
end}, end},
groups = {mesecon = 2, not_in_creative_inventory = 1}, groups = {mesecon = 2, not_in_creative_inventory = 1},
@ -389,9 +393,10 @@ if pipeworks.enable_detector_tube then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("nitems", 1) meta:set_int("nitems", 1)
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
local saved_pos = { x = pos.x, y = pos.y, z = pos.z }
minetest.after(0, function () minetest.after(0, function ()
minetest.after(0, function () minetest.after(0, function ()
minetest.after(0, minetest.registered_nodes[name].item_exit, pos) minetest.after(0, minetest.registered_nodes[name].item_exit, saved_pos)
end) end)
end) end)
end}) end})