diff options
author | FaceDeer <derksenmobile@gmail.com> | 2017-10-21 22:29:18 -0600 |
---|---|---|
committer | FaceDeer <derksenmobile@gmail.com> | 2017-10-21 22:29:18 -0600 |
commit | 94ccab9c391f0a08e9382220112a9546a108d3fd (patch) | |
tree | f5dab01bbf6e1e277694f190cb48518600499a87 /nodes | |
parent | e93ff0595617ebfb7b4498519538c38787a9aa16 (diff) |
add automation option to item ejector
Diffstat (limited to 'nodes')
-rw-r--r-- | nodes/node_battery_holder.lua | 8 | ||||
-rw-r--r-- | nodes/node_builders.lua | 10 | ||||
-rw-r--r-- | nodes/node_crate.lua | 19 | ||||
-rw-r--r-- | nodes/node_diggers.lua | 17 | ||||
-rw-r--r-- | nodes/node_item_ejector.lua | 172 | ||||
-rw-r--r-- | nodes/node_storage.lua | 21 |
6 files changed, 179 insertions, 68 deletions
diff --git a/nodes/node_battery_holder.lua b/nodes/node_battery_holder.lua index 6bd4fc3..56e0cd8 100644 --- a/nodes/node_battery_holder.lua +++ b/nodes/node_battery_holder.lua @@ -6,8 +6,7 @@ local S, NS = dofile(MP.."/intllib.lua") -- Battery storage. Controller node draws electrical power from here. -- Note that batttery boxes are digtron group 7. -local battery_holder_formspec = - "size[8,9.3]" .. +local battery_holder_formspec_string = "size[8,9.3]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots .. @@ -19,6 +18,9 @@ local battery_holder_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) +local battery_holder_formspec = function(pos, meta) + return battery_holder_formspec_string +end local holder_groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 7, tubedevice = 1, tubedevice_receiver = 1} if not minetest.get_modpath("technic") then @@ -50,7 +52,7 @@ minetest.register_node("digtron:battery_holder", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", battery_holder_formspec) + meta:set_string("formspec", battery_holder_formspec(pos, meta)) local inv = meta:get_inventory() inv:set_size("batteries", 8*4) end, diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index ecb76cd..63d780c 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -9,7 +9,7 @@ if minetest.get_modpath("doc") then displace_due_to_help_button = 0.0 end -local builder_formspec = +local builder_formspec_string = "size[8,5.2]" .. default.gui_bg .. default.gui_bg_img .. @@ -35,11 +35,15 @@ local builder_formspec = "listring[current_name;main]" if minetest.get_modpath("doc") then - builder_formspec = builder_formspec .. + builder_formspec_string = builder_formspec_string .. "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block") .. "]" end +local builder_formspec = function(pos, meta) + return builder_formspec_string +end + -- Builds objects in the targeted node. This is a complicated beastie. minetest.register_node("digtron:builder", { description = S("Digtron Builder Module"), @@ -84,7 +88,7 @@ minetest.register_node("digtron:builder", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", builder_formspec) + meta:set_string("formspec", builder_formspec(pos, meta)) meta:set_int("period", 1) meta:set_int("offset", 0) meta:set_int("build_facing", 0) diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index 101d7bb..dc035b2 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -62,10 +62,10 @@ minetest.register_node("digtron:empty_crate", { end, }) -local loaded_formspec - -if minetest.get_modpath("doc") then - loaded_formspec = +local modpath_doc = minetest.get_modpath("doc") +local loaded_formspec_string +if modpath_doc then + loaded_formspec_string = "size[4.1,1.5]" .. default.gui_bg .. default.gui_bg_img .. @@ -80,7 +80,7 @@ if minetest.get_modpath("doc") then "button_exit[3.0,1.2;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block") .. "]" else - loaded_formspec = + loaded_formspec_string = "size[4,1.5]" .. default.gui_bg .. default.gui_bg_img .. @@ -94,6 +94,11 @@ else "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" end + +local loaded_formspec = function(pos, meta) + return loaded_formspec_string +end + minetest.register_node("digtron:loaded_crate", { description = S("Digtron Crate (Loaded)"), _doc_items_longdesc = digtron.doc.loaded_crate_longdesc, @@ -107,7 +112,7 @@ minetest.register_node("digtron:loaded_crate", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", loaded_formspec) + meta:set_string("formspec", loaded_formspec(pos, meta)) end, on_receive_fields = function(pos, formname, fields, sender) @@ -202,7 +207,7 @@ minetest.register_node("digtron:loaded_crate", { meta:set_string("crated_layout", deserialized.layout) meta:set_string("title", deserialized.title) meta:set_string("infotext", deserialized.title) - meta:set_string("formspec", loaded_formspec) + --meta:set_string("formspec", loaded_formspec(pos, meta)) -- not needed, on_construct handles this itemstack:take_item(1) return itemstack diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua index 5b6874d..26de586 100644 --- a/nodes/node_diggers.lua +++ b/nodes/node_diggers.lua @@ -25,8 +25,9 @@ local dual_digger_nodebox = { {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}, -- Lower_Cutter_2 } -local intermittent_formspec = - default.gui_bg .. +local modpath_doc = minetest.get_modpath("doc") + +local intermittent_formspec_string = default.gui_bg .. default.gui_bg_img .. default.gui_slots .. "field[0.5,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. @@ -36,17 +37,21 @@ local intermittent_formspec = "button_exit[2.2,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" -if minetest.get_modpath("doc") then - intermittent_formspec = "size[4.5,1]" .. intermittent_formspec .. +if modpath_doc then + intermittent_formspec_string = "size[4.5,1]" .. intermittent_formspec_string .. "button_exit[3.2,0.5;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block") .. "]" else - intermittent_formspec = "size[3.5,1]" .. intermittent_formspec + intermittent_formspec_string = "size[3.5,1]" .. intermittent_formspec_string end +local intermittent_formspec = function(pos, meta) + return intermittent_formspec_string +end + local intermittent_on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", intermittent_formspec) + meta:set_string("formspec", intermittent_formspec(pos, meta)) meta:set_int("period", 1) meta:set_int("offset", 0) end diff --git a/nodes/node_item_ejector.lua b/nodes/node_item_ejector.lua index c29002f..6f9c64e 100644 --- a/nodes/node_item_ejector.lua +++ b/nodes/node_item_ejector.lua @@ -2,13 +2,111 @@ local MP = minetest.get_modpath(minetest.get_current_modname()) local S, NS = dofile(MP.."/intllib.lua") +--Build up the formspec, somewhat complicated due to multiple mod options local pipeworks_path = minetest.get_modpath("pipeworks") +local doc_path = minetest.get_modpath("doc") +local formspec_width = 1.5 + +local ejector_formspec_string = + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots + +if doc_path then + ejector_formspec_string = ejector_formspec_string .. + "button_exit[".. 0.2 + formspec_width ..",0.5;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block") .. "]" + formspec_width = formspec_width + 1.5 +end + +local ejector_formspec_string = "size[".. formspec_width .. ",1]" .. ejector_formspec_string + +local ejector_formspec = function(pos, meta) + local return_string = ejector_formspec_string + if pipeworks_path then + return_string = return_string .. "checkbox[0,0.5;nonpipe;"..S("Eject into world")..";"..meta:get_string("nonpipe").."]" .. + "tooltip[nonpipe;" .. S("When checked, will eject items even if there's no pipe to accept it") .. "]" + end + return return_string .. "checkbox[0,0;autoeject;"..S("Automatic")..";"..meta:get_string("autoeject").."]" .. + "tooltip[autoeject;" .. S("When checked, will eject items automatically with every Digtron cycle.\nItem ejectors can always be operated manually by punching them.") .. "]" +end + +local function eject_items(pos, node, player, eject_even_without_pipeworks) + local dir = minetest.facedir_to_dir(node.param2) + local destination_pos = vector.add(pos, dir) + local destination_node_name = minetest.get_node(destination_pos).name + local destination_node_def = minetest.registered_nodes[destination_node_name] + + if not pipeworks_path then eject_even_without_pipeworks = true end -- if pipeworks is not installed, always eject into world (there's no other option) + + local insert_into_pipe = false + local eject_into_world = false + if pipeworks_path and minetest.get_node_group(destination_node_name, "tubedevice") > 0 then + insert_into_pipe = true + elseif eject_even_without_pipeworks then + if destination_node_def and not destination_node_def.walkable then + eject_into_world = true + else + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + return false + end + else + return false + end + + local layout = DigtronLayout.create(pos, player) + + -- Build a list of all the items that builder nodes want to use. + local filter_items = {} + for _, node_image in pairs(layout.builders) do + filter_items[node_image.meta.inventory.main[1]:get_name()] = true + end + + -- Look through the inventories and find an item that's not on that list. + local source_node = nil + local source_index = nil + local source_stack = nil + for _, node_image in pairs(layout.inventories) do + for index, item_stack in pairs(node_image.meta.inventory.main) do + if item_stack:get_count() > 0 and not filter_items[item_stack:get_name()] then + source_node = node_image + source_index = index + source_stack = item_stack + break + end + end + if source_node then break end + end + + if source_node then + local meta = minetest.get_meta(source_node.pos) + local inv = meta:get_inventory() + + if insert_into_pipe then + local from_pos = vector.add(pos, vector.multiply(dir, 0.5)) + local start_pos = pos + inv:set_stack("main", source_index, nil) + pipeworks.tube_inject_item(from_pos, start_pos, vector.multiply(dir, 1), source_stack, player:get_player_name()) + minetest.sound_play("steam_puff", {gain=0.5, pos=pos}) + return true + elseif eject_into_world then + minetest.add_item(destination_pos, source_stack) + inv:set_stack("main", source_index, nil) + minetest.sound_play("steam_puff", {gain=0.5, pos=pos}) + return true + end + end + + -- couldn't find an item to eject + return false +end minetest.register_node("digtron:inventory_ejector", { description = S("Digtron Inventory Ejector"), _doc_items_longdesc = digtron.doc.inventory_ejector_longdesc, _doc_items_usagehelp = digtron.doc.inventory_ejector_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1, tubedevice = 1}, + _digtron_formspec = ejector_formspec, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 9, tubedevice = 1}, tiles = {"digtron_plate.png", "digtron_plate.png", "digtron_plate.png", "digtron_plate.png", "digtron_plate.png^digtron_output.png", "digtron_plate.png^digtron_output_back.png"}, drawtype = "nodebox", sounds = digtron.metal_sounds, @@ -24,57 +122,43 @@ minetest.register_node("digtron:inventory_ejector", { } }, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("autoeject", "true") + meta:set_string("formspec", ejector_formspec(pos, meta)) + end, + tube = (function() if pipeworks_path then return { connect_sides = {back = 1} } end end)(), - on_rightclick = function(pos, node, player) - local dir = minetest.facedir_to_dir(node.param2) - local destination_pos = vector.add(pos, dir) - local destination_node_name = minetest.get_node(destination_pos).name - local destination_node_def = minetest.registered_nodes[destination_node_name] - local layout = DigtronLayout.create(pos, player) - - -- Build a list of all the items that builder nodes want to use. - local filter_items = {} - for _, node_image in pairs(layout.builders) do - filter_items[node_image.meta.inventory.main[1]:get_name()] = true + on_punch = function(pos, node, player) + eject_items(pos, node, player, true) + end, + + execute_eject = function(pos, node, player) + local meta = minetest.get_meta(pos) + eject_items(pos, node, player, meta:get_string("nonpipe") == "true") + end, + + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built + local node_name = minetest.get_node(pos).name + minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true) end - -- Look through the inventories and find an item that's not on that list. - local source_node = nil - local source_index = nil - local source_stack = nil - for _, node_image in pairs(layout.inventories) do - for index, item_stack in pairs(node_image.meta.inventory.main) do - if item_stack:get_count() > 0 and not filter_items[item_stack:get_name()] then - source_node = node_image - source_index = index - source_stack = item_stack - break - end - end - if source_node then break end + if fields.nonpipe then + meta:set_string("nonpipe", fields.nonpipe) end - if source_node then - local meta = minetest.get_meta(source_node.pos) - local inv = meta:get_inventory() - - if pipeworks_path and minetest.get_node_group(destination_node_name, "tubedevice") > 0 then - local from_pos = vector.add(pos, vector.multiply(dir, 0.5)) - local start_pos = pos--vector.add(pos, dir) - inv:set_stack("main", source_index, nil) - pipeworks.tube_inject_item(from_pos, start_pos, vector.multiply(dir, 1), source_stack, player:get_player_name()) - minetest.sound_play("steam_puff", {gain=0.5, pos=pos}) - elseif destination_node_def and not destination_node_def.walkable then - minetest.add_item(destination_pos, source_stack) - inv:set_stack("main", source_index, nil) - minetest.sound_play("steam_puff", {gain=0.5, pos=pos}) - else - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) - end - end + if fields.autoeject then + meta:set_string("autoeject", fields.autoeject) + end + + meta:set_string("formspec", ejector_formspec(pos, meta)) + end, after_place_node = (function() if pipeworks_path then return pipeworks.after_place end end)(), diff --git a/nodes/node_storage.lua b/nodes/node_storage.lua index 123104e..9a52c1a 100644 --- a/nodes/node_storage.lua +++ b/nodes/node_storage.lua @@ -4,7 +4,7 @@ local S, NS = dofile(MP.."/intllib.lua") local pipeworks_path = minetest.get_modpath("pipeworks") -local inventory_formspec = +local inventory_formspec_string = "size[8,9.3]" .. default.gui_bg .. default.gui_bg_img .. @@ -17,6 +17,10 @@ local inventory_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) +local inventory_formspec = function(pos, meta) + return inventory_formspec_string +end + -- Storage buffer. Builder nodes draw from this inventory and digger nodes deposit into it. -- Note that inventories are digtron group 2. minetest.register_node("digtron:inventory", { @@ -42,7 +46,7 @@ minetest.register_node("digtron:inventory", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", inventory_formspec) + meta:set_string("formspec", inventory_formspec(pos, meta)) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, @@ -75,7 +79,7 @@ minetest.register_node("digtron:inventory", { after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) -local fuelstore_formspec = +local fuelstore_formspec_string = "size[8,9.3]" .. default.gui_bg .. default.gui_bg_img .. @@ -88,6 +92,10 @@ local fuelstore_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) +local fuelstore_formspec = function(pos, meta) + return fuelstore_formspec_string +end + -- Fuel storage. Controller node draws fuel from here. -- Note that fuel stores are digtron group 5. minetest.register_node("digtron:fuelstore", { @@ -164,7 +172,7 @@ minetest.register_node("digtron:fuelstore", { after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) -local combined_storage_formspec = +local combined_storage_formspec_string = "size[8,9.9]" .. default.gui_bg .. default.gui_bg_img .. @@ -179,6 +187,9 @@ local combined_storage_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.75) +local combined_storage_formspec = function(pos, meta) + return combined_storage_formspec_string +end -- Combined storage. Group 6 has both an inventory and a fuel store minetest.register_node("digtron:combined_storage", { @@ -202,7 +213,7 @@ minetest.register_node("digtron:combined_storage", { }, on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", combined_storage_formspec) + meta:set_string("formspec", combined_storage_formspec(pos, meta)) local inv = meta:get_inventory() inv:set_size("main", 8*3) inv:set_size("fuel", 8*1) |