From fb91ba53f1af1d5d618f7610cdd04e3895ebd6c6 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Tue, 19 Dec 2017 22:53:18 +0000 Subject: item_transport.lua: read cycle direction at start of go_next() in preparation for refactoring --- item_transport.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/item_transport.lua b/item_transport.lua index d0b0e63..72f6d7d 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -100,6 +100,11 @@ local function go_next(pos, velocity, stack, owner) vel.speed = speed crunch_tube(pos, cnode, cmeta) + -- cycling of outputs: + -- an integer counter is kept in each pipe's metadata, + -- which allows tracking which output was previously chosen. + -- note reliance on get_int returning 0 for uninitialised. + local cycledir = cmeta:get_int("tubedir") if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack) @@ -132,7 +137,9 @@ local function go_next(pos, velocity, stack, owner) return false, nil, nil end - local n = (cmeta:get_int("tubedir") % (#next_positions)) + 1 + local n = (cycledir % (#next_positions)) + 1 + -- if not using output cycling, + -- don't update the field so it stays the same for the next item. if pipeworks.enable_cyclic_mode then cmeta:set_int("tubedir", n) end -- cgit v1.2.3