Make filters behave correctly with protected areas (fixes #74)
This commit is contained in:
parent
3f85f83e35
commit
b49428721a
@ -1,8 +1,6 @@
|
|||||||
local fakePlayer = {
|
local function delay(x)
|
||||||
get_player_name = function() return ":pipeworks" end,
|
return (function() return x end)
|
||||||
-- any other player functions called by allow_metadata_inventory_take anywhere...
|
end
|
||||||
-- perhaps a custom metaclass that errors specially when fakePlayer.<property> is not found?
|
|
||||||
}
|
|
||||||
|
|
||||||
function pipeworks.tube_item(pos, item)
|
function pipeworks.tube_item(pos, item)
|
||||||
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
|
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
|
end
|
||||||
|
|
||||||
-- todo SOON: this function has *way too many* parameters
|
-- 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 = {}
|
local sposes = {}
|
||||||
for spos,stack in ipairs(frominv:get_list(frominvname)) do
|
for spos,stack in ipairs(frominv:get_list(frominvname)) do
|
||||||
local matches
|
local matches
|
||||||
@ -126,6 +124,10 @@ end
|
|||||||
local function punch_filter(data, filtpos, filtnode)
|
local function punch_filter(data, filtpos, filtnode)
|
||||||
local filtmeta = minetest.get_meta(filtpos)
|
local filtmeta = minetest.get_meta(filtpos)
|
||||||
local filtinv = filtmeta:get_inventory()
|
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 dir = minetest.facedir_to_right_dir(filtnode.param2)
|
||||||
local frompos = vector.subtract(filtpos, dir)
|
local frompos = vector.subtract(filtpos, dir)
|
||||||
local fromnode = minetest.get_node(frompos)
|
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
|
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
|
||||||
local done = false
|
local done = false
|
||||||
for _, filtername in ipairs(filters) do
|
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
|
done = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -190,6 +192,9 @@ for _, data in ipairs({
|
|||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 8*2)
|
inv:set_size("main", 8*2)
|
||||||
end,
|
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)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
fs_helpers.on_receive_fields(pos, fields)
|
fs_helpers.on_receive_fields(pos, fields)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user