add ability to "filter all" to sorter

This commit is contained in:
FaceDeer 2017-04-01 09:48:54 -06:00
parent 9972c1de84
commit 74c8cf887f
9 changed files with 149 additions and 45 deletions

@ -21,4 +21,4 @@ hopper.doc.chute_long_desc = S("A chute to transfer items over longer distances.
hopper.doc.chute_usage = S("Chutes operate much like hoppers but do not have their own intake capability. Items can only be inserted into a chute manually or by a hopper connected to a chute. They transfer items in the direction indicated by the arrow on their narrow segment at a rate of one item per second. They have a small buffer capacity, and any items that can't be placed into the target block's inventory will remain lodged in the chute's buffer until manually removed or their destination becomes available.") hopper.doc.chute_usage = S("Chutes operate much like hoppers but do not have their own intake capability. Items can only be inserted into a chute manually or by a hopper connected to a chute. They transfer items in the direction indicated by the arrow on their narrow segment at a rate of one item per second. They have a small buffer capacity, and any items that can't be placed into the target block's inventory will remain lodged in the chute's buffer until manually removed or their destination becomes available.")
hopper.doc.sorter_long_desc = S("A sorter to redirect certain items to an alternate target.") hopper.doc.sorter_long_desc = S("A sorter to redirect certain items to an alternate target.")
hopper.doc.sorter_usage = S("This is similar to a chute but has a secondary output that is used to shunt specific items to an alternate destination. There is a set of inventory slots labeled \"Filter\" at the top of this block's inventory display, if you place an item into one of these slots the sorter will record the item's type (without actually taking it from you). Then when items come through the sorter's inventory that match one of the items in the filter list it will first attempt to send it in the direction marked with an arrow on the sorter's sides.\n\nIf the item doesn't match the filter list, or the secondary output is unable to take the item for whatever reason, the sorter will try to send the item out the other output instead.") hopper.doc.sorter_usage = S("This is similar to a chute but has a secondary output that is used to shunt specific items to an alternate destination. There is a set of inventory slots labeled \"Filter\" at the top of this block's inventory display, if you place an item into one of these slots the sorter will record the item's type (without actually taking it from you). Then when items come through the sorter's inventory that match one of the items in the filter list it will first attempt to send it in the direction marked with an arrow on the sorter's sides.\n\nIf the item doesn't match the filter list, or the secondary output is unable to take the item for whatever reason, the sorter will try to send the item out the other output instead.\n\nIn addition, there is a button labeled \"Filter All\" that will tell the sorter to not use the filter list and instead first attempt to shunt all items out of the filter, only sending items along the non-filter path if the target cannot accept it for whatever reason. This feature is useful for handling \"overflow\" (when the target's inventory fills up) or for dealing with targets that are selective about what they accept (for example, a furnace's fuel slot).")

@ -30,6 +30,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local pos = minetest.string_to_pos(string.sub(formname, 17, -1)) local pos = minetest.string_to_pos(string.sub(formname, 17, -1))
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local eject_setting = meta:get_string("eject") == "true" local eject_setting = meta:get_string("eject") == "true"
local filter_all_setting = meta:get_string("filter_all") == "true"
if fields.eject then if fields.eject then
if eject_setting then if eject_setting then
meta:set_string("eject", nil) meta:set_string("eject", nil)
@ -37,6 +38,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta:set_string("eject", "true") meta:set_string("eject", "true")
end end
end end
if fields.filter_all then
if filter_all_setting then
meta:set_string("filter_all", nil)
else
meta:set_string("filter_all", "true")
end
end
end end
end) end)

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-31 00:35-0600\n" "POT-Creation-Date: 2017-04-01 09:43-0600\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -98,10 +98,18 @@ msgid ""
"\n" "\n"
"If the item doesn't match the filter list, or the secondary output is unable " "If the item doesn't match the filter list, or the secondary output is unable "
"to take the item for whatever reason, the sorter will try to send the item " "to take the item for whatever reason, the sorter will try to send the item "
"out the other output instead." "out the other output instead.\n"
"\n"
"In addition, there is a button labeled \"Filter All\" that will tell the "
"sorter to not use the filter list and instead first attempt to shunt all "
"items out of the filter, only sending items along the non-filter path if the "
"target cannot accept it for whatever reason. This feature is useful for "
"handling \"overflow\" (when the target's inventory fills up) or for dealing "
"with targets that are selective about what they accept (for example, a "
"furnace's fuel slot)."
msgstr "" msgstr ""
#: hopper\init.lua:53 #: hopper\init.lua:61
msgid "[MOD] Hopper loaded" msgid "[MOD] Hopper loaded"
msgstr "[MOD] Trichter geladen" msgstr "[MOD] Trichter geladen"
@ -135,7 +143,7 @@ msgstr ""
msgid "Hopper Chute" msgid "Hopper Chute"
msgstr "" msgstr ""
#: hopper\nodes\chute.lua:77 #: hopper\nodes\chute.lua:78
#, fuzzy #, fuzzy
msgid "@1 moves stuff to chute at @2" msgid "@1 moves stuff to chute at @2"
msgstr "@1 verlagert Dinge in einen Trichter bei @2" msgstr "@1 verlagert Dinge in einen Trichter bei @2"
@ -144,34 +152,65 @@ msgstr "@1 verlagert Dinge in einen Trichter bei @2"
msgid "Hopper" msgid "Hopper"
msgstr "Trichter" msgstr "Trichter"
#: hopper\nodes\hoppers.lua:121 #: hopper\nodes\hoppers.lua:122
#: hopper\nodes\hoppers.lua:212 #: hopper\nodes\hoppers.lua:214
msgid "@1 moves stuff in hopper at @2" msgid "@1 moves stuff in hopper at @2"
msgstr "@1 bewegt Dinge in einem Trichter bei @2" msgstr "@1 bewegt Dinge in einem Trichter bei @2"
#: hopper\nodes\hoppers.lua:126 #: hopper\nodes\hoppers.lua:127
#: hopper\nodes\hoppers.lua:217 #: hopper\nodes\hoppers.lua:219
msgid "@1 moves stuff to hopper at @2" msgid "@1 moves stuff to hopper at @2"
msgstr "@1 verlagert Dinge in einen Trichter bei @2" msgstr "@1 verlagert Dinge in einen Trichter bei @2"
#: hopper\nodes\hoppers.lua:131 #: hopper\nodes\hoppers.lua:132
#: hopper\nodes\hoppers.lua:222 #: hopper\nodes\hoppers.lua:224
msgid "@1 moves stuff from hopper at @2" msgid "@1 moves stuff from hopper at @2"
msgstr "@1 nimmt Dinge aus einem Trichter bei @2" msgstr "@1 nimmt Dinge aus einem Trichter bei @2"
#: hopper\nodes\hoppers.lua:147 #: hopper\nodes\hoppers.lua:148
msgid "Side Hopper" msgid "Side Hopper"
msgstr "Seitentrichter" msgstr "Seitentrichter"
#: hopper\nodes\sorter.lua:22
#: hopper\nodes\sorter.lua:39
msgid ""
"Selective\n"
"Filter"
msgstr ""
#: hopper\nodes\sorter.lua:23 #: hopper\nodes\sorter.lua:23
#: hopper\nodes\sorter.lua:40
msgid ""
"This sorter is currently set to try sending all items\n"
"in the direction of the arrow. Click this button\n"
"to enable an item-type-specific filter."
msgstr ""
#: hopper\nodes\sorter.lua:25
#: hopper\nodes\sorter.lua:43
msgid ""
"Filter\n"
"All"
msgstr ""
#: hopper\nodes\sorter.lua:26
#: hopper\nodes\sorter.lua:44
msgid ""
"This sorter is currently set to only send items listed\n"
"in the filter list in the direction of the arrow.\n"
"Click this button to set it to try sending all\n"
"items that way first."
msgstr ""
#: hopper\nodes\sorter.lua:42
msgid "Filter" msgid "Filter"
msgstr "" msgstr ""
#: hopper\nodes\sorter.lua:36 #: hopper\nodes\sorter.lua:64
msgid "Sorter" msgid "Sorter"
msgstr "" msgstr ""
#: hopper\nodes\sorter.lua:115 #: hopper\nodes\sorter.lua:143
#, fuzzy #, fuzzy
msgid "@1 moves stuff to sorter at @2" msgid "@1 moves stuff to sorter at @2"
msgstr "@1 verlagert Dinge in einen Trichter bei @2" msgstr "@1 verlagert Dinge in einen Trichter bei @2"

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-31 00:35-0600\n" "POT-Creation-Date: 2017-04-01 09:43-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -98,10 +98,18 @@ msgid ""
"\n" "\n"
"If the item doesn't match the filter list, or the secondary output is unable " "If the item doesn't match the filter list, or the secondary output is unable "
"to take the item for whatever reason, the sorter will try to send the item " "to take the item for whatever reason, the sorter will try to send the item "
"out the other output instead." "out the other output instead.\n"
"\n"
"In addition, there is a button labeled \"Filter All\" that will tell the "
"sorter to not use the filter list and instead first attempt to shunt all "
"items out of the filter, only sending items along the non-filter path if the "
"target cannot accept it for whatever reason. This feature is useful for "
"handling \"overflow\" (when the target's inventory fills up) or for dealing "
"with targets that are selective about what they accept (for example, a "
"furnace's fuel slot)."
msgstr "" msgstr ""
#: hopper\init.lua:53 #: hopper\init.lua:61
msgid "[MOD] Hopper loaded" msgid "[MOD] Hopper loaded"
msgstr "" msgstr ""
@ -135,7 +143,7 @@ msgstr ""
msgid "Hopper Chute" msgid "Hopper Chute"
msgstr "" msgstr ""
#: hopper\nodes\chute.lua:77 #: hopper\nodes\chute.lua:78
msgid "@1 moves stuff to chute at @2" msgid "@1 moves stuff to chute at @2"
msgstr "" msgstr ""
@ -143,33 +151,64 @@ msgstr ""
msgid "Hopper" msgid "Hopper"
msgstr "" msgstr ""
#: hopper\nodes\hoppers.lua:121 #: hopper\nodes\hoppers.lua:122
#: hopper\nodes\hoppers.lua:212 #: hopper\nodes\hoppers.lua:214
msgid "@1 moves stuff in hopper at @2" msgid "@1 moves stuff in hopper at @2"
msgstr "" msgstr ""
#: hopper\nodes\hoppers.lua:126 #: hopper\nodes\hoppers.lua:127
#: hopper\nodes\hoppers.lua:217 #: hopper\nodes\hoppers.lua:219
msgid "@1 moves stuff to hopper at @2" msgid "@1 moves stuff to hopper at @2"
msgstr "" msgstr ""
#: hopper\nodes\hoppers.lua:131 #: hopper\nodes\hoppers.lua:132
#: hopper\nodes\hoppers.lua:222 #: hopper\nodes\hoppers.lua:224
msgid "@1 moves stuff from hopper at @2" msgid "@1 moves stuff from hopper at @2"
msgstr "" msgstr ""
#: hopper\nodes\hoppers.lua:147 #: hopper\nodes\hoppers.lua:148
msgid "Side Hopper" msgid "Side Hopper"
msgstr "" msgstr ""
#: hopper\nodes\sorter.lua:22
#: hopper\nodes\sorter.lua:39
msgid ""
"Selective\n"
"Filter"
msgstr ""
#: hopper\nodes\sorter.lua:23 #: hopper\nodes\sorter.lua:23
#: hopper\nodes\sorter.lua:40
msgid ""
"This sorter is currently set to try sending all items\n"
"in the direction of the arrow. Click this button\n"
"to enable an item-type-specific filter."
msgstr ""
#: hopper\nodes\sorter.lua:25
#: hopper\nodes\sorter.lua:43
msgid ""
"Filter\n"
"All"
msgstr ""
#: hopper\nodes\sorter.lua:26
#: hopper\nodes\sorter.lua:44
msgid ""
"This sorter is currently set to only send items listed\n"
"in the filter list in the direction of the arrow.\n"
"Click this button to set it to try sending all\n"
"items that way first."
msgstr ""
#: hopper\nodes\sorter.lua:42
msgid "Filter" msgid "Filter"
msgstr "" msgstr ""
#: hopper\nodes\sorter.lua:36 #: hopper\nodes\sorter.lua:64
msgid "Sorter" msgid "Sorter"
msgstr "" msgstr ""
#: hopper\nodes\sorter.lua:115 #: hopper\nodes\sorter.lua:143
msgid "@1 moves stuff to sorter at @2" msgid "@1 moves stuff to sorter at @2"
msgstr "" msgstr ""

@ -8,7 +8,7 @@ local function get_chute_formspec(pos)
"size[8,7]" "size[8,7]"
.. hopper.formspec_bg .. hopper.formspec_bg
.. "list[nodemeta:" .. spos .. ";main;3,0.3;2,2;]" .. "list[nodemeta:" .. spos .. ";main;3,0.3;2,2;]"
.. hopper.get_eject_button_texts(pos, 7, 1) .. hopper.get_eject_button_texts(pos, 7, 0.8)
.. "list[current_player;main;0,2.85;8,1;]" .. "list[current_player;main;0,2.85;8,1;]"
.. "list[current_player;main;0,4.08;8,3;8]" .. "list[current_player;main;0,4.08;8,3;8]"
.. "listring[nodemeta:" .. spos .. ";main]" .. "listring[nodemeta:" .. spos .. ";main]"

@ -17,15 +17,30 @@ end
local function get_sorter_formspec(pos) local function get_sorter_formspec(pos)
local spos = hopper.get_string_pos(pos) local spos = hopper.get_string_pos(pos)
local filter_all = minetest.get_meta(pos):get_string("filter_all") == "true"
local y_displace = 0
local filter_button_text, filter_button_tooltip, filter_body
if filter_all then
filter_body = ""
filter_button_text = S("Selective\nFilter")
filter_button_tooltip = S("This sorter is currently set to try sending all items\nin the direction of the arrow. Click this button\nto enable an item-type-specific filter.")
else
filter_body = "label[3.7,0;"..S("Filter").."]list[nodemeta:" .. spos .. ";filter;0,0.5;8,1;]"
filter_button_text = S("Filter\nAll")
filter_button_tooltip = S("This sorter is currently set to only send items listed\nin the filter list in the direction of the arrow.\nClick this button to set it to try sending all\nitems that way first.")
y_displace = 1.6
end
local formspec = local formspec =
"size[8,8.4]" "size[8," .. 7 + y_displace .. "]"
.. hopper.formspec_bg .. hopper.formspec_bg
.. "label[3.7,0;"..S("Filter").."]" .. filter_body
.. "list[nodemeta:" .. spos .. ";filter;0,0.5;8,1;]" .. "list[nodemeta:" .. spos .. ";main;3,".. tostring(0.3 + y_displace) .. ";2,2;]"
.. "list[nodemeta:" .. spos .. ";main;3,2.1;2,2;]" .. "button_exit[7,".. tostring(0.8 + y_displace) .. ";1,1;filter_all;".. filter_button_text .. "]tooltip[filter_all;" .. filter_button_tooltip.. "]"
.. hopper.get_eject_button_texts(pos, 7, 3) .. hopper.get_eject_button_texts(pos, 6, 0.8 + y_displace)
.. "list[current_player;main;0,4.5;8,1;]" .. "list[current_player;main;0,".. tostring(2.85 + y_displace) .. ";8,1;]"
.. "list[current_player;main;0,5.7;8,3;8]" .. "list[current_player;main;0,".. tostring(4.08 + y_displace) .. ";8,3;8]"
.. "listring[nodemeta:" .. spos .. ";main]" .. "listring[nodemeta:" .. spos .. ";main]"
.. "listring[current_player;main]" .. "listring[current_player;main]"
return formspec return formspec
@ -44,8 +59,8 @@ minetest.register_node("hopper:sorter", {
tiles = { tiles = {
"hopper_bottom_" .. hopper.config.texture_resolution .. ".png", "hopper_bottom_" .. hopper.config.texture_resolution .. ".png",
"hopper_top_" .. hopper.config.texture_resolution .. ".png", "hopper_top_" .. hopper.config.texture_resolution .. ".png",
"hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png^[transformFX", "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png^[transformFX^hopper_sorter_sub_arrow_" .. hopper.config.texture_resolution .. ".png^[transformFX",
"hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png", "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_sub_arrow_" .. hopper.config.texture_resolution .. ".png",
"hopper_top_" .. hopper.config.texture_resolution .. ".png", "hopper_top_" .. hopper.config.texture_resolution .. ".png",
"hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png", "hopper_bottom_" .. hopper.config.texture_resolution .. ".png^hopper_sorter_arrow_" .. hopper.config.texture_resolution .. ".png",
}, },
@ -126,7 +141,9 @@ minetest.register_node("hopper:sorter", {
local inv = meta:get_inventory() local inv = meta:get_inventory()
-- build a filter list -- build a filter list
local filter_items = {} local filter_items = nil
if meta:get_string("filter_all") ~= "true" then
filter_items = {}
local filter_inv_size = inv:get_size("filter") local filter_inv_size = inv:get_size("filter")
for i = 1, filter_inv_size do for i = 1, filter_inv_size do
local stack = inv:get_stack("filter", i) local stack = inv:get_stack("filter", i)
@ -135,6 +152,7 @@ minetest.register_node("hopper:sorter", {
filter_items[item] = true filter_items[item] = true
end end
end end
end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local dir = minetest.facedir_to_dir(node.param2) local dir = minetest.facedir_to_dir(node.param2)

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

@ -37,7 +37,7 @@ hopper.get_eject_button_texts = function(pos, loc_X, loc_Y)
eject_button_text = S("Eject\nItems") eject_button_text = S("Eject\nItems")
eject_button_tooltip = S("This hopper is currently set to hold on to item if there\nisn't a compatible block positioned to receive it.\nClick this button to have it eject items instead.") eject_button_tooltip = S("This hopper is currently set to hold on to item if there\nisn't a compatible block positioned to receive it.\nClick this button to have it eject items instead.")
end end
return string.format("button_exit[%i,%i;1,1;eject;%s]tooltip[eject;%s]", loc_X, loc_Y, eject_button_text, eject_button_tooltip) return "button_exit["..loc_X..","..loc_Y..";1,1;eject;"..eject_button_text.."]tooltip[eject;"..eject_button_tooltip.."]"
end end
hopper.get_string_pos = function(pos) hopper.get_string_pos = function(pos)