| | |
| | | |
| | | local pipeworks = rawget(_G, "pipeworks") |
| | | local fs_helpers = rawget(_G, "fs_helpers") |
| | | local tubelib_exists = minetest.global_exists("tubelib") |
| | | |
| | | local allow_label = "" |
| | | local tube_entry = "" |
| | |
| | | "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"} |
| | | pipeworks.button_off, |
| | | pipeworks.button_on |
| | | } |
| | | )..allow_label |
| | | |
| | |
| | | local m = st:get_metadata() |
| | | local k = string.format("%s %05d %s", n, w, m) |
| | | if not typecnt[k] then |
| | | typecnt[k] = { |
| | | name = n, |
| | | wear = w, |
| | | metadata = m, |
| | | stack_max = st:get_stack_max(), |
| | | count = 0, |
| | | } |
| | | typecnt[k] = {st} |
| | | table.insert(typekeys, k) |
| | | else |
| | | table.insert(typecnt[k], st) |
| | | end |
| | | typecnt[k].count = typecnt[k].count + st:get_count() |
| | | end |
| | | end |
| | | table.sort(typekeys) |
| | | local outlist = {} |
| | | inv:set_list("main", {}) |
| | | for _, k in ipairs(typekeys) do |
| | | local tc = typecnt[k] |
| | | while tc.count > 0 do |
| | | local c = math.min(tc.count, tc.stack_max) |
| | | table.insert(outlist, ItemStack({ |
| | | name = tc.name, |
| | | wear = tc.wear, |
| | | metadata = tc.metadata, |
| | | count = c, |
| | | })) |
| | | tc.count = tc.count - c |
| | | for _, item in ipairs(typecnt[k]) do |
| | | inv:add_item("main", item) |
| | | end |
| | | end |
| | | if #outlist > #inlist then return end |
| | | while #outlist < #inlist do |
| | | table.insert(outlist, ItemStack(nil)) |
| | | end |
| | | inv:set_list("main", outlist) |
| | | end |
| | | |
| | | local function get_receive_fields(name, data) |
| | |
| | | return function(pos, formname, fields, sender) |
| | | local meta = minetest.get_meta(pos) |
| | | local page = "main" |
| | | |
| | | local owner = meta:get_string("owner") |
| | | if owner ~= "" then |
| | | -- prevent modification of locked chests |
| | | if owner ~= sender:get_player_name() then return end |
| | | elseif not fields.quit then |
| | | -- prevent modification of protected chests |
| | | if minetest.is_protected(pos, sender:get_player_name()) then return end |
| | | end |
| | | |
| | | if fields.sort or (data.autosort and fields.quit and meta:get_int("autosort") == 1) then |
| | | sort_inventory(meta:get_inventory()) |
| | | end |
| | |
| | | on_receive_fields = get_receive_fields(name, data), |
| | | on_metadata_inventory_move = self.on_inv_move, |
| | | on_metadata_inventory_put = self.on_inv_put, |
| | | on_metadata_inventory_take = self.on_inv_take, |
| | | on_metadata_inventory_take = self.on_inv_take, |
| | | on_blast = function(pos) |
| | | local drops = {} |
| | | default.get_inventory_drops(pos, "main", drops) |
| | |
| | | return def |
| | | end |
| | | |
| | | local _TUBELIB_CALLBACKS = { |
| | | on_pull_item = function(pos, side, player_name) |
| | | if not minetest.is_protected(pos, player_name) then |
| | | local inv = minetest.get_meta(pos):get_inventory() |
| | | for _, stack in pairs(inv:get_list("main")) do |
| | | if not stack:is_empty() then |
| | | return inv:remove_item("main", stack:get_name()) |
| | | end |
| | | end |
| | | end |
| | | return nil |
| | | end, |
| | | on_push_item = function(pos, side, item, player_name) |
| | | local inv = minetest.get_meta(pos):get_inventory() |
| | | if inv:room_for_item("main", item) then |
| | | inv:add_item("main", item) |
| | | return true |
| | | end |
| | | return false |
| | | end, |
| | | on_unpull_item = function(pos, side, item, player_name) |
| | | local inv = minetest.get_meta(pos):get_inventory() |
| | | if inv:room_for_item("main", item) then |
| | | inv:add_item("main", item) |
| | | return true |
| | | end |
| | | return false |
| | | end, |
| | | } |
| | | |
| | | function technic.chests:register(name, data) |
| | | local def = technic.chests:definition(name, data) |
| | | |
| | | local nn = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" |
| | | minetest.register_node(":"..nn, def) |
| | | |
| | | if tubelib_exists then |
| | | tubelib.register_node(nn, {}, _TUBELIB_CALLBACKS) |
| | | end |
| | | |
| | | if data.color then |
| | | local mk_front |
| | |
| | | colordef.groups = self.groups_noinv |
| | | colordef.tiles = { def.tiles[1], def.tiles[2], def.tiles[3], def.tiles[4], def.tiles[5], mk_front("technic_chest_overlay"..postfix..".png") } |
| | | minetest.register_node(":"..nn..postfix, colordef) |
| | | if tubelib_exists then |
| | | tubelib.register_node(nn..postfix, {}, _TUBELIB_CALLBACKS) |
| | | end |
| | | end |
| | | end |
| | | |
| | | end |
| | | |