From ef289f300b76b11d97b727fe2fda033c281814ef Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Tue, 6 Aug 2019 17:29:50 +0300 Subject: [PATCH 1/7] Add HighPerf Funnel --- releasenotes.md | 13 +++ tubelib_addons3/funnel.lua | 168 +++++++++++++++++++++++++++++++++++++ tubelib_addons3/init.lua | 3 +- 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tubelib_addons3/funnel.lua diff --git a/releasenotes.md b/releasenotes.md index 67a7bf4..932dc9a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -2,6 +2,19 @@ +## V2.03.05 (2019-08-06) + +### Additions +- Tubelib_addons3 "HighPerf Funnel" added (see isssue #36) + +### Removals + +### Changes + +### Fixes + + + ## V2.03.04 (2019-07-20) ### Additions diff --git a/tubelib_addons3/funnel.lua b/tubelib_addons3/funnel.lua new file mode 100644 index 0000000..860dafc --- /dev/null +++ b/tubelib_addons3/funnel.lua @@ -0,0 +1,168 @@ +--[[ + + Tubelib Addons 3 + ================ + + Copyright (C) 2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + funnel.lua + + A high performance funnel + +]]-- + +local function allow_metadata_inventory_put(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + minetest.log("action", player:get_player_name().." moves "..stack:get_name().. + " to HighPerf funnel at "..minetest.pos_to_string(pos)) + return stack:get_count() +end + +local function allow_metadata_inventory_take(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + minetest.log("action", player:get_player_name().." takes "..stack:get_name().. + " from HighPerf funnel at "..minetest.pos_to_string(pos)) + return stack:get_count() +end + +local function formspec() + return "size[9,7]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[context;main;0.5,0;8,2;]".. + "list[current_player;main;0.5,3.3;8,4;]".. + "listring[context;main]".. + "listring[current_player;main]" +end + +local function scan_for_objects(pos, elapsed) + local meta = minetest.get_meta(pos) + for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do + local lua_entity = object:get_luaentity() + if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then + local obj_pos = object:getpos() + if lua_entity.itemstring ~= "" and ((obj_pos.y - pos.y) >= 0.4) then + if tubelib.put_item(meta, "main", lua_entity.itemstring) then + lua_entity.itemstring = "" + object:remove() + end + end + + end + end + return true +end + +minetest.register_node("tubelib_addons3:funnel", { + description = "HighPerf Funnel", + tiles = { + -- up, down, right, left, back, front + 'tubelib_addons1_funnel_top.png^tubelib_addons3_node_frame4.png', + 'tubelib_addons1_funnel_top.png^tubelib_addons3_node_frame4.png', + 'tubelib_addons1_funnel.png^tubelib_addons3_node_frame4.png', + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, 8/16, -6/16}, + {-8/16, -8/16, 6/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, -6/16, 8/16, 8/16}, + { 6/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-6/16, -8/16, -6/16, 6/16, 4/16, 6/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size('main', 16) + end, + + after_place_node = function(pos, placer) + tubelib.add_node(pos, "tubelib_addons3:funnel") + local meta = minetest.get_meta(pos) + meta:set_string("formspec", formspec()) + minetest.get_node_timer(pos):start(1) + end, + + on_timer = scan_for_objects, + on_rotate = screwdriver.disallow, + + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false + end + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_take = allow_metadata_inventory_take, + + paramtype = "light", + sunlight_propagates = true, + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + + +minetest.register_craft({ + output = "tubelib_addons3:funnel 2", + recipe = { + {"default:tin_ingot", "tubelib_addons1:funnel", ""}, + {"tubelib_addons1:funnel", "default:gold_ingot", ""}, + {"", "", ""}, + }, +}) + + +tubelib.register_node("tubelib_addons3:funnel", {}, { + on_pull_stack = function(pos, side) + local meta = minetest.get_meta(pos) + return tubelib.get_stack(meta, "main") + end, + on_pull_item = function(pos, side) + local meta = minetest.get_meta(pos) + return tubelib.get_item(meta, "main") + end, + on_unpull_item = function(pos, side, item) + local meta = minetest.get_meta(pos) + return tubelib.put_item(meta, "main", item) + end, + + on_recv_message = function(pos, topic, payload) + if topic == "state" then + local meta = minetest.get_meta(pos) + return tubelib.get_inv_state(meta, "main") + else + return "unsupported" + end + end, + on_node_load = function(pos) + minetest.get_node_timer(pos):start(1) + end, + +}) + + diff --git a/tubelib_addons3/init.lua b/tubelib_addons3/init.lua index 93a20cf..a6d584a 100644 --- a/tubelib_addons3/init.lua +++ b/tubelib_addons3/init.lua @@ -14,4 +14,5 @@ dofile(minetest.get_modpath("tubelib_addons3") .. '/chest.lua') dofile(minetest.get_modpath("tubelib_addons3") .. '/pusher.lua') dofile(minetest.get_modpath("tubelib_addons3") .. '/distributor.lua') dofile(minetest.get_modpath("tubelib_addons3") .. '/pushing_chest.lua') -dofile(minetest.get_modpath("tubelib_addons3") .. '/teleporter.lua') \ No newline at end of file +dofile(minetest.get_modpath("tubelib_addons3") .. '/teleporter.lua') +dofile(minetest.get_modpath("tubelib_addons3") .. '/funnel.lua') From 11562718fbe89266a589cfbea6d5c7539d273d54 Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Tue, 6 Aug 2019 17:50:33 +0300 Subject: [PATCH 2/7] Fix crafting recipe output --- tubelib_addons3/funnel.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubelib_addons3/funnel.lua b/tubelib_addons3/funnel.lua index 860dafc..c149413 100644 --- a/tubelib_addons3/funnel.lua +++ b/tubelib_addons3/funnel.lua @@ -128,7 +128,7 @@ minetest.register_node("tubelib_addons3:funnel", { minetest.register_craft({ - output = "tubelib_addons3:funnel 2", + output = "tubelib_addons3:funnel", recipe = { {"default:tin_ingot", "tubelib_addons1:funnel", ""}, {"tubelib_addons1:funnel", "default:gold_ingot", ""}, From 3082c64dac5d5107d87c339559edfe3c4113eabe Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Wed, 7 Aug 2019 21:43:21 +0300 Subject: [PATCH 3/7] Fix incorrect count check on item put --- tubelib/distributor.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tubelib/distributor.lua b/tubelib/distributor.lua index d588910..e4a1b27 100644 --- a/tubelib/distributor.lua +++ b/tubelib/distributor.lua @@ -142,19 +142,19 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) local meta = M(pos) local inv = meta:get_inventory() local list = inv:get_list(listname) + local stack_count = stack:get_count() if minetest.is_protected(pos, player:get_player_name()) then return 0 end if listname == "src" then - if State:get_state(M(pos)) == tubelib.STANDBY then + if State:get_state(meta) == tubelib.STANDBY then State:start(pos, meta) end - return stack:get_count() - elseif invlist_num_entries(list) < MAX_NUM_PER_CYC then - return stack:get_count() + return stack_count end - return 0 + + return math.min(stack_count, MAX_NUM_PER_CYC - invlist_num_entries(list)) end local function allow_metadata_inventory_take(pos, listname, index, stack, player) From 2e14f13c46bc7049dc56e626583b90e82838de53 Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Wed, 7 Aug 2019 21:46:32 +0300 Subject: [PATCH 4/7] Revert "Fix incorrect count check on item put" This reverts commit 3082c64dac5d5107d87c339559edfe3c4113eabe. (incorrect branch) --- tubelib/distributor.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tubelib/distributor.lua b/tubelib/distributor.lua index e4a1b27..d588910 100644 --- a/tubelib/distributor.lua +++ b/tubelib/distributor.lua @@ -142,19 +142,19 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) local meta = M(pos) local inv = meta:get_inventory() local list = inv:get_list(listname) - local stack_count = stack:get_count() if minetest.is_protected(pos, player:get_player_name()) then return 0 end if listname == "src" then - if State:get_state(meta) == tubelib.STANDBY then + if State:get_state(M(pos)) == tubelib.STANDBY then State:start(pos, meta) end - return stack_count + return stack:get_count() + elseif invlist_num_entries(list) < MAX_NUM_PER_CYC then + return stack:get_count() end - - return math.min(stack_count, MAX_NUM_PER_CYC - invlist_num_entries(list)) + return 0 end local function allow_metadata_inventory_take(pos, listname, index, stack, player) From db11cc0e928a1b4b375b0589b036aeb0f4ecb34b Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Thu, 8 Aug 2019 16:59:17 +0300 Subject: [PATCH 5/7] Fixes to metadata_inventory functions in distributor code --- tubelib/distributor.lua | 77 +++++++++++++++++++-------------- tubelib_addons3/distributor.lua | 28 +++++++----- 2 files changed, 62 insertions(+), 43 deletions(-) diff --git a/tubelib/distributor.lua b/tubelib/distributor.lua index d588910..0d70cad 100644 --- a/tubelib/distributor.lua +++ b/tubelib/distributor.lua @@ -138,39 +138,6 @@ local function num_items(moved_items, name, filter_item_names, rejected_item_nam end end -local function allow_metadata_inventory_put(pos, listname, index, stack, player) - local meta = M(pos) - local inv = meta:get_inventory() - local list = inv:get_list(listname) - - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - if listname == "src" then - if State:get_state(M(pos)) == tubelib.STANDBY then - State:start(pos, meta) - end - return stack:get_count() - elseif invlist_num_entries(list) < MAX_NUM_PER_CYC then - return stack:get_count() - end - return 0 -end - -local function allow_metadata_inventory_take(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - return stack:get_count() -end - -local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) - local meta = M(pos) - local inv = meta:get_inventory() - local stack = inv:get_stack(from_list, from_index) - return allow_metadata_inventory_put(pos, to_list, to_index, stack, player) -end - local SlotColors = {"red", "green", "blue", "yellow"} local Num2Ascii = {"B", "L", "F", "R"} -- color to side translation local FilterCache = {} -- local cache for filter settings @@ -204,6 +171,50 @@ local function filter_settings(pos) } end +local function allow_metadata_inventory_put(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + local meta = M(pos) + local inv = meta:get_inventory() + local list = inv:get_list(listname) + local stack_count = stack:get_count() + + if listname == "src" then + if State:get_state(M(pos)) == tubelib.STANDBY then + State:start(pos, meta) + end + return stack_count + end + + local space_left = MAX_NUM_PER_CYC - invlist_num_entries(list) + if space_left <= 0 then -- < 0 case is possible if distributor is already misconfigured + return 0 + end + + filter_settings(pos) + return math.min(stack_count, space_left) +end + +local function allow_metadata_inventory_take(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + if listname ~= "src" then + filter_settings(pos) + end + return stack:get_count() +end + +local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) + local meta = M(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + return allow_metadata_inventory_put(pos, to_list, to_index, stack, player) +end + -- move items from configured filters to the output local function distributing(pos, meta) local player_name = meta:get_string("player_name") diff --git a/tubelib_addons3/distributor.lua b/tubelib_addons3/distributor.lua index bed3ae5..f1dd69b 100644 --- a/tubelib_addons3/distributor.lua +++ b/tubelib_addons3/distributor.lua @@ -143,30 +143,38 @@ local function filter_settings(pos) end local function allow_metadata_inventory_put(pos, listname, index, stack, player) - local meta = M(pos) - local inv = meta:get_inventory() - local list = inv:get_list(listname) - if minetest.is_protected(pos, player:get_player_name()) then return 0 end + + local meta = M(pos) + local inv = meta:get_inventory() + local list = inv:get_list(listname) + local stack_count = stack:get_count() + if listname == "src" then if State:get_state(M(pos)) == tubelib.STANDBY then State:start(pos, meta) end - return stack:get_count() - elseif invlist_num_entries(list) < NUM_FILTER_ELEM then - filter_settings(pos) - return 1 + return stack_count end - return 0 + + local space_left = NUM_FILTER_ELEM - invlist_num_entries(list) + if space_left <= 0 then + return 0 + end + + filter_settings(pos) + return 1 end local function allow_metadata_inventory_take(pos, listname, index, stack, player) if minetest.is_protected(pos, player:get_player_name()) then return 0 end - filter_settings(pos) + if listname ~= "src" then + filter_settings(pos) + end return stack:get_count() end From b44ddb0bb3784f0831a046565c89ffa25333db03 Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Thu, 8 Aug 2019 19:08:35 +0300 Subject: [PATCH 6/7] Update releasenotes --- releasenotes.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/releasenotes.md b/releasenotes.md index 932dc9a..bf13eec 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -2,6 +2,19 @@ +## V2.03.05 (2019-08-08) + +### Additions + +### Removals + +### Changes + +### Fixes +- Fixes to distributor metadata_inventory functions + + + ## V2.03.05 (2019-08-06) ### Additions From 241d779c421165b70a6e3046640dba35c2f8700c Mon Sep 17 00:00:00 2001 From: Andrey Kozlovskiy Date: Thu, 8 Aug 2019 19:13:17 +0300 Subject: [PATCH 7/7] Change version in releasenotes. --- releasenotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes.md b/releasenotes.md index bf13eec..2978382 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -2,7 +2,7 @@ -## V2.03.05 (2019-08-08) +## V2.03.06 (2019-08-08) ### Additions