summaryrefslogtreecommitdiff
path: root/pipeworks/filter-injector.lua
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-09-26 00:11:57 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-09-26 00:11:57 -0400
commit3d08b568ad1da1e3259a66cb91fd1039781c75cb (patch)
tree59c396f503f3946b8757093f5c90605fe9f91d07 /pipeworks/filter-injector.lua
parent4aab7d0dbd782cf6741bdbba94440faf0c5c2e61 (diff)
downloaddreambuilder_modpack-3d08b568ad1da1e3259a66cb91fd1039781c75cb.tar
dreambuilder_modpack-3d08b568ad1da1e3259a66cb91fd1039781c75cb.tar.gz
dreambuilder_modpack-3d08b568ad1da1e3259a66cb91fd1039781c75cb.tar.bz2
dreambuilder_modpack-3d08b568ad1da1e3259a66cb91fd1039781c75cb.tar.xz
dreambuilder_modpack-3d08b568ad1da1e3259a66cb91fd1039781c75cb.zip
update castles modpack, boost_cart, homedecor, currency, farming redo,
framed glass, gloopblocks, mesecons, moreblocks, pipeworks, signs_lib, technic, unified mesecons, and worldedit created a new tag for this release (this will be standard procedure from now on)
Diffstat (limited to 'pipeworks/filter-injector.lua')
-rw-r--r--pipeworks/filter-injector.lua95
1 files changed, 87 insertions, 8 deletions
diff --git a/pipeworks/filter-injector.lua b/pipeworks/filter-injector.lua
index 45b27c4..c9d132f 100644
--- a/pipeworks/filter-injector.lua
+++ b/pipeworks/filter-injector.lua
@@ -156,7 +156,7 @@ local function grabAndFire(data,slotseq_mode,exmatch_mode,filtmeta,frominv,fromi
end
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
local start_pos = vector.add(frompos, dir)
- local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item)
+ local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item, fakePlayer:get_player_name())
return true-- only fire one item, please
end
end
@@ -219,7 +219,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
local filters = {}
if data.digiline then
local function add_filter(name, group, count, wear, metadata)
- table.insert(filters, {name = name, group = group, count = count, wear = wear, metadata = metadata})
+ table.insert(filters, {name = name, group = group, count = tonumber(count), wear = wear, metadata = metadata})
end
local function add_itemstring_filter(filter)
@@ -317,8 +317,16 @@ local function punch_filter(data, filtpos, filtnode, msg)
exact_match = filtmeta:get_int("exmatch_mode")
end
- local frommeta = minetest.get_meta(frompos)
- local frominv = frommeta:get_inventory()
+ local frominv
+ if fromtube.return_input_invref then
+ frominv = fromtube.return_input_invref(frompos, fromnode, dir, owner)
+ if not frominv then
+ return
+ end
+ else
+ local frommeta = minetest.get_meta(frompos)
+ frominv = frommeta:get_inventory()
+ end
if fromtube.before_filter then fromtube.before_filter(frompos) end
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
local done = false
@@ -378,12 +386,22 @@ for _, data in ipairs({
end,
after_dig_node = pipeworks.after_dig,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- if not pipeworks.may_configure(pos, player) then return 0 end
- return stack:get_count()
+ if not pipeworks.may_configure(pos, player) then
+ return 0
+ end
+ local inv = minetest.get_meta(pos):get_inventory()
+ inv:set_stack("main", index, stack)
+ return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- if not pipeworks.may_configure(pos, player) then return 0 end
- return stack:get_count()
+ if not pipeworks.may_configure(pos, player) then
+ return 0
+ end
+ local inv = minetest.get_meta(pos):get_inventory()
+ local fake_stack = inv:get_stack("main", index)
+ fake_stack:take_item(stack:get_count())
+ inv:set_stack("main", index, fake_stack)
+ return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end
@@ -481,3 +499,64 @@ if minetest.get_modpath("digilines") then
},
})
end
+
+--[[
+In the past the filter-injectors had real items in their inventories. This code
+puts them to the input to the filter-injector if possible. Else the items are
+dropped.
+]]
+local function put_to_inputinv(pos, node, filtmeta, list)
+ local dir = pipeworks.facedir_to_right_dir(node.param2)
+ local frompos = vector.subtract(pos, dir)
+ local fromnode = minetest.get_node(frompos)
+ local fromdef = minetest.registered_nodes[fromnode.name]
+ if not fromdef or not fromdef.tube then
+ return
+ end
+ local fromtube = fromdef.tube
+ local frominv
+ if fromtube.return_input_invref then
+ local owner = filtmeta:get_string("owner")
+ frominv = fromtube.return_input_invref(frompos, fromnode, dir, owner)
+ if not frominv then
+ return
+ end
+ else
+ frominv = minetest.get_meta(frompos):get_inventory()
+ end
+ local listname = type(fromtube.input_inventory) == "table" and
+ fromtube.input_inventory[1] or fromtube.input_inventory
+ if not listname then
+ return
+ end
+ for i = 1, #list do
+ local item = list[i]
+ if not item:is_empty() then
+ local leftover = frominv:add_item(listname, item)
+ if not leftover:is_empty() then
+ minetest.add_item(pos, leftover)
+ end
+ end
+ end
+ return true
+end
+minetest.register_lbm({
+ label = "Give back items of old filters that had real inventories",
+ name = "pipeworks:give_back_old_filter_items",
+ nodenames = {"pipeworks:filter", "pipeworks:mese_filter"},
+ run_at_every_load = false,
+ action = function(pos, node)
+ local meta = minetest.get_meta(pos)
+ local list = meta:get_inventory():get_list("main")
+ if put_to_inputinv(pos, node, meta, list) then
+ return
+ end
+ pos.y = pos.y + 1
+ for i = 1, #list do
+ local item = list[i]
+ if not item:is_empty() then
+ minetest.add_item(pos, item)
+ end
+ end
+ end,
+})