From b49428721a7c0e8ce445be7465f0d219cf55a61c Mon Sep 17 00:00:00 2001 From: Novatux Date: Sun, 16 Nov 2014 13:14:17 +0100 Subject: Make filters behave correctly with protected areas (fixes #74) --- item_transport.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/item_transport.lua b/item_transport.lua index c378d6e..cf2d828 100755 --- a/item_transport.lua +++ b/item_transport.lua @@ -1,8 +1,6 @@ -local fakePlayer = { - get_player_name = function() return ":pipeworks" end, - -- any other player functions called by allow_metadata_inventory_take anywhere... - -- perhaps a custom metaclass that errors specially when fakePlayer. is not found? -} +local function delay(x) + return (function() return x end) +end function pipeworks.tube_item(pos, item) error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead") @@ -49,7 +47,7 @@ local function set_filter_formspec(data, meta) end -- todo SOON: this function has *way too many* parameters -local function grabAndFire(data,slotseq_mode,filtmeta,frominv,frominvname,frompos,fromnode,filtername,fromtube,fromdef,dir,all) +local function grabAndFire(data,slotseq_mode,filtmeta,frominv,frominvname,frompos,fromnode,filtername,fromtube,fromdef,dir,fakePlayer,all) local sposes = {} for spos,stack in ipairs(frominv:get_list(frominvname)) do local matches @@ -126,6 +124,10 @@ end local function punch_filter(data, filtpos, filtnode) local filtmeta = minetest.get_meta(filtpos) local filtinv = filtmeta:get_inventory() + local owner = filtmeta:get_string("owner") + local fakePlayer = { + get_player_name = delay(owner), + } -- TODO: use a mechanism as the wielder one local dir = minetest.facedir_to_right_dir(filtnode.param2) local frompos = vector.subtract(filtpos, dir) local fromnode = minetest.get_node(frompos) @@ -147,7 +149,7 @@ local function punch_filter(data, filtpos, filtnode) for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do local done = false for _, filtername in ipairs(filters) do - if grabAndFire(data, slotseq_mode, filtmeta, frominv, frominvname, frompos, fromnode, filtername, fromtube, fromdef, dir, data.stackwise) then + if grabAndFire(data, slotseq_mode, filtmeta, frominv, frominvname, frompos, fromnode, filtername, fromtube, fromdef, dir, fakePlayer, data.stackwise) then done = true break end @@ -190,6 +192,9 @@ for _, data in ipairs({ local inv = meta:get_inventory() inv:set_size("main", 8*2) end, + after_place_node = function (pos, placer) + minetest.get_meta(pos):set_string("owner", placer:get_player_name()) + end, on_receive_fields = function(pos, formname, fields, sender) fs_helpers.on_receive_fields(pos, fields) local meta = minetest.get_meta(pos) -- cgit v1.2.3