allow per-chest stack splitting

(default off)
This commit is contained in:
Vanessa Ezekowitz 2017-04-11 04:41:26 -04:00
parent 7244f86ee5
commit 11f20da744
2 changed files with 36 additions and 8 deletions

View File

@ -1,4 +1,3 @@
technic.chests.groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic.chests.groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
tubedevice=1, tubedevice_receiver=1} tubedevice=1, tubedevice_receiver=1}
technic.chests.groups_noinv = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic.chests.groups_noinv = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
@ -13,8 +12,10 @@ technic.chests.tube = {
can_insert = function(pos, node, stack, direction) can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local onestack = stack:peek_item(1) if meta:get_int("splitstacks") == 1 then
return inv:room_for_item("main", onestack) stack = stack:peek_item(1)
end
return inv:room_for_item("main",stack)
end, end,
input_inventory = "main", input_inventory = "main",
connect_sides = {left=1, right=1, front=1, back=1, top=1, bottom=1}, connect_sides = {left=1, right=1, front=1, back=1, top=1, bottom=1},

View File

@ -1,9 +1,15 @@
local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
local pipeworks = rawget(_G, "pipeworks") local pipeworks = rawget(_G, "pipeworks")
local fs_helpers = rawget(_G, "fs_helpers")
local allow_label = ""
local shift_edit_field = 0
if not minetest.get_modpath("pipeworks") then if not minetest.get_modpath("pipeworks") then
-- Pipeworks is not installed. Simulate using a dummy table... -- Pipeworks is not installed. Simulate using a dummy table...
pipeworks = {} pipeworks = {}
fs_helpers = {}
local pipeworks_meta = {} local pipeworks_meta = {}
setmetatable(pipeworks, pipeworks_meta) setmetatable(pipeworks, pipeworks_meta)
local dummy = function() local dummy = function()
@ -15,6 +21,11 @@ if not minetest.get_modpath("pipeworks") then
end end
pipeworks.after_place = dummy pipeworks.after_place = dummy
pipeworks.after_dig = dummy pipeworks.after_dig = dummy
fs_helpers.cycling_button = function() return "" end
else
fs_helpers = pipeworks.fs_helpers
allow_label = "label[0.9,0.36;Allow splitting incoming stacks from tubes]"
shift_edit_field = 3
end end
local chest_mark_colors = { local chest_mark_colors = {
@ -72,6 +83,16 @@ local function set_formspec(pos, data, page)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local formspec = data.base_formspec local formspec = data.base_formspec
formspec = formspec..fs_helpers.cycling_button(
meta,
"image_button[0,0.35;1,0.6",
"splitstacks",
{
{text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"},
{text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
}
)..allow_label
if data.autosort then if data.autosort then
local status = meta:get_int("autosort") local status = meta:get_int("autosort")
formspec = formspec.."button["..(data.hileft+2)..","..(data.height+1.1)..";3,0.8;autosort_to_"..(1-status)..";"..S("Auto-sort is %s"):format(status == 1 and S("On") or S("Off")).."]" formspec = formspec.."button["..(data.hileft+2)..","..(data.height+1.1)..";3,0.8;autosort_to_"..(1-status)..";"..S("Auto-sort is %s"):format(status == 1 and S("On") or S("Off")).."]"
@ -79,13 +100,13 @@ local function set_formspec(pos, data, page)
if data.infotext then if data.infotext then
local formspec_infotext = minetest.formspec_escape(meta:get_string("infotext")) local formspec_infotext = minetest.formspec_escape(meta:get_string("infotext"))
if page == "main" then if page == "main" then
formspec = formspec.."image_button["..(data.hileft+2.1)..",0.1;0.8,0.8;" formspec = formspec.."image_button["..(shift_edit_field+data.hileft+2.1)..",0.1;0.8,0.8;"
.."technic_pencil_icon.png;edit_infotext;]" .."technic_pencil_icon.png;edit_infotext;]"
.."label["..(data.hileft+3)..",0;"..formspec_infotext.."]" .."label["..(shift_edit_field+data.hileft+3)..",0;"..formspec_infotext.."]"
elseif page == "edit_infotext" then elseif page == "edit_infotext" then
formspec = formspec.."image_button["..(data.hileft+2.1)..",0.1;0.8,0.8;" formspec = formspec.."image_button["..(shift_edit_field+data.hileft+2.1)..",0.1;0.8,0.8;"
.."technic_checkmark_icon.png;save_infotext;]" .."technic_checkmark_icon.png;save_infotext;]"
.."field["..(data.hileft+3.3)..",0.2;4.8,1;" .."field["..(shift_edit_field+data.hileft+3.3)..",0.2;4.8,1;"
.."infotext_box;"..S("Edit chest description:")..";" .."infotext_box;"..S("Edit chest description:")..";"
..formspec_infotext.."]" ..formspec_infotext.."]"
end end
@ -169,12 +190,17 @@ local function get_receive_fields(name, data)
local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest" local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest"
check_color_buttons(pos, meta, nn, fields) check_color_buttons(pos, meta, nn, fields)
end end
if fields["fs_helpers_cycling:0:splitstacks"]
or fields["fs_helpers_cycling:1:splitstacks"] then
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
end
meta:get_inventory():set_size("main", data.width * data.height) meta:get_inventory():set_size("main", data.width * data.height)
set_formspec(pos, data, page) set_formspec(pos, data, page)
end end
end end
function technic.chests:definition(name, data) function technic.chests:definition(name, data)
local lname = name:lower() local lname = name:lower()
name = S(name) name = S(name)
@ -211,6 +237,7 @@ function technic.chests:definition(name, data)
"background["..data.hileft..",1;"..data.width..","..data.height..";technic_"..lname.."_chest_inventory.png]".. "background["..data.hileft..",1;"..data.width..","..data.height..";technic_"..lname.."_chest_inventory.png]"..
"background["..data.loleft..","..data.lotop..";8,4;technic_main_inventory.png]".. "background["..data.loleft..","..data.lotop..";8,4;technic_main_inventory.png]"..
"listring[]" "listring[]"
if data.sort then if data.sort then
data.base_formspec = data.base_formspec.."button["..data.hileft..","..(data.height+1.1)..";1,0.8;sort;"..S("Sort").."]" data.base_formspec = data.base_formspec.."button["..data.hileft..","..(data.height+1.1)..";1,0.8;sort;"..S("Sort").."]"
end end