2018-04-08 14:11:39 +00:00
|
|
|
-- holostorage cabling
|
2018-04-08 12:06:49 +00:00
|
|
|
|
2018-04-08 13:35:50 +00:00
|
|
|
local function get_formspec(title, filter)
|
|
|
|
local fl = "Blacklist"
|
|
|
|
|
|
|
|
if filter ~= nil then
|
|
|
|
if filter == 1 then
|
|
|
|
fl = "Whitelist"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fl = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if fl then
|
|
|
|
fl = "button[0,2.5;2,1;filter;"..fl.."]"
|
|
|
|
else
|
|
|
|
fl = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
return "size[8,8.5]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"label[0,0;"..title.."]"..
|
|
|
|
"list[context;filter;0,1.5;8,1;]"..
|
|
|
|
"list[current_player;main;0,4.25;8,1;]"..
|
|
|
|
"list[current_player;main;0,5.5;8,3;8]"..
|
|
|
|
fl..
|
|
|
|
"listring[context;filter]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0, 4.25)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function inventory_ghost_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
stack:set_count(1)
|
|
|
|
inv:set_stack(listname, index, stack)
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function inventory_ghost_take(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
inv:set_stack(listname, index, ItemStack(nil))
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function flip_filter(pos, form, fields, player)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local ndef = minetest.registered_nodes[node.name].description
|
|
|
|
if fields["filter"] then
|
|
|
|
local f = meta:get_int("filter")
|
|
|
|
if f == 0 then f = 1 else f = 0 end
|
|
|
|
meta:set_int("filter", f)
|
|
|
|
|
|
|
|
meta:set_string("formspec", get_formspec(ndef, f))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-09 09:01:17 +00:00
|
|
|
-- Import Bus
|
2018-04-08 14:11:39 +00:00
|
|
|
minetest.register_node("holostorage:import_bus", {
|
2018-04-08 12:06:49 +00:00
|
|
|
description = "Import Bus",
|
|
|
|
tiles = {
|
2018-04-08 14:11:39 +00:00
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_machine_block.png",
|
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_import.png",
|
2018-04-08 12:06:49 +00:00
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_distributor = 1,
|
|
|
|
holostorage_device = 1,
|
2018-04-08 12:06:49 +00:00
|
|
|
cracky = 2,
|
|
|
|
oddly_breakable_by_hand = 2
|
|
|
|
},
|
|
|
|
on_construct = function (pos)
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage.network.clear_networks(pos)
|
2018-04-08 13:35:50 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", get_formspec("Import Bus", 0))
|
|
|
|
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("filter", 8)
|
|
|
|
|
|
|
|
meta:set_int("filter", 0)
|
2018-04-08 12:06:49 +00:00
|
|
|
end,
|
2018-04-09 09:01:17 +00:00
|
|
|
after_dig_node = holostorage.network.clear_networks,
|
2018-04-08 13:35:50 +00:00
|
|
|
on_receive_fields = flip_filter,
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_run = function (pos, _, controller)
|
2018-04-08 12:06:49 +00:00
|
|
|
local network = minetest.hash_node_position(controller)
|
|
|
|
local node = minetest.get_node(pos)
|
2018-04-08 13:35:50 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2018-04-08 14:11:39 +00:00
|
|
|
local front = holostorage.front(pos, node.param2)
|
2018-04-08 12:06:49 +00:00
|
|
|
|
|
|
|
local front_node = minetest.get_node(front)
|
|
|
|
if front_node.name ~= "air" then
|
|
|
|
local front_meta = minetest.get_meta(front)
|
|
|
|
local front_inv = front_meta:get_inventory()
|
2018-04-09 09:34:41 +00:00
|
|
|
local front_pos = minetest.pos_to_string(front)
|
2018-04-08 12:06:49 +00:00
|
|
|
local front_def = minetest.registered_nodes[front_node.name]
|
|
|
|
if front_inv:get_list("main") then
|
|
|
|
local list = front_inv:get_list("main")
|
2018-04-08 13:35:50 +00:00
|
|
|
local filter_type = meta:get_int("filter")
|
2018-04-08 12:06:49 +00:00
|
|
|
for index, stack in pairs(list) do
|
|
|
|
if not stack:is_empty() then
|
2018-04-08 13:35:50 +00:00
|
|
|
local can_take = false
|
2018-04-08 12:06:49 +00:00
|
|
|
local copystack = front_inv:get_stack("main", index)
|
|
|
|
copystack:set_count(1)
|
2018-04-08 13:35:50 +00:00
|
|
|
|
|
|
|
if filter_type == 0 and inv:contains_item("filter", copystack) then
|
|
|
|
can_take = false
|
|
|
|
elseif filter_type == 1 and inv:contains_item("filter", copystack) then
|
|
|
|
can_take = true
|
|
|
|
else
|
|
|
|
can_take = true
|
|
|
|
end
|
|
|
|
|
2018-04-09 09:34:41 +00:00
|
|
|
meta:set_string("infotext", "Importing from Inventory at "..front_pos)
|
|
|
|
|
2018-04-08 13:35:50 +00:00
|
|
|
if can_take then
|
2018-04-08 14:11:39 +00:00
|
|
|
local success, outst = holostorage.network.insert_item(network, copystack)
|
2018-04-08 13:35:50 +00:00
|
|
|
if success then
|
|
|
|
stack:set_count(stack:get_count() - 1)
|
|
|
|
front_inv:set_stack("main", index, stack)
|
|
|
|
break -- Don't take more than one per cycle
|
|
|
|
end
|
2018-04-08 12:06:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
front_inv:set_list("main", list)
|
2018-04-09 09:34:41 +00:00
|
|
|
return
|
2018-04-08 12:06:49 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-09 09:34:41 +00:00
|
|
|
meta:set_string("infotext", "No Inventory Found")
|
2018-04-08 13:35:50 +00:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_take = inventory_ghost_take,
|
|
|
|
allow_metadata_inventory_put = inventory_ghost_put
|
|
|
|
})
|
|
|
|
|
2018-04-09 09:01:17 +00:00
|
|
|
-- Export Bus
|
2018-04-08 14:11:39 +00:00
|
|
|
minetest.register_node("holostorage:export_bus", {
|
2018-04-08 13:35:50 +00:00
|
|
|
description = "Export Bus",
|
|
|
|
tiles = {
|
2018-04-08 14:11:39 +00:00
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_machine_block.png",
|
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_export.png",
|
2018-04-08 13:35:50 +00:00
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_distributor = 1,
|
|
|
|
holostorage_device = 1,
|
2018-04-08 13:35:50 +00:00
|
|
|
cracky = 2,
|
|
|
|
oddly_breakable_by_hand = 2
|
|
|
|
},
|
|
|
|
on_construct = function (pos)
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage.network.clear_networks(pos)
|
2018-04-08 13:35:50 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", get_formspec("Export Bus"))
|
|
|
|
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("filter", 8)
|
|
|
|
end,
|
2018-04-09 09:01:17 +00:00
|
|
|
after_dig_node = holostorage.network.clear_networks,
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_run = function (pos, _, controller)
|
2018-04-08 13:35:50 +00:00
|
|
|
local network = minetest.hash_node_position(controller)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2018-04-08 14:11:39 +00:00
|
|
|
local front = holostorage.front(pos, node.param2)
|
2018-04-08 13:35:50 +00:00
|
|
|
|
|
|
|
local front_node = minetest.get_node(front)
|
|
|
|
if front_node.name ~= "air" then
|
|
|
|
local front_meta = minetest.get_meta(front)
|
2018-04-09 09:34:41 +00:00
|
|
|
local front_pos = minetest.pos_to_string(front)
|
|
|
|
local front_inv = front_meta:get_inventory()
|
|
|
|
local front_def = minetest.registered_nodes[front_node.name]
|
2018-04-08 13:35:50 +00:00
|
|
|
if front_inv:get_list("main") then
|
2018-04-08 14:11:39 +00:00
|
|
|
local items = holostorage.network.get_storage_inventories(network)
|
2018-04-08 13:35:50 +00:00
|
|
|
for index, stack in pairs(items) do
|
|
|
|
if not stack:is_empty() then
|
|
|
|
local can_take = false
|
|
|
|
stack:set_count(1)
|
|
|
|
|
|
|
|
if inv:contains_item("filter", stack) then
|
|
|
|
can_take = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if not front_inv:room_for_item("main", stack) then
|
|
|
|
can_take = false
|
2018-04-09 09:34:41 +00:00
|
|
|
meta:set_string("infotext", "Inventory full")
|
2018-04-08 13:35:50 +00:00
|
|
|
end
|
|
|
|
|
2018-04-09 09:34:41 +00:00
|
|
|
meta:set_string("infotext", "Exporting to Inventory at "..front_pos)
|
|
|
|
|
2018-04-08 13:35:50 +00:00
|
|
|
if can_take then
|
2018-04-08 14:11:39 +00:00
|
|
|
local success, gotten = holostorage.network.take_item(network, stack)
|
2018-04-08 13:35:50 +00:00
|
|
|
if success then
|
|
|
|
front_inv:add_item("main", gotten)
|
|
|
|
break -- Don't take more than one per cycle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-09 09:34:41 +00:00
|
|
|
return
|
2018-04-08 13:35:50 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-09 09:34:41 +00:00
|
|
|
meta:set_string("infotext", "No Inventory Found")
|
2018-04-08 13:35:50 +00:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_take = inventory_ghost_take,
|
|
|
|
allow_metadata_inventory_put = inventory_ghost_put
|
2018-04-08 12:06:49 +00:00
|
|
|
})
|
|
|
|
|
2018-04-09 09:01:17 +00:00
|
|
|
-- External Storage Bus
|
|
|
|
|
|
|
|
-- Export Bus
|
|
|
|
minetest.register_node("holostorage:external_storage_bus", {
|
|
|
|
description = "External Storage Bus",
|
|
|
|
tiles = {
|
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_machine_block.png",
|
|
|
|
"holostorage_machine_block.png", "holostorage_machine_block.png", "holostorage_external.png",
|
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {
|
|
|
|
holostorage_distributor = 1,
|
|
|
|
holostorage_device = 1,
|
|
|
|
holostorage_storage = 1,
|
|
|
|
cracky = 2,
|
|
|
|
oddly_breakable_by_hand = 2
|
|
|
|
},
|
|
|
|
on_construct = function (pos)
|
|
|
|
holostorage.network.clear_networks(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("inv_pos", "")
|
|
|
|
meta:set_string("inv_name", "")
|
|
|
|
end,
|
|
|
|
after_dig_node = holostorage.network.clear_networks,
|
2018-04-09 09:23:30 +00:00
|
|
|
on_destruct = function (pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local front = holostorage.front(pos, node.param2)
|
|
|
|
minetest.forceload_free_block(front)
|
|
|
|
end,
|
2018-04-09 09:01:17 +00:00
|
|
|
holostorage_run = function (pos, _, controller)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local front = holostorage.front(pos, node.param2)
|
|
|
|
|
|
|
|
local front_node = minetest.get_node(front)
|
|
|
|
if front_node.name ~= "air" then
|
|
|
|
local front_meta = minetest.get_meta(front)
|
|
|
|
local front_inv = front_meta:get_inventory()
|
|
|
|
if front_inv:get_list("main") then
|
|
|
|
local pos_str = minetest.pos_to_string(front)
|
2018-04-09 09:23:30 +00:00
|
|
|
minetest.forceload_block(front)
|
2018-04-09 09:01:17 +00:00
|
|
|
meta:set_string("infotext", "Serving Inventory at "..pos_str)
|
|
|
|
meta:set_string("inv_pos", pos_str)
|
|
|
|
meta:set_string("inv_name", "main")
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
meta:set_string("infotext", "No Inventory Found")
|
|
|
|
meta:set_string("inv_pos", "")
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_take = inventory_ghost_take,
|
|
|
|
allow_metadata_inventory_put = inventory_ghost_put
|
|
|
|
})
|
|
|
|
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage.devices["holostorage:import_bus"] = true
|
|
|
|
holostorage.devices["holostorage:export_bus"] = true
|
2018-04-09 09:01:17 +00:00
|
|
|
holostorage.devices["holostorage:external_storage_bus"] = true
|