| | |
| | | local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end |
| | | |
| | | local pipeworks = rawget(_G, "pipeworks") |
| | | local fs_helpers = rawget(_G, "fs_helpers") |
| | | local fs_helpers |
| | | local tubelib_exists = minetest.global_exists("tubelib") |
| | | |
| | | local allow_label = "" |
| | | local tube_entry = "" |
| | |
| | | |
| | | local function set_formspec(pos, data, page) |
| | | local meta = minetest.get_meta(pos) |
| | | local node = minetest.get_node(pos) |
| | | local formspec = data.base_formspec |
| | | formspec = formspec..fs_helpers.cycling_button( |
| | | meta, |
| | |
| | | |
| | | if data.autosort then |
| | | 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")).."]" |
| | | end |
| | | if data.infotext then |
| | | local formspec_infotext = minetest.formspec_escape(meta:get_string("infotext")) |
| | |
| | | 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 |
| | |
| | | data.lotop = data.height + 2 |
| | | data.ovheight = data.lotop + 4 |
| | | |
| | | local locked_after_place = nil |
| | | local front = {"technic_"..lname.."_chest_front.png"} |
| | | data.base_formspec = "size["..data.ovwidth..","..data.ovheight.."]".. |
| | | "label[0,0;"..S("%s Chest"):format(name).."]".. |
| | |
| | | data.base_formspec = data.base_formspec..get_color_buttons(data.coleft, data.lotop) |
| | | end |
| | | |
| | | local locked_after_place |
| | | if data.locked then |
| | | locked_after_place = function(pos, placer) |
| | | local meta = minetest.get_meta(pos) |
| | |
| | | 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 |
| | | |