Add external storage bus, Fix network node removal
This commit is contained in:
parent
4e9ab352df
commit
b478c8e298
@ -135,6 +135,14 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "holostorage:external_storage_bus",
|
||||
recipe = {
|
||||
{"holostorage:import_bus", "holostorage:export_bus"},
|
||||
{"default:mese_crystal", "default:chest"}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "holostorage:controller",
|
||||
recipe = {
|
||||
|
@ -65,6 +65,7 @@ local function flip_filter(pos, form, fields, player)
|
||||
end
|
||||
end
|
||||
|
||||
-- Import Bus
|
||||
minetest.register_node("holostorage:import_bus", {
|
||||
description = "Import Bus",
|
||||
tiles = {
|
||||
@ -89,7 +90,7 @@ minetest.register_node("holostorage:import_bus", {
|
||||
|
||||
meta:set_int("filter", 0)
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
on_receive_fields = flip_filter,
|
||||
holostorage_run = function (pos, _, controller)
|
||||
local network = minetest.hash_node_position(controller)
|
||||
@ -138,6 +139,7 @@ minetest.register_node("holostorage:import_bus", {
|
||||
allow_metadata_inventory_put = inventory_ghost_put
|
||||
})
|
||||
|
||||
-- Export Bus
|
||||
minetest.register_node("holostorage:export_bus", {
|
||||
description = "Export Bus",
|
||||
tiles = {
|
||||
@ -160,7 +162,7 @@ minetest.register_node("holostorage:export_bus", {
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("filter", 8)
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
holostorage_run = function (pos, _, controller)
|
||||
local network = minetest.hash_node_position(controller)
|
||||
local node = minetest.get_node(pos)
|
||||
@ -204,5 +206,55 @@ minetest.register_node("holostorage:export_bus", {
|
||||
allow_metadata_inventory_put = inventory_ghost_put
|
||||
})
|
||||
|
||||
-- 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,
|
||||
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)
|
||||
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
|
||||
})
|
||||
|
||||
holostorage.devices["holostorage:import_bus"] = true
|
||||
holostorage.devices["holostorage:export_bus"] = true
|
||||
holostorage.devices["holostorage:external_storage_bus"] = true
|
||||
|
@ -43,5 +43,5 @@ minetest.register_node("holostorage:cable", {
|
||||
on_construct = function (pos)
|
||||
holostorage.network.clear_networks(pos)
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
})
|
||||
|
138
nodes/common.lua
138
nodes/common.lua
@ -42,3 +42,141 @@ function holostorage.front(pos, fd)
|
||||
front.z = front.z * -1 + pos.z
|
||||
return front
|
||||
end
|
||||
|
||||
function holostorage.stack_list(pos)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
local inv_n = "main"
|
||||
local inv_p
|
||||
if diskptr:find("chest/") then
|
||||
inv_p, inv_n = diskptr:match("chest/(.*)/([%a_]+)")
|
||||
local pos1 = minetest.string_to_pos(inv_p)
|
||||
local meta = minetest.get_meta(pos1)
|
||||
invref = meta:get_inventory()
|
||||
end
|
||||
|
||||
if invref then
|
||||
local stacks = invref:get_list(inv_n)
|
||||
for _,stack in pairs(stacks) do
|
||||
if not stack:is_empty() then
|
||||
table.insert(tabl, stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--table.sort( tabl, sort_by_stack_name )
|
||||
return tabl
|
||||
end
|
||||
|
||||
-- Storage Devices
|
||||
function holostorage.insert_stack(pos, stack)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
local success = false
|
||||
local leftover
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
local inv_n = "main"
|
||||
local inv_p
|
||||
if diskptr:find("chest/") then
|
||||
inv_p, inv_n = diskptr:match("chest/(.*)/([%a_]+)")
|
||||
local pos1 = minetest.string_to_pos(inv_p)
|
||||
local meta = minetest.get_meta(pos1)
|
||||
invref = meta:get_inventory()
|
||||
end
|
||||
|
||||
if invref then
|
||||
if invref:room_for_item(inv_n, stack) then
|
||||
leftover = invref:add_item(inv_n, stack)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return success, leftover
|
||||
end
|
||||
|
||||
function holostorage.take_stack(pos, stack)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
local stack_ret
|
||||
local success = false
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
local inv_n = "main"
|
||||
local inv_p
|
||||
if diskptr:find("chest/") then
|
||||
inv_p, inv_n = diskptr:match("chest/(.*)/([%a_]+)")
|
||||
local pos1 = minetest.string_to_pos(inv_p)
|
||||
local meta = minetest.get_meta(pos1)
|
||||
invref = meta:get_inventory()
|
||||
end
|
||||
|
||||
if invref then
|
||||
local list = invref:get_list(inv_n)
|
||||
for i, stacki in pairs(list) do
|
||||
if stacki:get_name() == stack:get_name() and stacki:get_wear() == stack:get_wear() then
|
||||
success = true
|
||||
if stack:get_count() >= stacki:get_count() then
|
||||
stack:set_count(stacki:get_count())
|
||||
stacki:clear()
|
||||
else
|
||||
stacki:set_count(stacki:get_count() - stack:get_count())
|
||||
end
|
||||
stack_ret = stack
|
||||
list[i] = stacki
|
||||
break
|
||||
end
|
||||
end
|
||||
invref:set_list(inv_n, list)
|
||||
end
|
||||
end
|
||||
|
||||
return success, stack_ret
|
||||
end
|
||||
|
||||
function holostorage.get_all_inventories(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if minetest.get_item_group(node.name, "holostorage_storage") == 0 then return nil end
|
||||
local inventories = {}
|
||||
|
||||
if minetest.get_item_group(node.name, "disk_drive") ~= 0 then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local drives = inv:get_list("main")
|
||||
for i, v in pairs(drives) do
|
||||
if not v:is_empty() then
|
||||
local meta = v:get_meta()
|
||||
local tag = meta:get_string("storage_tag")
|
||||
if tag and tag ~= "" then
|
||||
inventories[#inventories + 1] = tag
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv_p = meta:get_string("inv_pos")
|
||||
if inv_p and inv_p ~= "" then
|
||||
local inv_n = meta:get_string("inv_name")
|
||||
local pos1 = minetest.string_to_pos(inv_p)
|
||||
local meta1 = minetest.get_meta(pos1)
|
||||
local inv = meta1:get_inventory()
|
||||
if inv and inv:get_list(inv_n) then
|
||||
inventories[#inventories + 1] = "chest/"..inv_p.."/"..inv_n
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return inventories
|
||||
end
|
||||
|
@ -68,101 +68,6 @@ local function sort_by_stack_name( ... )
|
||||
-- body
|
||||
end
|
||||
|
||||
function holostorage.stack_list(pos)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
if invref then
|
||||
local stacks = invref:get_list("main")
|
||||
for _,stack in pairs(stacks) do
|
||||
if not stack:is_empty() then
|
||||
table.insert(tabl, stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--table.sort( tabl, sort_by_stack_name )
|
||||
return tabl
|
||||
end
|
||||
|
||||
function holostorage.insert_stack(pos, stack)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
local success = false
|
||||
local leftover
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
if invref then
|
||||
if invref:room_for_item("main", stack) then
|
||||
leftover = invref:add_item("main", stack)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return success, leftover
|
||||
end
|
||||
|
||||
function holostorage.take_stack(pos, stack)
|
||||
local invs = holostorage.get_all_inventories(pos)
|
||||
if not invs then return {} end
|
||||
local tabl = {}
|
||||
local stack_ret
|
||||
local success = false
|
||||
|
||||
for _,diskptr in pairs(invs) do
|
||||
local invref = holostorage.disks.memcache[diskptr]
|
||||
if invref then
|
||||
local list = invref:get_list("main")
|
||||
for i, stacki in pairs(list) do
|
||||
if stacki:get_name() == stack:get_name() and stacki:get_wear() == stack:get_wear() then
|
||||
success = true
|
||||
if stack:get_count() >= stacki:get_count() then
|
||||
stack:set_count(stacki:get_count())
|
||||
stacki:clear()
|
||||
else
|
||||
stacki:set_count(stacki:get_count() - stack:get_count())
|
||||
end
|
||||
stack_ret = stack
|
||||
list[i] = stacki
|
||||
break
|
||||
end
|
||||
end
|
||||
invref:set_list("main", list)
|
||||
end
|
||||
end
|
||||
|
||||
return success, stack_ret
|
||||
end
|
||||
|
||||
function holostorage.get_all_inventories(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if minetest.get_item_group(node.name, "disk_drive") == 0 then return nil end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local drives = inv:get_list("main")
|
||||
local inventories = {}
|
||||
for i, v in pairs(drives) do
|
||||
if not v:is_empty() then
|
||||
local meta = v:get_meta()
|
||||
local tag = meta:get_string("storage_tag")
|
||||
if tag and tag ~= "" then
|
||||
inventories[#inventories + 1] = tag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return inventories
|
||||
end
|
||||
|
||||
local function register_disk_drive(index)
|
||||
local groups = {
|
||||
cracky = 1,
|
||||
@ -196,7 +101,7 @@ local function register_disk_drive(index)
|
||||
inv:set_size("main", 6)
|
||||
holostorage.network.clear_networks(pos)
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
|
@ -269,7 +269,7 @@ minetest.register_node("holostorage:grid", {
|
||||
minetest.get_node_timer(pos):start(0.02)
|
||||
return itemstack
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
holostorage_run = holostorage.helpers.grid_refresh,
|
||||
allow_metadata_inventory_move = function ()
|
||||
return 0
|
||||
@ -310,7 +310,7 @@ minetest.register_node("holostorage:grid_active", {
|
||||
minetest.get_node_timer(pos):start(0.05)
|
||||
return itemstack
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
holostorage_run = holostorage.helpers.grid_refresh,
|
||||
holostorage_disabled_name = "holostorage:grid",
|
||||
allow_metadata_inventory_move = holostorage.grid.allow_move_active,
|
||||
@ -351,7 +351,7 @@ minetest.register_node("holostorage:crafting_grid", {
|
||||
minetest.get_node_timer(pos):start(0.02)
|
||||
return itemstack
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
holostorage_run = holostorage.helpers.grid_refresh,
|
||||
allow_metadata_inventory_move = function ()
|
||||
return 0
|
||||
@ -392,7 +392,7 @@ minetest.register_node("holostorage:crafting_grid_active", {
|
||||
minetest.get_node_timer(pos):start(0.05)
|
||||
return itemstack
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
holostorage_run = holostorage.helpers.grid_refresh,
|
||||
holostorage_disabled_name = "holostorage:crafting_grid",
|
||||
allow_metadata_inventory_move = holostorage.grid.allow_move_active,
|
||||
|
@ -196,7 +196,7 @@ minetest.register_node("holostorage:solderer", {
|
||||
inv:set_size("src", 3)
|
||||
inv:set_size("dst", 1)
|
||||
end,
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
selection_box = collision_box,
|
||||
collision_box = collision_box,
|
||||
|
||||
@ -221,7 +221,7 @@ minetest.register_node("holostorage:solderer_active", {
|
||||
holostorage_device = 1,
|
||||
not_in_creative_inventory = 1,
|
||||
},
|
||||
on_destruct = holostorage.network.clear_networks,
|
||||
after_dig_node = holostorage.network.clear_networks,
|
||||
selection_box = collision_box,
|
||||
collision_box = collision_box,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user