allow per-generator stack splitting

(default off)
This commit is contained in:
Vanessa Ezekowitz 2017-04-11 05:13:27 -04:00
parent 11f20da744
commit 4eaf48290f

View File

@ -1,5 +1,7 @@
local S = technic.getter local S = technic.getter
local fs_helpers = pipeworks.fs_helpers
local tube = { local tube = {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -9,8 +11,10 @@ local 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("src", onestack) stack = stack:peek_item(1)
end
return inv:room_for_item("src", stack)
end, end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
} }
@ -77,14 +81,29 @@ function technic.register_generator(data)
if burn_totaltime == 0 then burn_totaltime = 1 end if burn_totaltime == 0 then burn_totaltime = 1 end
local percent = math.floor((burn_time / burn_totaltime) * 100) local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("infotext", desc.." ("..percent.."%)") meta:set_string("infotext", desc.." ("..percent.."%)")
meta:set_string("formspec",
"size[8, 9]".. local form = ""
"label[0, 0;"..minetest.formspec_escape(desc).."]".. if ltier ~= "lv" then
"list[current_name;src;3, 1;1, 1;]".. form = fs_helpers.cycling_button(
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. meta,
(percent)..":default_furnace_fire_fg.png]".. "image_button[0,4.3;1,0.6",
"list[current_player;main;0, 5;8, 4;]".. "splitstacks",
"listring[]") {
{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"}
}
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]"
end
meta:set_string("formspec",
"size[8, 9]"..
"label[0, 0;"..minetest.formspec_escape(desc).."]"..
"list[current_name;src;3, 1;1, 1;]"..
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
(percent)..":default_furnace_fire_fg.png]"..
"list[current_player;main;0, 5;8, 4;]"..
"listring[]"..
form
)
end end
minetest.register_node("technic:"..ltier.."_generator", { minetest.register_node("technic:"..ltier.."_generator", {
@ -104,7 +123,20 @@ function technic.register_generator(data)
meta:set_int(data.tier.."_EU_supply", 0) meta:set_int(data.tier.."_EU_supply", 0)
meta:set_int("burn_time", 0) meta:set_int("burn_time", 0)
meta:set_int("tube_time", 0) meta:set_int("tube_time", 0)
meta:set_string("formspec", generator_formspec) local form = generator_formspec
if ltier ~= "lv" then
form = generator_formspec ..
fs_helpers.cycling_button(
meta,
"image_button[0,4.3;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"}
}
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]"
end
meta:set_string("formspec", form)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("src", 1) inv:set_size("src", 1)
end, end,
@ -114,7 +146,27 @@ function technic.register_generator(data)
allow_metadata_inventory_move = technic.machine_inventory_move, allow_metadata_inventory_move = technic.machine_inventory_move,
technic_run = run, technic_run = run,
after_place_node = data.tube and pipeworks.after_place, after_place_node = data.tube and pipeworks.after_place,
after_dig_node = technic.machine_after_dig_node after_dig_node = technic.machine_after_dig_node,
on_receive_fields = function(pos, formname, fields, sender)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
local form = generator_formspec
if ltier ~= "lv" then
form = generator_formspec ..
fs_helpers.cycling_button(
meta,
"image_button[0,4.3;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"}
}
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]"
end
meta:set_string("formspec", form)
end,
}) })
minetest.register_node("technic:"..ltier.."_generator_active", { minetest.register_node("technic:"..ltier.."_generator_active", {
@ -158,6 +210,19 @@ function technic.register_generator(data)
burn_time = burn_time - 1 burn_time = burn_time - 1
meta:set_int("burn_time", burn_time) meta:set_int("burn_time", burn_time)
local percent = math.floor(burn_time / burn_totaltime * 100) local percent = math.floor(burn_time / burn_totaltime * 100)
local formbuttons = ""
if ltier ~= "lv" then
form = fs_helpers.cycling_button(
meta,
"image_button[0,4.3;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"}
}
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]"
end
meta:set_string("formspec", meta:set_string("formspec",
"size[8, 9]".. "size[8, 9]"..
"label[0, 0;"..minetest.formspec_escape(desc).."]".. "label[0, 0;"..minetest.formspec_escape(desc).."]"..
@ -165,9 +230,45 @@ function technic.register_generator(data)
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
(percent)..":default_furnace_fire_fg.png]".. (percent)..":default_furnace_fire_fg.png]"..
"list[current_player;main;0, 5;8, 4;]".. "list[current_player;main;0, 5;8, 4;]"..
"listring[]") "listring[]"..
form
)
return true return true
end, end,
on_receive_fields = function(pos, formname, fields, sender)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
local form = generator_formspec
if ltier ~= "lv" then
form = generator_formspec ..
fs_helpers.cycling_button(
meta,
"image_button[0,4.3;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"}
}
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]"
end
local burn_totaltime = meta:get_int("burn_totaltime") or 0
local burn_time = meta:get_int("burn_time")
local percent = math.floor(burn_time / burn_totaltime * 100)
meta:set_string("formspec",
"size[8, 9]"..
"label[0, 0;"..minetest.formspec_escape(desc).."]"..
"list[current_name;src;3, 1;1, 1;]"..
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
(percent)..":default_furnace_fire_fg.png]"..
"list[current_player;main;0, 5;8, 4;]"..
"listring[]"..
form
)
end,
}) })
technic.register_machine(tier, "technic:"..ltier.."_generator", technic.producer) technic.register_machine(tier, "technic:"..ltier.."_generator", technic.producer)