From cd2e72c307143d32fc256091b8ddd2a731969bf4 Mon Sep 17 00:00:00 2001 From: Evert Date: Sun, 8 Apr 2018 15:06:49 +0300 Subject: [PATCH] Simple importer --- nodes.lua | 3 +++ nodes/bus.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ nodes/common.lua | 8 ++++++++ 3 files changed, 63 insertions(+) create mode 100644 nodes/bus.lua diff --git a/nodes.lua b/nodes.lua index 2db6d3f..544815c 100644 --- a/nodes.lua +++ b/nodes.lua @@ -15,6 +15,9 @@ dofile(storagetest.modpath.."/nodes/disk_drive.lua") -- Grids dofile(storagetest.modpath.."/nodes/grid.lua") +-- Buses +dofile(storagetest.modpath.."/nodes/bus.lua") + -- Start the network storagetest.network.register_abm_controller("storagetest:controller_active") storagetest.network.register_abm_nodes() diff --git a/nodes/bus.lua b/nodes/bus.lua new file mode 100644 index 0000000..4ae2c0c --- /dev/null +++ b/nodes/bus.lua @@ -0,0 +1,52 @@ +-- Storagetest cabling + +minetest.register_node("storagetest:import_bus", { + description = "Import Bus", + tiles = { + "storagetest_machine_block.png", "storagetest_machine_block.png", "storagetest_machine_block.png", + "storagetest_machine_block.png", "storagetest_machine_block.png", "storagetest_import.png", + }, + paramtype2 = "facedir", + is_ground_content = false, + groups = { + storagetest_distributor = 1, + storagetest_device = 1, + cracky = 2, + oddly_breakable_by_hand = 2 + }, + on_construct = function (pos) + storagetest.network.clear_networks(pos) + end, + on_destruct = storagetest.network.clear_networks, + storagetest_run = function (pos, _, controller) + local network = minetest.hash_node_position(controller) + local node = minetest.get_node(pos) + local front = storagetest.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() + local front_def = minetest.registered_nodes[front_node.name] + if front_inv:get_list("main") then + local list = front_inv:get_list("main") + for index, stack in pairs(list) do + if not stack:is_empty() then + local allow_count = 0 + local copystack = front_inv:get_stack("main", index) + copystack:set_count(1) + local success, outst = storagetest.network.insert_item(network, copystack) + 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 + end + end + front_inv:set_list("main", list) + end + end + end +}) + +storagetest.devices["storagetest:import_bus"] = true diff --git a/nodes/common.lua b/nodes/common.lua index f6cc873..f6888e7 100644 --- a/nodes/common.lua +++ b/nodes/common.lua @@ -28,3 +28,11 @@ function storagetest.helpers.grid_refresh(pos, n, controller) storagetest.helpers.swap_node(pos, node) end end + +function storagetest.front(pos, fd) + local front = minetest.facedir_to_dir(fd) + front.x = front.x * -1 + pos.x + front.y = front.y * -1 + pos.y + front.z = front.z * -1 + pos.z + return front +end