From 15b327c842ebe4189ceae16a419dce974c8b2451 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Mon, 11 Sep 2017 23:47:25 -0600 Subject: move node defs and recipes into a subfolder --- init.lua | 16 +- node_axle.lua | 64 ------ node_builders.lua | 334 -------------------------------- node_controllers.lua | 345 --------------------------------- node_crate.lua | 193 ------------------ node_diggers.lua | 473 --------------------------------------------- node_misc.lua | 141 -------------- node_storage.lua | 276 -------------------------- nodes/node_axle.lua | 64 ++++++ nodes/node_builders.lua | 334 ++++++++++++++++++++++++++++++++ nodes/node_controllers.lua | 345 +++++++++++++++++++++++++++++++++ nodes/node_crate.lua | 193 ++++++++++++++++++ nodes/node_diggers.lua | 473 +++++++++++++++++++++++++++++++++++++++++++++ nodes/node_misc.lua | 141 ++++++++++++++ nodes/node_storage.lua | 276 ++++++++++++++++++++++++++ nodes/recipes.lua | 283 +++++++++++++++++++++++++++ recipes.lua | 283 --------------------------- 17 files changed, 2117 insertions(+), 2117 deletions(-) delete mode 100644 node_axle.lua delete mode 100644 node_builders.lua delete mode 100644 node_controllers.lua delete mode 100644 node_crate.lua delete mode 100644 node_diggers.lua delete mode 100644 node_misc.lua delete mode 100644 node_storage.lua create mode 100644 nodes/node_axle.lua create mode 100644 nodes/node_builders.lua create mode 100644 nodes/node_controllers.lua create mode 100644 nodes/node_crate.lua create mode 100644 nodes/node_diggers.lua create mode 100644 nodes/node_misc.lua create mode 100644 nodes/node_storage.lua create mode 100644 nodes/recipes.lua delete mode 100644 recipes.lua diff --git a/init.lua b/init.lua index c01692e..4483d42 100644 --- a/init.lua +++ b/init.lua @@ -11,14 +11,14 @@ dofile( minetest.get_modpath( "digtron" ) .. "/awards.lua" ) dofile( minetest.get_modpath( "digtron" ) .. "/class_pointset.lua" ) dofile( minetest.get_modpath( "digtron" ) .. "/class_layout.lua" ) dofile( minetest.get_modpath( "digtron" ) .. "/entities.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/node_misc.lua" ) -- contains structure and light nodes -dofile( minetest.get_modpath( "digtron" ) .. "/node_storage.lua" ) -- contains inventory and fuel storage nodes -dofile( minetest.get_modpath( "digtron" ) .. "/node_diggers.lua" ) -- contains all diggers -dofile( minetest.get_modpath( "digtron" ) .. "/node_builders.lua" ) -- contains all builders (there's just one currently) -dofile( minetest.get_modpath( "digtron" ) .. "/node_controllers.lua" ) -- controllers -dofile( minetest.get_modpath( "digtron" ) .. "/node_axle.lua" ) -- Rotation controller -dofile( minetest.get_modpath( "digtron" ) .. "/node_crate.lua" ) -- Digtron portability support -dofile( minetest.get_modpath( "digtron" ) .. "/recipes.lua" ) +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_misc.lua" ) -- contains structure and light nodes +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_storage.lua" ) -- contains inventory and fuel storage nodes +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_diggers.lua" ) -- contains all diggers +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_builders.lua" ) -- contains all builders (there's just one currently) +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_controllers.lua" ) -- controllers +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_axle.lua" ) -- Rotation controller +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_crate.lua" ) -- Digtron portability support +dofile( minetest.get_modpath( "digtron" ) .. "/nodes/recipes.lua" ) -- digtron group numbers: -- 1 - generic digtron node, nothing special is done with these. They're just dragged along. diff --git a/node_axle.lua b/node_axle.lua deleted file mode 100644 index 8726ab8..0000000 --- a/node_axle.lua +++ /dev/null @@ -1,64 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - -minetest.register_node("digtron:axle", { - description = S("Digtron Rotation Axle"), - _doc_items_longdesc = digtron.doc.axle_longdesc, - _doc_items_usagehelp = digtron.doc.axle_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:axle", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^digtron_axel_top.png", - "digtron_plate.png^digtron_axel_top.png", - "digtron_plate.png^digtron_axel_side.png", - "digtron_plate.png^digtron_axel_side.png", - "digtron_plate.png^digtron_axel_side.png", - "digtron_plate.png^digtron_axel_side.png", - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.5, 0.3125, -0.3125, 0.5, 0.5, 0.3125}, -- Uppercap - {-0.5, -0.5, -0.3125, 0.5, -0.3125, 0.3125}, -- Lowercap - {-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, -- Uppercap_edge2 - {-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, -- Uppercap_edge1 - {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, -- Lowercap_edge1 - {-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, -- Lowercap_edge2 - {-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle - } - }, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - if meta:get_string("waiting") == "true" then - -- Been too soon since last time the digtron rotated. - return - end - local image = DigtronLayout.create(pos, clicker) - image:rotate_layout_image(node.param2) - if image:can_write_layout_image() then - image:write_layout_image(clicker) - - minetest.sound_play("whirr", {gain=1.0, pos=pos}) - meta = minetest.get_meta(pos) - meta:set_string("waiting", "true") - meta:set_string("infotext", nil) - minetest.get_node_timer(pos):start(digtron.cycle_time*2) - else - minetest.sound_play("buzzer", {gain=1.0, pos=pos}) - meta:set_string("infotext", S("Digtron is obstructed.")) - end - end, - - on_timer = function(pos, elapsed) - minetest.get_meta(pos):set_string("waiting", nil) - end, -}) \ No newline at end of file diff --git a/node_builders.lua b/node_builders.lua deleted file mode 100644 index 424eb67..0000000 --- a/node_builders.lua +++ /dev/null @@ -1,334 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - --- Note: builders go in group 4 and have both test_build and execute_build methods. - -local builder_formspec = nil - -if minetest.get_modpath("doc") then - builder_formspec = "size[8,5.2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0,0;1,1;]" .. - "label[0,0.8;" .. S("Block to build") .. "]" .. - "field[1.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. - "field[2.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. - "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. - "field[3.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. - "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. - "button_exit[4.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. - "tooltip[set;" .. S("Saves settings") .. "]" .. - "field[5.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. - "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. - "button_exit[6.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. - "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. - "list[current_player;main;0,1.3;8,1;]" .. - default.get_hotbar_bg(0,1.3) .. - "list[current_player;main;0,2.5;8,3;8]" .. - "listring[current_player;main]" .. - "listring[current_name;main]" .. - "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. - "tooltip[help;" .. S("Show documentation about this block") .. "]" -else - builder_formspec = "size[8,5.2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0.5,0;1,1;]" .. - "label[0.5,0.8;" .. S("Block to build") .. "]" .. - "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. - "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. - "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. - "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. - "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. - "button_exit[5.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. - "tooltip[set;" .. S("Saves settings") .. "]" .. - "field[6.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. - "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. - "button_exit[7.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. - "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. - "list[current_player;main;0,1.3;8,1;]" .. - default.get_hotbar_bg(0,1.3) .. - "list[current_player;main;0,2.5;8,3;8]" .. - "listring[current_player;main]" .. - "listring[current_name;main]" -end - --- Builds objects in the targeted node. This is a complicated beastie. -minetest.register_node("digtron:builder", { - description = S("Digtron Builder Module"), - _doc_items_longdesc = digtron.doc.builder_longdesc, - _doc_items_usagehelp = digtron.doc.builder_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 4}, - drop = "digtron:builder", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - tiles = { - "digtron_plate.png^[transformR90", - "digtron_plate.png^[transformR270", - "digtron_plate.png", - "digtron_plate.png^[transformR180", - "digtron_plate.png^digtron_builder.png", - "digtron_plate.png", - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.25, 0.3125, 0.3125, 0.25, 0.5, 0.5}, -- FrontFrame_top - {-0.25, -0.5, 0.3125, 0.25, -0.3125, 0.5}, -- FrontFrame_bottom - {0.3125, -0.25, 0.3125, 0.5, 0.25, 0.5}, -- FrontFrame_right - {-0.5, -0.25, 0.3125, -0.3125, 0.25, 0.5}, -- FrontFrame_left - {-0.5, 0.25, -0.5, -0.25, 0.5, 0.5}, -- edge_topright - {-0.5, -0.5, -0.5, -0.25, -0.25, 0.5}, -- edge_bottomright - {0.25, 0.25, -0.5, 0.5, 0.5, 0.5}, -- edge_topleft - {0.25, -0.5, -0.5, 0.5, -0.25, 0.5}, -- edge_bottomleft - {-0.25, 0.4375, -0.5, 0.25, 0.5, -0.4375}, -- backframe_top - {-0.25, -0.5, -0.5, 0.25, -0.4375, -0.4375}, -- backframe_bottom - {-0.5, -0.25, -0.5, -0.4375, 0.25, -0.4375}, -- backframe_left - {0.4375, -0.25, -0.5, 0.5, 0.25, -0.4375}, -- Backframe_right - {-0.0625, -0.3125, 0.3125, 0.0625, 0.3125, 0.375}, -- frontcross_vertical - {-0.3125, -0.0625, 0.3125, 0.3125, 0.0625, 0.375}, -- frontcross_horizontal - } - }, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", builder_formspec) - meta:set_int("period", 1) - meta:set_int("offset", 0) - meta:set_int("build_facing", 0) - meta:set_int("extrusion", 1) - - local inv = meta:get_inventory() - inv:set_size("main", 1) - end, - - on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos) - local period = tonumber(fields.period) - local offset = tonumber(fields.offset) - local build_facing = tonumber(fields.build_facing) - local extrusion = tonumber(fields.extrusion) - - if period and period > 0 then - meta:set_int("period", math.floor(tonumber(fields.period))) - else - period = meta:get_int("period") - end - if offset then - meta:set_int("offset", math.floor(tonumber(fields.offset))) - else - offset = meta:get_int("offset") - end - if build_facing and build_facing >= 0 and build_facing < 24 then - -- TODO: wallmounted facings only run from 0-5, a player could theoretically put a wallmounted item into the builder and then manually set the build facing to an invalid number - -- Should prevent that somehow. But not tonight. - meta:set_int("build_facing", math.floor(build_facing)) - end - if extrusion and extrusion > 0 and extrusion <= digtron.maximum_extrusion then - meta:set_int("extrusion", math.floor(tonumber(fields.extrusion))) - else - extrusion = meta:get_int("extrusion") - end - - if fields.set then - local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2) - local x_pos = math.floor((buildpos.x+offset)/period)*period - offset - minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker") - if x_pos >= buildpos.x then - minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker") - end - if x_pos <= buildpos.x then - minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker") - end - - local y_pos = math.floor((buildpos.y+offset)/period)*period - offset - minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical") - if y_pos >= buildpos.y then - minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical") - end - if y_pos <= buildpos.y then - minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical") - end - - local z_pos = math.floor((buildpos.z+offset)/period)*period - offset - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708) - if z_pos >= buildpos.z then - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708) - end - if z_pos <= buildpos.z then - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708) - end - - elseif fields.read then - local meta = minetest.get_meta(pos) - local facing = minetest.get_node(pos).param2 - local buildpos = digtron.find_new_pos(pos, facing) - meta:set_int("build_facing", minetest.get_node(buildpos).param2) - end - - if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built - minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:builder", true) - end - - digtron.update_builder_item(pos) - end, - - on_destruct = function(pos) - digtron.remove_builder_item(pos) - end, - - after_place_node = function(pos) - digtron.update_builder_item(pos) - end, - - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then - return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output. - end - local inv = minetest.get_inventory({type="node", pos=pos}) - inv:set_stack(listname, index, stack:take_item(1)) - return 0 - end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local inv = minetest.get_inventory({type="node", pos=pos}) - inv:set_stack(listname, index, ItemStack("")) - return 0 - end, - - -- "builder at pos, imagine that you're in test_pos. If you're willing and able to build from there, take the item you need from inventory. - -- return the item you took and the inventory location you took it from so it can be put back after all the other builders have been tested. - -- If you couldn't get the item from inventory, return an error code so we can abort the cycle. - -- If you're not supposed to build at all, or the location is obstructed, return 0 to let us know you're okay and we shouldn't abort." - - --return code and accompanying value: - -- 0, {} -- not supposed to build, no error - -- 1, {{itemstack, source inventory pos}, ...} -- can build, took items from inventory - -- 2, {{itemstack, source inventory pos}, ...}, itemstack -- was supposed to build, but couldn't get the item from inventory - -- 3, {} -- builder configuration error - test_build = function(pos, test_pos, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) - local meta = minetest.get_meta(pos) - local facing = minetest.get_node(pos).param2 - local buildpos = digtron.find_new_pos(test_pos, facing) - - if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then - --It's not the builder's turn to build right now. - return 0, {} - end - - local extrusion_count = 0 - local extrusion_target = meta:get_int("extrusion") - if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then - extrusion_target = 1 -- failsafe - end - - local return_items = {} - - local inv = minetest.get_inventory({type="node", pos=pos}) - local item_stack = inv:get_stack("main", 1) - - if item_stack:is_empty() then - return 3, {} -- error code for "this builder's item slot is unset" - end - - while extrusion_count < extrusion_target do - if not digtron.can_move_to(buildpos, protected_nodes, nodes_dug) then - --using "can_move_to" instead of "can_build_to" test case in case the builder is pointed "backward", and will thus - --be building into the space that it's currently in and will be vacating after moving, or in case the builder is aimed - --sideways and a fellow digtron node was ahead of it (will also be moving out of the way). - - --If the player has built his digtron stupid (eg has another digtron node in the place the builder wants to build) this - --assumption is wrong, but I can't hold the player's hand through *every* possible bad design decision. Worst case, - --the digtron will think its inventory can't handle the next build step and abort the build when it actually could have - --managed one more cycle. That's not a bad outcome for a digtron array that was built stupidly to begin with. - return 1, return_items - end - - local source_location = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) - if source_location ~= nil then - table.insert(return_items, {item=item_stack, location=source_location}) - else - return 2, return_items, item_stack -- error code for "needed an item but couldn't get it from inventory" - end - extrusion_count = extrusion_count + 1 - buildpos = digtron.find_new_pos(buildpos, facing) - end - - return 1, return_items - end, - - execute_build = function(pos, player, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) - local meta = minetest.get_meta(pos) - local build_facing = tonumber(meta:get_int("build_facing")) - local facing = minetest.get_node(pos).param2 - local buildpos = digtron.find_new_pos(pos, facing) - - if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then - return 0 - end - - local extrusion_count = 0 - local extrusion_target = meta:get_int("extrusion") - if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then - extrusion_target = 1 -- failsafe - end - local built_count = 0 - - local inv = minetest.get_inventory({type="node", pos=pos}) - local item_stack = inv:get_stack("main", 1) - if item_stack:is_empty() then - return built_count - end - - while extrusion_count < extrusion_target do - if not digtron.can_build_to(buildpos, protected_nodes, nodes_dug) then - return built_count - end - - local oldnode = minetest.get_node(buildpos) - - if digtron.creative_mode then - local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) - if success == true then - minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) - nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) - built_count = built_count + 1 - else - return built_count - end - end - - local sourcepos = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) - if sourcepos == nil then - -- item not in inventory! Need to sound the angry buzzer to let the player know, so return a negative number. - return (built_count + 1) * -1 - end - local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) - if success == true then - minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) - --flag this node as *not* to be dug. - nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) - digtron.award_item_built(item_stack:get_name(), player:get_player_name()) - built_count = built_count + 1 - else - --failed to build, target node probably obstructed. Put the item back in inventory. - --Should probably never reach this since we're guarding against can_build_to, above, but this makes things safe if we somehow do. - digtron.place_in_specific_inventory(item_stack, sourcepos, inventory_positions, controller_pos) - return built_count - end - - extrusion_count = extrusion_count + 1 - buildpos = digtron.find_new_pos(buildpos, facing) - end - return built_count - end, -}) \ No newline at end of file diff --git a/node_controllers.lua b/node_controllers.lua deleted file mode 100644 index a09cfbe..0000000 --- a/node_controllers.lua +++ /dev/null @@ -1,345 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - -local controller_nodebox ={ - {-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core - {-0.1875, 0.3125, -0.1875, 0.1875, 0.5, 0.1875}, -- +y_connector - {-0.1875, -0.5, -0.1875, 0.1875, -0.3125, 0.1875}, -- -y_Connector - {0.3125, -0.1875, -0.1875, 0.5, 0.1875, 0.1875}, -- +x_connector - {-0.5, -0.1875, -0.1875, -0.3125, 0.1875, 0.1875}, -- -x_connector - {-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- +z_connector - {-0.5, 0.125, -0.5, -0.125, 0.5, -0.3125}, -- back_connector_3 - {0.125, 0.125, -0.5, 0.5, 0.5, -0.3125}, -- back_connector_1 - {0.125, -0.5, -0.5, 0.5, -0.125, -0.3125}, -- back_connector_2 - {-0.5, -0.5, -0.5, -0.125, -0.125, -0.3125}, -- back_connector_4 -} - --- Master controller. Most complicated part of the whole system. Determines which direction a digtron moves and triggers all of its component parts. -minetest.register_node("digtron:controller", { - description = S("Digtron Control Module"), - _doc_items_longdesc = digtron.doc.controller_longdesc, - _doc_items_usagehelp = digtron.doc.controller_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1}, - drop = "digtron:controller", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90", - "digtron_plate.png^[transformR270", - "digtron_plate.png", - "digtron_plate.png^[transformR180", - "digtron_plate.png", - "digtron_plate.png^digtron_control.png", - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = controller_nodebox, - }, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_float("fuel_burning", 0.0) - meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) - end, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - if meta:get_string("waiting") == "true" then - -- Been too soon since last time the digtron did a cycle. - return - end - - local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker) - - meta = minetest.get_meta(newpos) - if status ~= nil then - meta:set_string("infotext", status) - end - - -- Start the delay before digtron can run again. - minetest.get_meta(newpos):set_string("waiting", "true") - minetest.get_node_timer(newpos):start(digtron.cycle_time) - end, - - on_timer = function(pos, elapsed) - minetest.get_meta(pos):set_string("waiting", nil) - end, -}) - --- Auto-controller ---------------------------------------------------------------------------------------------------------------- - -local auto_formspec = "size[8,6.2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "container[2.0,0]" .. - "field[0.0,0.8;1,0.1;cycles;" .. S("Cycles").. ";${cycles}]" .. - "tooltip[cycles;" .. S("When triggered, this controller will try to run for the given number of cycles.\nThe cycle count will decrement as it runs, so if it gets halted by a problem\nyou can fix the problem and restart.").. "]" .. - "button_exit[0.7,0.5;1,0.1;set;" .. S("Set").. "]" .. - "tooltip[set;" .. S("Saves the cycle setting without starting the controller running").. "]" .. - "button_exit[1.7,0.5;1,0.1;execute;" .. S("Set &\nExecute").. "]" .. - "tooltip[execute;" .. S("Begins executing the given number of cycles").. "]" .. - "field[0.0,2.0;1,0.1;slope;" .. S("Slope").. ";${slope}]" .. - "tooltip[slope;" .. S("For diagonal digging. After moving forward this number of nodes the auto controller\nwill add an additional cycle moving the digtron laterally in the\ndirection of the arrows on the side of this controller.\nSet to 0 for no lateral digging.").. "]" .. - "field[1.0,2.0;1,0.1;offset;" .. S("Offset").. ";${offset}]" .. - "tooltip[offset;" .. S("Sets the offset of the lateral motion defined in the Slope field.\nNote: this offset is relative to the controller's location.\nThe controller will move laterally when it reaches the indicated point.").. "]" .. - "field[2.0,2.0;1,0.1;period;" .. S("Delay").. ";${period}]" .. - "tooltip[period;" .. S("Number of seconds to wait between each cycle").. "]" .. - "list[current_name;stop;3.0,0.7;1,1;]" .. - "label[3.0,1.5;" .. S("Stop block").. "]" .. - "container_end[]" .. - "list[current_player;main;0,2.3;8,1;]" .. - default.get_hotbar_bg(0,2.3) .. - "list[current_player;main;0,3.5;8,3;8]" .. - "listring[current_player;main]" .. - "listring[current_name;stop]" - -if minetest.get_modpath("doc") then - auto_formspec = auto_formspec .. - "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. - "tooltip[help;" .. S("Show documentation about this block").. "]" -end - --- Needed to make this global so that it could recurse into minetest.after -digtron.auto_cycle = function(pos) - local node = minetest.get_node(pos) - local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2) - local meta = minetest.get_meta(pos) - local player = minetest.get_player_by_name(meta:get_string("triggering_player")) - if player == nil or meta:get_string("waiting") == "true" then - return - end - - local cycle = meta:get_int("cycles") - local slope = meta:get_int("slope") - - if meta:get_string("lateral_done") ~= "true" and slope ~= 0 and (pos[controlling_coordinate] + meta:get_int("offset")) % slope == 0 then - --Do a downward dig cycle. Don't update the "cycles" count, these don't count towards that. - local newpos, status, return_code = digtron.execute_downward_dig_cycle(pos, player) - - if vector.equals(pos, newpos) then - status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) - meta:set_string("infotext", status) - if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. - minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) - else - meta:set_string("formspec", auto_formspec) - end - else - meta = minetest.get_meta(newpos) - minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) - meta:set_string("infotext", status) - meta:set_string("lateral_done", "true") - end - return - end - - local newpos, status, return_code = digtron.execute_dig_cycle(pos, player) - - if vector.equals(pos, newpos) then - status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) - meta:set_string("infotext", status) - if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. - minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) - else - meta:set_string("formspec", auto_formspec) - end - return - end - - meta = minetest.get_meta(newpos) - cycle = meta:get_int("cycles") - 1 - meta:set_int("cycles", cycle) - status = status .. string.format("\n" .. S("Cycles remaining: %d"), cycle) - meta:set_string("infotext", status) - meta:set_string("lateral_done", nil) - - if cycle > 0 then - minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) - else - meta:set_string("formspec", auto_formspec) - end -end - -minetest.register_node("digtron:auto_controller", { - description = S("Digtron Automatic Control Module"), - _doc_items_longdesc = digtron.doc.auto_controller_longdesc, - _doc_items_usagehelp = digtron.doc.auto_controller_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1}, - drop = "digtron:auto_controller", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90^[colorize:" .. digtron.auto_controller_colorize, - "digtron_plate.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, - "digtron_plate.png^digtron_axel_side.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, - "digtron_plate.png^digtron_axel_side.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, - "digtron_plate.png^[colorize:" .. digtron.auto_controller_colorize, - "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.auto_controller_colorize, - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = controller_nodebox, - }, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_float("fuel_burning", 0.0) - meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) - meta:set_string("formspec", auto_formspec) - -- Reusing offset and period to keep the digtron node-moving code simple, and the names still fit well - meta:set_int("period", digtron.cycle_time) - meta:set_int("offset", 0) - meta:set_int("cycles", 0) - meta:set_int("slope", 0) - - local inv = meta:get_inventory() - inv:set_size("stop", 1) - end, - - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then - return 0 -- pointless setting a Digtron node as a stop block - end - local inv = minetest.get_inventory({type="node", pos=pos}) - inv:set_stack(listname, index, stack:take_item(1)) - return 0 - end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local inv = minetest.get_inventory({type="node", pos=pos}) - inv:set_stack(listname, index, ItemStack("")) - return 0 - end, - - on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos) - local offset = tonumber(fields.offset) - local period = tonumber(fields.period) - local slope = tonumber(fields.slope) - local cycles = tonumber(fields.cycles) - - if period and period > 0 then - meta:set_int("period", math.max(digtron.cycle_time, math.floor(period))) - end - - if offset then - meta:set_int("offset", offset) - end - - if slope and slope >= 0 then - meta:set_int("slope", slope) - end - - if cycles and cycles >= 0 then - meta:set_int("cycles", math.floor(cycles)) - if sender:is_player() and cycles > 0 then - meta:set_string("triggering_player", sender:get_player_name()) - if fields.execute then - meta:set_string("waiting", nil) - meta:set_string("formspec", nil) - digtron.auto_cycle(pos) - end - end - end - - if fields.set and slope and slope > 0 then - local node = minetest.get_node(pos) - local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2) - - local newpos = pos - local markerpos = {x=newpos.x, y=newpos.y, z=newpos.z} - local x_pos = math.floor((newpos[controlling_coordinate]+offset)/slope)*slope - offset - markerpos[controlling_coordinate] = x_pos - minetest.add_entity(markerpos, "digtron:marker_vertical") - if x_pos >= newpos[controlling_coordinate] then - markerpos[controlling_coordinate] = x_pos - slope - minetest.add_entity(markerpos, "digtron:marker_vertical") - end - if x_pos <= newpos[controlling_coordinate] then - markerpos[controlling_coordinate] = x_pos + slope - minetest.add_entity(markerpos, "digtron:marker_vertical") - end - end - - if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built - minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:auto_controller", true) - end - end, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Interrupted!")) - meta:set_string("waiting", "true") - meta:set_string("formspec", auto_formspec) - end, - - on_timer = function(pos, elapsed) - minetest.get_meta(pos):set_string("waiting", nil) - end, - -}) - ---------------------------------------------------------------------------------------------------------------- - --- A much simplified control unit that only moves the digtron, and doesn't trigger the diggers or builders. --- Handy for shoving a digtron to the side if it's been built a bit off. -minetest.register_node("digtron:pusher", { - description = S("Digtron Pusher Module"), - _doc_items_longdesc = digtron.doc.pusher_longdesc, - _doc_items_usagehelp = digtron.doc.pusher_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:pusher", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90^[colorize:" .. digtron.pusher_controller_colorize, - "digtron_plate.png^[transformR270^[colorize:" .. digtron.pusher_controller_colorize, - "digtron_plate.png^[colorize:" .. digtron.pusher_controller_colorize, - "digtron_plate.png^[transformR180^[colorize:" .. digtron.pusher_controller_colorize, - "digtron_plate.png^[colorize:" .. digtron.pusher_controller_colorize, - "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.pusher_controller_colorize, - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = controller_nodebox, - }, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - if meta:get_string("waiting") == "true" then - -- Been too soon since last time the digtron did a cycle. - return - end - - local newpos, status_text, return_code = digtron.execute_move_cycle(pos, clicker) - meta = minetest.get_meta(newpos) - meta:set_string("infotext", status_text) - - -- Start the delay before digtron can run again. - minetest.get_meta(newpos):set_string("waiting", "true") - minetest.get_node_timer(newpos):start(digtron.cycle_time) - end, - - on_timer = function(pos, elapsed) - minetest.get_meta(pos):set_string("waiting", nil) - end, - -}) \ No newline at end of file diff --git a/node_crate.lua b/node_crate.lua deleted file mode 100644 index 017023d..0000000 --- a/node_crate.lua +++ /dev/null @@ -1,193 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - -minetest.register_node("digtron:empty_crate", { - description = S("Digtron Crate (Empty)"), - _doc_items_longdesc = digtron.doc.empty_crate_longdesc, - _doc_items_usagehelp = digtron.doc.empty_crate_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3}, - drop = "digtron:empty_crate", - sounds = default.node_sound_wood_defaults(), - tiles = {"digtron_crate.png"}, - is_ground_content = false, - drawtype = "nodebox", - paramtype = "light", - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local layout = DigtronLayout.create(pos, clicker) - if layout.contains_protected_node then - local meta = minetest.get_meta(pos) - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) - meta:set_string("infotext", S("Digtron can't be packaged, it contains protected blocks")) - -- no stealing other peoples' digtrons - return - end - - digtron.award_crate(layout, clicker:get_player_name()) - - local layout_string = layout:serialize() - - -- destroy everything. Note that this includes the empty crate, which will be bundled up with the layout. - for _, node_image in pairs(layout.all) do - minetest.remove_node(node_image.pos) - end - - -- Create the loaded crate node - minetest.set_node(pos, {name="digtron:loaded_crate", param1=node.param1, param2=node.param2}) - minetest.sound_play("machine1", {gain=1.0, pos=pos}) - - local meta = minetest.get_meta(pos) - meta:set_string("crated_layout", layout_string) - meta:set_string("title", S("Crated Digtron")) - meta:set_string("infotext", S("Crated Digtron")) - end, -}) - -local loaded_formspec - -if minetest.get_modpath("doc") then - loaded_formspec = - "size[4.1,1.5]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "field[0.3,0.5;4,0.5;title;" .. S("Digtron Name") .. ";${title}]" .. - "button_exit[0.0,1.2;1,0.1;save;" .. S("Save\nTitle") .. "]" .. - "tooltip[save;" .. S("Saves the title of this Digtron") .. "]" .. - "button_exit[1.0,1.2;1,0.1;show;" .. S("Show\nBlocks") .. "]" .. - "tooltip[show;" .. S("Shows which blocks the packed Digtron will occupy if unpacked") .. "]" .. - "button_exit[2.0,1.2;1,0.1;unpack;" .. S("Unpack") .. "]" .. - "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" .. - "button_exit[3.0,1.2;1,0.1;help;" .. S("Help") .. "]" .. - "tooltip[help;" .. S("Show documentation about this block") .. "]" -else - loaded_formspec = - "size[4,1.5]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "field[0.3,0.5;4,0.5;title;" .. S("Digtron Name") .. ";${title}]" .. - "button_exit[0.5,1.2;1,0.1;save;" .. S("Save\nTitle") .. "]" .. - "tooltip[show;" .. S("Saves the title of this Digtron") .. "]" .. - "button_exit[1.5,1.2;1,0.1;show;" .. S("Show\nBlocks") .. "]" .. - "tooltip[save;" .. S("Shows which blocks the packed Digtron will occupy if unpacked") .. "]" .. - "button_exit[2.5,1.2;1,0.1;unpack;" .. S("Unpack") .. "]" .. - "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" -end - -minetest.register_node("digtron:loaded_crate", { - description = S("Digtron Crate (Loaded)"), - _doc_items_longdesc = digtron.doc.loaded_crate_longdesc, - _doc_items_usagehelp = digtron.doc.loaded_crate_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1}, - stack_max = 1, - sounds = default.node_sound_wood_defaults(), - tiles = {"digtron_plate.png^digtron_crate.png"}, - is_ground_content = false, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", loaded_formspec) - end, - - on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos) - - if fields.unpack or fields.save or fields.show then - meta:set_string("title", fields.title) - meta:set_string("infotext", fields.title) - end - - if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built - minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:loaded_crate", true) - end - - if not (fields.unpack or fields.show) then - return - end - - local layout_string = meta:get_string("crated_layout") - local layout = DigtronLayout.deserialize(layout_string) - - if layout == nil then - meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted or lost.")) - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) - -- Something went horribly wrong - return - end - - local protected_node = false - local obstructed_node = false - - local pos_diff = vector.subtract(pos, layout.controller) - layout.controller = pos - for _, node_image in pairs(layout.all) do - node_image.pos = vector.add(pos_diff, node_image.pos) - if not vector.equals(pos, node_image.pos) then - if minetest.is_protected(node_image.pos, sender:get_player_name()) and not minetest.check_player_privs(sender, "protection_bypass") then - protected_node = true - minetest.add_entity(node_image.pos, "digtron:marker_crate_bad") - elseif not minetest.registered_nodes[minetest.get_node(node_image.pos).name].buildable_to then - obstructed_node = true - minetest.add_entity(node_image.pos, "digtron:marker_crate_bad") - else - minetest.add_entity(node_image.pos, "digtron:marker_crate_good") - end - end - end - - if not fields.unpack then - return - end - - if protected_node then - meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to deploy Digtron due to protected blocks in target area")) - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) - return - end - - if obstructed_node then - meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to deploy Digtron due to obstruction in target area")) - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) - return - end - - -- build digtron. Since the empty crate was included in the layout, that will overwrite this loaded crate and destroy it. - minetest.sound_play("machine2", {gain=1.0, pos=pos}) - layout:write_layout_image(sender) - end, - - on_dig = function(pos, node, player) - - local meta = minetest.get_meta(pos) - local to_serialize = {title=meta:get_string("title"), layout=meta:get_string("crated_layout")} - - local stack = ItemStack({name="digtron:loaded_crate", count=1, wear=0, metadata=minetest.serialize(to_serialize)}) - local inv = player:get_inventory() - local stack = inv:add_item("main", stack) - if stack:get_count() > 0 then - minetest.add_item(pos, stack) - end - -- call on_dignodes callback - minetest.remove_node(pos) - end, - - on_place = function(itemstack, placer, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing, true) - local deserialized = minetest.deserialize(itemstack:get_metadata()) - if pos and deserialized then - minetest.set_node(pos, {name="digtron:loaded_crate"}) - local meta = minetest.get_meta(pos) - - 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) - - itemstack:take_item(1) - return itemstack - end - -- after-place callbacks - end, -}) \ No newline at end of file diff --git a/node_diggers.lua b/node_diggers.lua deleted file mode 100644 index c12b46c..0000000 --- a/node_diggers.lua +++ /dev/null @@ -1,473 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - --- Note: diggers go in group 3 and have an execute_dig method. - -local digger_nodebox = { - {-0.5, -0.5, 0, 0.5, 0.5, 0.4375}, -- Block - {-0.4375, -0.3125, 0.4375, 0.4375, 0.3125, 0.5}, -- Cutter1 - {-0.3125, -0.4375, 0.4375, 0.3125, 0.4375, 0.5}, -- Cutter2 - {-0.5, -0.125, -0.125, 0.5, 0.125, 0}, -- BackFrame1 - {-0.125, -0.5, -0.125, 0.125, 0.5, 0}, -- BackFrame2 - {-0.25, -0.25, -0.5, 0.25, 0.25, 0}, -- Drive -} - -local dual_digger_nodebox = { - {-0.5, -0.4375, 0, 0.5, 0.5, 0.4375}, -- Block - {-0.4375, -0.3125, 0.4375, 0.4375, 0.3125, 0.5}, -- Cutter1 - {-0.3125, -0.4375, 0.4375, 0.3125, 0.4375, 0.5}, -- Cutter2 - {-0.5, 0, -0.125, 0.5, 0.125, 0}, -- BackFrame1 - {-0.25, 0, -0.5, 0.25, 0.25, 0}, -- Drive - {-0.25, 0.25, -0.25, 0.25, 0.5, 0}, -- Upper_Drive - {-0.5, -0.4375, -0.5, 0.5, 0, 0.4375}, -- Lower_Block - {-0.3125, -0.5, -0.4375, 0.3125, -0.4375, 0.4375}, -- Lower_Cutter_1 - {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}, -- Lower_Cutter_2 -} - -local intermittent_formspec = - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "field[0.5,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. - "tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" .. - "field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. - "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" .. - "button_exit[2.2,0.5;1,0.1;set;" .. S("Save") .. "]" .. - "tooltip[set;" .. S("Saves settings") .. "]" - -local intermittent_on_construct = function(pos) - local formspec = intermittent_formspec - if minetest.get_modpath("doc") then - formspec = "size[4.5,1]" .. formspec .. - "button_exit[3.2,0.5;1,0.1;help;" .. S("Help") .. "]" .. - "tooltip[help;" .. S("Show documentation about this block") .. "]" - else - formspec = "size[3.5,1]" .. formspec - end - local meta = minetest.get_meta(pos) - meta:set_string("formspec", formspec) - meta:set_int("period", 1) - meta:set_int("offset", 0) -end - -local intermittent_on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.get_meta(pos) - local period = tonumber(fields.period) - local offset = tonumber(fields.offset) - if period and period > 0 then - meta:set_int("period", math.floor(period)) - end - if offset then - meta:set_int("offset", math.floor(offset)) - end - 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 -end, - --- Digs out nodes that are "in front" of the digger head. -minetest.register_node("digtron:digger", { - description = S("Digtron Digger Head"), - _doc_items_longdesc = digtron.doc.digger_longdesc, - _doc_items_usagehelp = digtron.doc.digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = digger_nodebox, - }, - - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90", - "digtron_plate.png^[transformR270", - "digtron_plate.png", - "digtron_plate.png^[transformR180", - { - name = "digtron_digger_yb.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_motor.png", - }, - - -- returns fuel_cost, item_produced - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) then - return 0, {} - end - - return digtron.mark_diggable(digpos, nodes_dug) - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local facing = minetest.get_node(pos).param2 - digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8) - end, -}) - --- Digs out nodes that are "in front" of the digger head. -minetest.register_node("digtron:intermittent_digger", { - description = S("Digtron Intermittent Digger Head"), - _doc_items_longdesc = digtron.doc.intermittent_digger_longdesc, - _doc_items_usagehelp = digtron.doc.intermittent_digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:intermittent_digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = digger_nodebox, - }, - - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90", - "digtron_plate.png^[transformR270", - "digtron_plate.png", - "digtron_plate.png^[transformR180", - { - name = "digtron_digger_yb.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_intermittent.png^digtron_motor.png", - }, - - on_construct = intermittent_on_construct, - - on_receive_fields = intermittent_on_receive_fields, - - -- returns fuel_cost, item_produced - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - if lateral_dig == true then - return 0, {} - end - - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) then - return 0, {} - end - - local meta = minetest.get_meta(pos) - if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then - return 0, {} - end - - return digtron.mark_diggable(digpos, nodes_dug) - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local facing = minetest.get_node(pos).param2 - local targetpos = digtron.find_new_pos(pos, facing) - local meta = minetest.get_meta(pos) - if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then - digtron.damage_creatures(player, targetpos, 8) - end - end -}) - --- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes -minetest.register_node("digtron:soft_digger", { - description = S("Digtron Soft Material Digger Head"), - _doc_items_longdesc = digtron.doc.soft_digger_longdesc, - _doc_items_usagehelp = digtron.doc.soft_digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:soft_digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = digger_nodebox, - }, - - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[transformR270^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, - { - name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, - }, - - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) then - return 0, {} - end - - if digtron.is_soft_material(digpos) then - return digtron.mark_diggable(digpos, nodes_dug) - end - - return 0, {} - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local facing = minetest.get_node(pos).param2 - digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4) - end, -}) - -minetest.register_node("digtron:intermittent_soft_digger", { - description = S("Digtron Intermittent Soft Material Digger Head"), - _doc_items_longdesc = digtron.doc.intermittent_soft_digger_longdesc, - _doc_items_usagehelp = digtron.doc.intermittent_soft_digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:intermittent_soft_digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = digger_nodebox, - }, - - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[transformR270^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, - { - name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_intermittent.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, - }, - - on_construct = intermittent_on_construct, - - on_receive_fields = intermittent_on_receive_fields, - - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - if lateral_dig == true then - return 0, {} - end - - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) then - return 0, {} - end - - local meta = minetest.get_meta(pos) - if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then - return 0, {} - end - - if digtron.is_soft_material(digpos) then - return digtron.mark_diggable(digpos, nodes_dug) - end - - return 0, {} - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local meta = minetest.get_meta(pos) - local facing = minetest.get_node(pos).param2 - local targetpos = digtron.find_new_pos(pos, facing) - if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then - digtron.damage_creatures(player, targetpos, 4) - end - end, -}) - --- Digs out nodes that are "in front" of the digger head and "below" the digger head (can be rotated). -minetest.register_node("digtron:dual_digger", { - description = S("Digtron Dual Digger Head"), - _doc_items_longdesc = digtron.doc.dual_digger_longdesc, - _doc_items_usagehelp = digtron.doc.dual_digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:dual_digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = dual_digger_nodebox, - }, - - -- Aims in the +Z and -Y direction by default - tiles = { - "digtron_plate.png^digtron_motor.png", - { - name = "digtron_digger_yb.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png", - "digtron_plate.png^[transformR180", - { - name = "digtron_digger_yb.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_motor.png", - }, - - -- returns fuel_cost, items_produced - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - local digdown = digtron.find_new_pos_downward(pos, facing) - - local items = {} - local cost = 0 - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true then - local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug) - for _, item in pairs(forward_items) do - table.insert(items, item) - end - cost = cost + forward_cost - end - if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true then - local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug) - for _, item in pairs(down_items) do - table.insert(items, item) - end - cost = cost + down_cost - end - - return cost, items - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local facing = minetest.get_node(pos).param2 - digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8) - digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 8) - end, -}) - --- Digs out soft nodes that are "in front" of the digger head and "below" the digger head (can be rotated). -minetest.register_node("digtron:dual_soft_digger", { - description = S("Digtron Dual Soft Material Digger Head"), - _doc_items_longdesc = digtron.doc.dual_soft_digger_longdesc, - _doc_items_usagehelp = digtron.doc.dual_soft_digger_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, - drop = "digtron:dual_soft_digger", - sounds = digtron.metal_sounds, - paramtype = "light", - paramtype2= "facedir", - is_ground_content = false, - drawtype="nodebox", - node_box = { - type = "fixed", - fixed = dual_digger_nodebox, - }, - - -- Aims in the +Z and -Y direction by default - tiles = { - "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, - { - name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, - "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, - { - name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 1.0, - }, - }, - "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, - }, - - -- returns fuel_cost, items_produced - execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) - local facing = minetest.get_node(pos).param2 - local digpos = digtron.find_new_pos(pos, facing) - local digdown = digtron.find_new_pos_downward(pos, facing) - - local items = {} - local cost = 0 - - if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true and digtron.is_soft_material(digpos) then - local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug) - for _, item in pairs(forward_items) do - table.insert(items, item) - end - cost = cost + forward_cost - end - if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true and digtron.is_soft_material(digdown) then - local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug) - for _, item in pairs(down_items) do - table.insert(items, item) - end - cost = cost + down_cost - end - - return cost, items - end, - - damage_creatures = function(player, pos, controlling_coordinate) - local facing = minetest.get_node(pos).param2 - digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4) - digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 4) - end, -}) \ No newline at end of file diff --git a/node_misc.lua b/node_misc.lua deleted file mode 100644 index e847045..0000000 --- a/node_misc.lua +++ /dev/null @@ -1,141 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - --- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other. -minetest.register_node("digtron:structure", { - description = S("Digtron Structure"), - _doc_items_longdesc = digtron.doc.structure_longdesc, - _doc_items_usagehelp = digtron.doc.structure_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:structure", - tiles = {"digtron_plate.png"}, - drawtype = "nodebox", - sounds = digtron.metal_sounds, - climbable = true, - walkable = false, - paramtype = "light", - is_ground_content = false, - node_box = { - type = "fixed", - fixed = { - {0.3125, 0.3125, -0.5, 0.5, 0.5, 0.5}, - {0.3125, -0.5, -0.5, 0.5, -0.3125, 0.5}, - {-0.5, 0.3125, -0.5, -0.3125, 0.5, 0.5}, - {-0.5, -0.5, -0.5, -0.3125, -0.3125, 0.5}, - {-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, - {-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, - {-0.5, -0.3125, 0.3125, -0.3125, 0.3125, 0.5}, - {0.3125, -0.3125, 0.3125, 0.5, 0.3125, 0.5}, - {-0.5, -0.3125, -0.5, -0.3125, 0.3125, -0.3125}, - {0.3125, -0.3125, -0.5, 0.5, 0.3125, -0.3125}, - {-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, - {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, - } - }, -}) - --- A modest light source that will move with the digtron, handy for working in a tunnel you aren't bothering to install permanent lights in. -minetest.register_node("digtron:light", { - description = S("Digtron Light"), - _doc_items_longdesc = digtron.doc.light_longdesc, - _doc_items_usagehelp = digtron.doc.light_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:light", - tiles = {"digtron_plate.png^digtron_light.png"}, - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - light_source = 10, - sounds = default.node_sound_glass_defaults(), - paramtype2 = "wallmounted", - node_box = { - type = "wallmounted", - wall_top = {-0.25, 0.3125, -0.25, 0.25, 0.5, 0.25}, - wall_bottom = {-0.25, -0.3125, -0.25, 0.25, -0.5, 0.25}, - wall_side = {-0.5, -0.25, -0.25, -0.1875, 0.25, 0.25}, - }, -}) - --- A simple structural panel -minetest.register_node("digtron:panel", { - description = S("Digtron Panel"), - _doc_items_longdesc = digtron.doc.panel_longdesc, - _doc_items_usagehelp = digtron.doc.panel_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:panel", - tiles = {"digtron_plate.png"}, - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - sounds = digtron.metal_sounds, - paramtype2 = "facedir", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5}, - }, - collision_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, - }, -}) - --- A simple structural panel -minetest.register_node("digtron:edge_panel", { - description = S("Digtron Edge Panel"), - _doc_items_longdesc = digtron.doc.edge_panel_longdesc, - _doc_items_usagehelp = digtron.doc.edge_panel_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:edge_panel", - tiles = {"digtron_plate.png"}, - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - sounds = digtron.metal_sounds, - paramtype2 = "facedir", - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0.375, 0.5, 0.5, 0.5}, - {-0.5, -0.5, -0.5, 0.5, -0.375, 0.375} - }, - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}, - {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.4375} - }, - }, - -}) - -minetest.register_node("digtron:corner_panel", { - description = S("Digtron Corner Panel"), - _doc_items_longdesc = digtron.doc.corner_panel_longdesc, - _doc_items_usagehelp = digtron.doc.corner_panel_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, - drop = "digtron:corner_panel", - tiles = {"digtron_plate.png"}, - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - sounds = digtron.metal_sounds, - paramtype2 = "facedir", - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0.375, 0.5, 0.5, 0.5}, - {-0.5, -0.5, -0.5, 0.5, -0.375, 0.375}, - {-0.5, -0.375, -0.5, -0.375, 0.5, 0.375}, - }, - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}, - {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.4375}, - {-0.5, -0.4375, -0.5, -0.4375, 0.5, 0.4375}, - }, - }, -}) \ No newline at end of file diff --git a/node_storage.lua b/node_storage.lua deleted file mode 100644 index 5284490..0000000 --- a/node_storage.lua +++ /dev/null @@ -1,276 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - --- 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", { - description = S("Digtron Inventory Storage"), - _doc_items_longdesc = digtron.doc.inventory_longdesc, - _doc_items_usagehelp = digtron.doc.inventory_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 2, tubedevice = 1, tubedevice_receiver = 1}, - drop = "digtron:inventory", - sounds = digtron.metal_sounds, - paramtype2= "facedir", - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - tiles = { - "digtron_plate.png^digtron_crossbrace.png", - "digtron_plate.png^digtron_crossbrace.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", - }, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.3]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Inventory items") .. "]" .. - "list[current_name;main;0,0.6;8,4;]" .. - "list[current_player;main;0,5.15;8,1;]" .. - "list[current_player;main;0,6.38;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.15) - ) - local inv = meta:get_inventory() - inv:set_size("main", 8*4) - end, - - can_dig = function(pos,player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:is_empty("main") - end, - - -- Pipeworks compatibility - ---------------------------------------------------------------- - - tube = (function() if minetest.get_modpath("pipeworks") then return { - insert_object = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item("main", stack) - end, - can_insert = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:room_for_item("main", stack) - end, - input_inventory = "main", - connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} - } end end)(), - - after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), - after_dig_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_dig end end)() -}) - --- Fuel storage. Controller node draws fuel from here. --- Note that fuel stores are digtron group 5. -minetest.register_node("digtron:fuelstore", { - description = S("Digtron Fuel Storage"), - _doc_items_longdesc = digtron.doc.fuelstore_longdesc, - _doc_items_usagehelp = digtron.doc.fuelstore_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 5, tubedevice = 1, tubedevice_receiver = 1}, - drop = "digtron:fuelstore", - sounds = digtron.metal_sounds, - paramtype2= "facedir", - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - tiles = { - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", - }, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.3]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Fuel items") .. "]" .. - "list[current_name;fuel;0,0.6;8,4;]" .. - "list[current_player;main;0,5.15;8,1;]" .. - "list[current_player;main;0,6.38;8,3;8]" .. - "listring[current_name;fuel]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.15) - ) - local inv = meta:get_inventory() - inv:set_size("fuel", 8*4) - end, - - -- Only allow fuel items to be placed in fuel - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if listname == "fuel" then - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then - return stack:get_count() - else - return 0 - end - end - return 0 - end, - - can_dig = function(pos,player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:is_empty("fuel") - end, - - -- Pipeworks compatibility - ---------------------------------------------------------------- - - tube = (function() if minetest.get_modpath("pipeworks") then return { - insert_object = function(pos, node, stack, direction) - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item("fuel", stack) - end - return stack - end, - can_insert = function(pos, node, stack, direction) - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:room_for_item("fuel", stack) - end - return false - end, - input_inventory = "fuel", - connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} - } end end)(), - - after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), - after_dig_node = (function() if minetest.get_modpath("pipeworks")then return pipeworks.after_dig end end)() -}) - --- Combined storage. Group 6 has both an inventory and a fuel store -minetest.register_node("digtron:combined_storage", { - description = S("Digtron Combined Storage"), - _doc_items_longdesc = digtron.doc.combined_storage_longdesc, - _doc_items_usagehelp = digtron.doc.combined_storage_usagehelp, - groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 6, tubedevice = 1, tubedevice_receiver = 1}, - drop = "digtron:combined_storage", - sounds = digtron.metal_sounds, - paramtype2= "facedir", - drawtype = "nodebox", - paramtype = "light", - is_ground_content = false, - tiles = { - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", - "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", - }, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Inventory items") .. "]" .. - "list[current_name;main;0,0.6;8,3;]" .. - "label[0,3.5;" .. S("Fuel items") .. "]" .. - "list[current_name;fuel;0,4.1;8,1;]" .. - "list[current_player;main;0,5.75;8,1;]" .. - "list[current_player;main;0,6.98;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.75) - ) - local inv = meta:get_inventory() - inv:set_size("main", 8*3) - inv:set_size("fuel", 8*1) - end, - - -- Only allow fuel items to be placed in fuel - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if listname == "fuel" then - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then - return stack:get_count() - else - return 0 - end - end - return stack:get_count() -- otherwise, allow all drops - end, - - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - if to_list == "main" then - return count - end - - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local stack = inv:get_stack(from_list, from_index) - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then - return stack:get_count() - end - return 0 - end, - - can_dig = function(pos,player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:is_empty("fuel") and inv:is_empty("main") - end, - - -- Pipeworks compatibility - ---------------------------------------------------------------- - tube = (function() if minetest.get_modpath("pipeworks") then return { - insert_object = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then - return inv:add_item("fuel", stack) - end - return inv:add_item("main", stack) - end, - can_insert = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then - return inv:room_for_item("fuel", stack) - end - return inv:room_for_item("main", stack) - end, - input_inventory = "main", - connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} - } end end)(), - - after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), - after_dig_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_dig end end)() -}) - --- Hopper compatibility -if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then - hopper:add_container({ - {"top", "digtron:inventory", "main"}, - {"bottom", "digtron:inventory", "main"}, - {"side", "digtron:inventory", "main"}, - - {"top", "digtron:fuelstore", "fuel"}, - {"bottom", "digtron:fuelstore", "fuel"}, - {"side", "digtron:fuelstore", "fuel"}, - - {"top", "digtron:combined_storage", "main"}, - {"bottom", "digtron:combined_storage", "main"}, - {"side", "digtron:combined_storage", "fuel"}, - }) -end diff --git a/nodes/node_axle.lua b/nodes/node_axle.lua new file mode 100644 index 0000000..8726ab8 --- /dev/null +++ b/nodes/node_axle.lua @@ -0,0 +1,64 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +minetest.register_node("digtron:axle", { + description = S("Digtron Rotation Axle"), + _doc_items_longdesc = digtron.doc.axle_longdesc, + _doc_items_usagehelp = digtron.doc.axle_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:axle", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^digtron_axel_top.png", + "digtron_plate.png^digtron_axel_top.png", + "digtron_plate.png^digtron_axel_side.png", + "digtron_plate.png^digtron_axel_side.png", + "digtron_plate.png^digtron_axel_side.png", + "digtron_plate.png^digtron_axel_side.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.5, 0.3125, -0.3125, 0.5, 0.5, 0.3125}, -- Uppercap + {-0.5, -0.5, -0.3125, 0.5, -0.3125, 0.3125}, -- Lowercap + {-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, -- Uppercap_edge2 + {-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, -- Uppercap_edge1 + {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, -- Lowercap_edge1 + {-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, -- Lowercap_edge2 + {-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle + } + }, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + if meta:get_string("waiting") == "true" then + -- Been too soon since last time the digtron rotated. + return + end + local image = DigtronLayout.create(pos, clicker) + image:rotate_layout_image(node.param2) + if image:can_write_layout_image() then + image:write_layout_image(clicker) + + minetest.sound_play("whirr", {gain=1.0, pos=pos}) + meta = minetest.get_meta(pos) + meta:set_string("waiting", "true") + meta:set_string("infotext", nil) + minetest.get_node_timer(pos):start(digtron.cycle_time*2) + else + minetest.sound_play("buzzer", {gain=1.0, pos=pos}) + meta:set_string("infotext", S("Digtron is obstructed.")) + end + end, + + on_timer = function(pos, elapsed) + minetest.get_meta(pos):set_string("waiting", nil) + end, +}) \ No newline at end of file diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua new file mode 100644 index 0000000..424eb67 --- /dev/null +++ b/nodes/node_builders.lua @@ -0,0 +1,334 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +-- Note: builders go in group 4 and have both test_build and execute_build methods. + +local builder_formspec = nil + +if minetest.get_modpath("doc") then + builder_formspec = "size[8,5.2]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[current_name;main;0,0;1,1;]" .. + "label[0,0.8;" .. S("Block to build") .. "]" .. + "field[1.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. + "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. + "field[2.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. + "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. + "field[3.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. + "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. + "button_exit[4.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. + "tooltip[set;" .. S("Saves settings") .. "]" .. + "field[5.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. + "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. + "button_exit[6.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. + "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. + "list[current_player;main;0,1.3;8,1;]" .. + default.get_hotbar_bg(0,1.3) .. + "list[current_player;main;0,2.5;8,3;8]" .. + "listring[current_player;main]" .. + "listring[current_name;main]" .. + "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block") .. "]" +else + builder_formspec = "size[8,5.2]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[current_name;main;0.5,0;1,1;]" .. + "label[0.5,0.8;" .. S("Block to build") .. "]" .. + "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. + "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. + "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. + "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. + "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. + "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. + "button_exit[5.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. + "tooltip[set;" .. S("Saves settings") .. "]" .. + "field[6.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. + "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. + "button_exit[7.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. + "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. + "list[current_player;main;0,1.3;8,1;]" .. + default.get_hotbar_bg(0,1.3) .. + "list[current_player;main;0,2.5;8,3;8]" .. + "listring[current_player;main]" .. + "listring[current_name;main]" +end + +-- Builds objects in the targeted node. This is a complicated beastie. +minetest.register_node("digtron:builder", { + description = S("Digtron Builder Module"), + _doc_items_longdesc = digtron.doc.builder_longdesc, + _doc_items_usagehelp = digtron.doc.builder_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 4}, + drop = "digtron:builder", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + tiles = { + "digtron_plate.png^[transformR90", + "digtron_plate.png^[transformR270", + "digtron_plate.png", + "digtron_plate.png^[transformR180", + "digtron_plate.png^digtron_builder.png", + "digtron_plate.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.25, 0.3125, 0.3125, 0.25, 0.5, 0.5}, -- FrontFrame_top + {-0.25, -0.5, 0.3125, 0.25, -0.3125, 0.5}, -- FrontFrame_bottom + {0.3125, -0.25, 0.3125, 0.5, 0.25, 0.5}, -- FrontFrame_right + {-0.5, -0.25, 0.3125, -0.3125, 0.25, 0.5}, -- FrontFrame_left + {-0.5, 0.25, -0.5, -0.25, 0.5, 0.5}, -- edge_topright + {-0.5, -0.5, -0.5, -0.25, -0.25, 0.5}, -- edge_bottomright + {0.25, 0.25, -0.5, 0.5, 0.5, 0.5}, -- edge_topleft + {0.25, -0.5, -0.5, 0.5, -0.25, 0.5}, -- edge_bottomleft + {-0.25, 0.4375, -0.5, 0.25, 0.5, -0.4375}, -- backframe_top + {-0.25, -0.5, -0.5, 0.25, -0.4375, -0.4375}, -- backframe_bottom + {-0.5, -0.25, -0.5, -0.4375, 0.25, -0.4375}, -- backframe_left + {0.4375, -0.25, -0.5, 0.5, 0.25, -0.4375}, -- Backframe_right + {-0.0625, -0.3125, 0.3125, 0.0625, 0.3125, 0.375}, -- frontcross_vertical + {-0.3125, -0.0625, 0.3125, 0.3125, 0.0625, 0.375}, -- frontcross_horizontal + } + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", builder_formspec) + meta:set_int("period", 1) + meta:set_int("offset", 0) + meta:set_int("build_facing", 0) + meta:set_int("extrusion", 1) + + local inv = meta:get_inventory() + inv:set_size("main", 1) + end, + + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + local period = tonumber(fields.period) + local offset = tonumber(fields.offset) + local build_facing = tonumber(fields.build_facing) + local extrusion = tonumber(fields.extrusion) + + if period and period > 0 then + meta:set_int("period", math.floor(tonumber(fields.period))) + else + period = meta:get_int("period") + end + if offset then + meta:set_int("offset", math.floor(tonumber(fields.offset))) + else + offset = meta:get_int("offset") + end + if build_facing and build_facing >= 0 and build_facing < 24 then + -- TODO: wallmounted facings only run from 0-5, a player could theoretically put a wallmounted item into the builder and then manually set the build facing to an invalid number + -- Should prevent that somehow. But not tonight. + meta:set_int("build_facing", math.floor(build_facing)) + end + if extrusion and extrusion > 0 and extrusion <= digtron.maximum_extrusion then + meta:set_int("extrusion", math.floor(tonumber(fields.extrusion))) + else + extrusion = meta:get_int("extrusion") + end + + if fields.set then + local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2) + local x_pos = math.floor((buildpos.x+offset)/period)*period - offset + minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker") + if x_pos >= buildpos.x then + minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker") + end + if x_pos <= buildpos.x then + minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker") + end + + local y_pos = math.floor((buildpos.y+offset)/period)*period - offset + minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical") + if y_pos >= buildpos.y then + minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical") + end + if y_pos <= buildpos.y then + minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical") + end + + local z_pos = math.floor((buildpos.z+offset)/period)*period - offset + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708) + if z_pos >= buildpos.z then + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708) + end + if z_pos <= buildpos.z then + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708) + end + + elseif fields.read then + local meta = minetest.get_meta(pos) + local facing = minetest.get_node(pos).param2 + local buildpos = digtron.find_new_pos(pos, facing) + meta:set_int("build_facing", minetest.get_node(buildpos).param2) + end + + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built + minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:builder", true) + end + + digtron.update_builder_item(pos) + end, + + on_destruct = function(pos) + digtron.remove_builder_item(pos) + end, + + after_place_node = function(pos) + digtron.update_builder_item(pos) + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then + return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output. + end + local inv = minetest.get_inventory({type="node", pos=pos}) + inv:set_stack(listname, index, stack:take_item(1)) + return 0 + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local inv = minetest.get_inventory({type="node", pos=pos}) + inv:set_stack(listname, index, ItemStack("")) + return 0 + end, + + -- "builder at pos, imagine that you're in test_pos. If you're willing and able to build from there, take the item you need from inventory. + -- return the item you took and the inventory location you took it from so it can be put back after all the other builders have been tested. + -- If you couldn't get the item from inventory, return an error code so we can abort the cycle. + -- If you're not supposed to build at all, or the location is obstructed, return 0 to let us know you're okay and we shouldn't abort." + + --return code and accompanying value: + -- 0, {} -- not supposed to build, no error + -- 1, {{itemstack, source inventory pos}, ...} -- can build, took items from inventory + -- 2, {{itemstack, source inventory pos}, ...}, itemstack -- was supposed to build, but couldn't get the item from inventory + -- 3, {} -- builder configuration error + test_build = function(pos, test_pos, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) + local meta = minetest.get_meta(pos) + local facing = minetest.get_node(pos).param2 + local buildpos = digtron.find_new_pos(test_pos, facing) + + if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then + --It's not the builder's turn to build right now. + return 0, {} + end + + local extrusion_count = 0 + local extrusion_target = meta:get_int("extrusion") + if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then + extrusion_target = 1 -- failsafe + end + + local return_items = {} + + local inv = minetest.get_inventory({type="node", pos=pos}) + local item_stack = inv:get_stack("main", 1) + + if item_stack:is_empty() then + return 3, {} -- error code for "this builder's item slot is unset" + end + + while extrusion_count < extrusion_target do + if not digtron.can_move_to(buildpos, protected_nodes, nodes_dug) then + --using "can_move_to" instead of "can_build_to" test case in case the builder is pointed "backward", and will thus + --be building into the space that it's currently in and will be vacating after moving, or in case the builder is aimed + --sideways and a fellow digtron node was ahead of it (will also be moving out of the way). + + --If the player has built his digtron stupid (eg has another digtron node in the place the builder wants to build) this + --assumption is wrong, but I can't hold the player's hand through *every* possible bad design decision. Worst case, + --the digtron will think its inventory can't handle the next build step and abort the build when it actually could have + --managed one more cycle. That's not a bad outcome for a digtron array that was built stupidly to begin with. + return 1, return_items + end + + local source_location = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) + if source_location ~= nil then + table.insert(return_items, {item=item_stack, location=source_location}) + else + return 2, return_items, item_stack -- error code for "needed an item but couldn't get it from inventory" + end + extrusion_count = extrusion_count + 1 + buildpos = digtron.find_new_pos(buildpos, facing) + end + + return 1, return_items + end, + + execute_build = function(pos, player, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) + local meta = minetest.get_meta(pos) + local build_facing = tonumber(meta:get_int("build_facing")) + local facing = minetest.get_node(pos).param2 + local buildpos = digtron.find_new_pos(pos, facing) + + if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then + return 0 + end + + local extrusion_count = 0 + local extrusion_target = meta:get_int("extrusion") + if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then + extrusion_target = 1 -- failsafe + end + local built_count = 0 + + local inv = minetest.get_inventory({type="node", pos=pos}) + local item_stack = inv:get_stack("main", 1) + if item_stack:is_empty() then + return built_count + end + + while extrusion_count < extrusion_target do + if not digtron.can_build_to(buildpos, protected_nodes, nodes_dug) then + return built_count + end + + local oldnode = minetest.get_node(buildpos) + + if digtron.creative_mode then + local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) + if success == true then + minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) + nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) + built_count = built_count + 1 + else + return built_count + end + end + + local sourcepos = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) + if sourcepos == nil then + -- item not in inventory! Need to sound the angry buzzer to let the player know, so return a negative number. + return (built_count + 1) * -1 + end + local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) + if success == true then + minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) + --flag this node as *not* to be dug. + nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) + digtron.award_item_built(item_stack:get_name(), player:get_player_name()) + built_count = built_count + 1 + else + --failed to build, target node probably obstructed. Put the item back in inventory. + --Should probably never reach this since we're guarding against can_build_to, above, but this makes things safe if we somehow do. + digtron.place_in_specific_inventory(item_stack, sourcepos, inventory_positions, controller_pos) + return built_count + end + + extrusion_count = extrusion_count + 1 + buildpos = digtron.find_new_pos(buildpos, facing) + end + return built_count + end, +}) \ No newline at end of file diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua new file mode 100644 index 0000000..a09cfbe --- /dev/null +++ b/nodes/node_controllers.lua @@ -0,0 +1,345 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +local controller_nodebox ={ + {-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core + {-0.1875, 0.3125, -0.1875, 0.1875, 0.5, 0.1875}, -- +y_connector + {-0.1875, -0.5, -0.1875, 0.1875, -0.3125, 0.1875}, -- -y_Connector + {0.3125, -0.1875, -0.1875, 0.5, 0.1875, 0.1875}, -- +x_connector + {-0.5, -0.1875, -0.1875, -0.3125, 0.1875, 0.1875}, -- -x_connector + {-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- +z_connector + {-0.5, 0.125, -0.5, -0.125, 0.5, -0.3125}, -- back_connector_3 + {0.125, 0.125, -0.5, 0.5, 0.5, -0.3125}, -- back_connector_1 + {0.125, -0.5, -0.5, 0.5, -0.125, -0.3125}, -- back_connector_2 + {-0.5, -0.5, -0.5, -0.125, -0.125, -0.3125}, -- back_connector_4 +} + +-- Master controller. Most complicated part of the whole system. Determines which direction a digtron moves and triggers all of its component parts. +minetest.register_node("digtron:controller", { + description = S("Digtron Control Module"), + _doc_items_longdesc = digtron.doc.controller_longdesc, + _doc_items_usagehelp = digtron.doc.controller_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1}, + drop = "digtron:controller", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90", + "digtron_plate.png^[transformR270", + "digtron_plate.png", + "digtron_plate.png^[transformR180", + "digtron_plate.png", + "digtron_plate.png^digtron_control.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = controller_nodebox, + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_float("fuel_burning", 0.0) + meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) + end, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + if meta:get_string("waiting") == "true" then + -- Been too soon since last time the digtron did a cycle. + return + end + + local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker) + + meta = minetest.get_meta(newpos) + if status ~= nil then + meta:set_string("infotext", status) + end + + -- Start the delay before digtron can run again. + minetest.get_meta(newpos):set_string("waiting", "true") + minetest.get_node_timer(newpos):start(digtron.cycle_time) + end, + + on_timer = function(pos, elapsed) + minetest.get_meta(pos):set_string("waiting", nil) + end, +}) + +-- Auto-controller +--------------------------------------------------------------------------------------------------------------- + +local auto_formspec = "size[8,6.2]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "container[2.0,0]" .. + "field[0.0,0.8;1,0.1;cycles;" .. S("Cycles").. ";${cycles}]" .. + "tooltip[cycles;" .. S("When triggered, this controller will try to run for the given number of cycles.\nThe cycle count will decrement as it runs, so if it gets halted by a problem\nyou can fix the problem and restart.").. "]" .. + "button_exit[0.7,0.5;1,0.1;set;" .. S("Set").. "]" .. + "tooltip[set;" .. S("Saves the cycle setting without starting the controller running").. "]" .. + "button_exit[1.7,0.5;1,0.1;execute;" .. S("Set &\nExecute").. "]" .. + "tooltip[execute;" .. S("Begins executing the given number of cycles").. "]" .. + "field[0.0,2.0;1,0.1;slope;" .. S("Slope").. ";${slope}]" .. + "tooltip[slope;" .. S("For diagonal digging. After moving forward this number of nodes the auto controller\nwill add an additional cycle moving the digtron laterally in the\ndirection of the arrows on the side of this controller.\nSet to 0 for no lateral digging.").. "]" .. + "field[1.0,2.0;1,0.1;offset;" .. S("Offset").. ";${offset}]" .. + "tooltip[offset;" .. S("Sets the offset of the lateral motion defined in the Slope field.\nNote: this offset is relative to the controller's location.\nThe controller will move laterally when it reaches the indicated point.").. "]" .. + "field[2.0,2.0;1,0.1;period;" .. S("Delay").. ";${period}]" .. + "tooltip[period;" .. S("Number of seconds to wait between each cycle").. "]" .. + "list[current_name;stop;3.0,0.7;1,1;]" .. + "label[3.0,1.5;" .. S("Stop block").. "]" .. + "container_end[]" .. + "list[current_player;main;0,2.3;8,1;]" .. + default.get_hotbar_bg(0,2.3) .. + "list[current_player;main;0,3.5;8,3;8]" .. + "listring[current_player;main]" .. + "listring[current_name;stop]" + +if minetest.get_modpath("doc") then + auto_formspec = auto_formspec .. + "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block").. "]" +end + +-- Needed to make this global so that it could recurse into minetest.after +digtron.auto_cycle = function(pos) + local node = minetest.get_node(pos) + local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2) + local meta = minetest.get_meta(pos) + local player = minetest.get_player_by_name(meta:get_string("triggering_player")) + if player == nil or meta:get_string("waiting") == "true" then + return + end + + local cycle = meta:get_int("cycles") + local slope = meta:get_int("slope") + + if meta:get_string("lateral_done") ~= "true" and slope ~= 0 and (pos[controlling_coordinate] + meta:get_int("offset")) % slope == 0 then + --Do a downward dig cycle. Don't update the "cycles" count, these don't count towards that. + local newpos, status, return_code = digtron.execute_downward_dig_cycle(pos, player) + + if vector.equals(pos, newpos) then + status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) + meta:set_string("infotext", status) + if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. + minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) + else + meta:set_string("formspec", auto_formspec) + end + else + meta = minetest.get_meta(newpos) + minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) + meta:set_string("infotext", status) + meta:set_string("lateral_done", "true") + end + return + end + + local newpos, status, return_code = digtron.execute_dig_cycle(pos, player) + + if vector.equals(pos, newpos) then + status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) + meta:set_string("infotext", status) + if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. + minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) + else + meta:set_string("formspec", auto_formspec) + end + return + end + + meta = minetest.get_meta(newpos) + cycle = meta:get_int("cycles") - 1 + meta:set_int("cycles", cycle) + status = status .. string.format("\n" .. S("Cycles remaining: %d"), cycle) + meta:set_string("infotext", status) + meta:set_string("lateral_done", nil) + + if cycle > 0 then + minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) + else + meta:set_string("formspec", auto_formspec) + end +end + +minetest.register_node("digtron:auto_controller", { + description = S("Digtron Automatic Control Module"), + _doc_items_longdesc = digtron.doc.auto_controller_longdesc, + _doc_items_usagehelp = digtron.doc.auto_controller_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1}, + drop = "digtron:auto_controller", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90^[colorize:" .. digtron.auto_controller_colorize, + "digtron_plate.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, + "digtron_plate.png^digtron_axel_side.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, + "digtron_plate.png^digtron_axel_side.png^[transformR270^[colorize:" .. digtron.auto_controller_colorize, + "digtron_plate.png^[colorize:" .. digtron.auto_controller_colorize, + "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.auto_controller_colorize, + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = controller_nodebox, + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_float("fuel_burning", 0.0) + meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) + meta:set_string("formspec", auto_formspec) + -- Reusing offset and period to keep the digtron node-moving code simple, and the names still fit well + meta:set_int("period", digtron.cycle_time) + meta:set_int("offset", 0) + meta:set_int("cycles", 0) + meta:set_int("slope", 0) + + local inv = meta:get_inventory() + inv:set_size("stop", 1) + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then + return 0 -- pointless setting a Digtron node as a stop block + end + local inv = minetest.get_inventory({type="node", pos=pos}) + inv:set_stack(listname, index, stack:take_item(1)) + return 0 + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local inv = minetest.get_inventory({type="node", pos=pos}) + inv:set_stack(listname, index, ItemStack("")) + return 0 + end, + + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + local offset = tonumber(fields.offset) + local period = tonumber(fields.period) + local slope = tonumber(fields.slope) + local cycles = tonumber(fields.cycles) + + if period and period > 0 then + meta:set_int("period", math.max(digtron.cycle_time, math.floor(period))) + end + + if offset then + meta:set_int("offset", offset) + end + + if slope and slope >= 0 then + meta:set_int("slope", slope) + end + + if cycles and cycles >= 0 then + meta:set_int("cycles", math.floor(cycles)) + if sender:is_player() and cycles > 0 then + meta:set_string("triggering_player", sender:get_player_name()) + if fields.execute then + meta:set_string("waiting", nil) + meta:set_string("formspec", nil) + digtron.auto_cycle(pos) + end + end + end + + if fields.set and slope and slope > 0 then + local node = minetest.get_node(pos) + local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2) + + local newpos = pos + local markerpos = {x=newpos.x, y=newpos.y, z=newpos.z} + local x_pos = math.floor((newpos[controlling_coordinate]+offset)/slope)*slope - offset + markerpos[controlling_coordinate] = x_pos + minetest.add_entity(markerpos, "digtron:marker_vertical") + if x_pos >= newpos[controlling_coordinate] then + markerpos[controlling_coordinate] = x_pos - slope + minetest.add_entity(markerpos, "digtron:marker_vertical") + end + if x_pos <= newpos[controlling_coordinate] then + markerpos[controlling_coordinate] = x_pos + slope + minetest.add_entity(markerpos, "digtron:marker_vertical") + end + end + + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built + minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:auto_controller", true) + end + end, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Interrupted!")) + meta:set_string("waiting", "true") + meta:set_string("formspec", auto_formspec) + end, + + on_timer = function(pos, elapsed) + minetest.get_meta(pos):set_string("waiting", nil) + end, + +}) + +--------------------------------------------------------------------------------------------------------------- + +-- A much simplified control unit that only moves the digtron, and doesn't trigger the diggers or builders. +-- Handy for shoving a digtron to the side if it's been built a bit off. +minetest.register_node("digtron:pusher", { + description = S("Digtron Pusher Module"), + _doc_items_longdesc = digtron.doc.pusher_longdesc, + _doc_items_usagehelp = digtron.doc.pusher_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:pusher", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90^[colorize:" .. digtron.pusher_controller_colorize, + "digtron_plate.png^[transformR270^[colorize:" .. digtron.pusher_controller_colorize, + "digtron_plate.png^[colorize:" .. digtron.pusher_controller_colorize, + "digtron_plate.png^[transformR180^[colorize:" .. digtron.pusher_controller_colorize, + "digtron_plate.png^[colorize:" .. digtron.pusher_controller_colorize, + "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.pusher_controller_colorize, + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = controller_nodebox, + }, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + if meta:get_string("waiting") == "true" then + -- Been too soon since last time the digtron did a cycle. + return + end + + local newpos, status_text, return_code = digtron.execute_move_cycle(pos, clicker) + meta = minetest.get_meta(newpos) + meta:set_string("infotext", status_text) + + -- Start the delay before digtron can run again. + minetest.get_meta(newpos):set_string("waiting", "true") + minetest.get_node_timer(newpos):start(digtron.cycle_time) + end, + + on_timer = function(pos, elapsed) + minetest.get_meta(pos):set_string("waiting", nil) + end, + +}) \ No newline at end of file diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua new file mode 100644 index 0000000..017023d --- /dev/null +++ b/nodes/node_crate.lua @@ -0,0 +1,193 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +minetest.register_node("digtron:empty_crate", { + description = S("Digtron Crate (Empty)"), + _doc_items_longdesc = digtron.doc.empty_crate_longdesc, + _doc_items_usagehelp = digtron.doc.empty_crate_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3}, + drop = "digtron:empty_crate", + sounds = default.node_sound_wood_defaults(), + tiles = {"digtron_crate.png"}, + is_ground_content = false, + drawtype = "nodebox", + paramtype = "light", + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local layout = DigtronLayout.create(pos, clicker) + if layout.contains_protected_node then + local meta = minetest.get_meta(pos) + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + meta:set_string("infotext", S("Digtron can't be packaged, it contains protected blocks")) + -- no stealing other peoples' digtrons + return + end + + digtron.award_crate(layout, clicker:get_player_name()) + + local layout_string = layout:serialize() + + -- destroy everything. Note that this includes the empty crate, which will be bundled up with the layout. + for _, node_image in pairs(layout.all) do + minetest.remove_node(node_image.pos) + end + + -- Create the loaded crate node + minetest.set_node(pos, {name="digtron:loaded_crate", param1=node.param1, param2=node.param2}) + minetest.sound_play("machine1", {gain=1.0, pos=pos}) + + local meta = minetest.get_meta(pos) + meta:set_string("crated_layout", layout_string) + meta:set_string("title", S("Crated Digtron")) + meta:set_string("infotext", S("Crated Digtron")) + end, +}) + +local loaded_formspec + +if minetest.get_modpath("doc") then + loaded_formspec = + "size[4.1,1.5]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "field[0.3,0.5;4,0.5;title;" .. S("Digtron Name") .. ";${title}]" .. + "button_exit[0.0,1.2;1,0.1;save;" .. S("Save\nTitle") .. "]" .. + "tooltip[save;" .. S("Saves the title of this Digtron") .. "]" .. + "button_exit[1.0,1.2;1,0.1;show;" .. S("Show\nBlocks") .. "]" .. + "tooltip[show;" .. S("Shows which blocks the packed Digtron will occupy if unpacked") .. "]" .. + "button_exit[2.0,1.2;1,0.1;unpack;" .. S("Unpack") .. "]" .. + "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" .. + "button_exit[3.0,1.2;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block") .. "]" +else + loaded_formspec = + "size[4,1.5]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "field[0.3,0.5;4,0.5;title;" .. S("Digtron Name") .. ";${title}]" .. + "button_exit[0.5,1.2;1,0.1;save;" .. S("Save\nTitle") .. "]" .. + "tooltip[show;" .. S("Saves the title of this Digtron") .. "]" .. + "button_exit[1.5,1.2;1,0.1;show;" .. S("Show\nBlocks") .. "]" .. + "tooltip[save;" .. S("Shows which blocks the packed Digtron will occupy if unpacked") .. "]" .. + "button_exit[2.5,1.2;1,0.1;unpack;" .. S("Unpack") .. "]" .. + "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" +end + +minetest.register_node("digtron:loaded_crate", { + description = S("Digtron Crate (Loaded)"), + _doc_items_longdesc = digtron.doc.loaded_crate_longdesc, + _doc_items_usagehelp = digtron.doc.loaded_crate_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1}, + stack_max = 1, + sounds = default.node_sound_wood_defaults(), + tiles = {"digtron_plate.png^digtron_crate.png"}, + is_ground_content = false, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", loaded_formspec) + end, + + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + + if fields.unpack or fields.save or fields.show then + meta:set_string("title", fields.title) + meta:set_string("infotext", fields.title) + end + + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built + minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:loaded_crate", true) + end + + if not (fields.unpack or fields.show) then + return + end + + local layout_string = meta:get_string("crated_layout") + local layout = DigtronLayout.deserialize(layout_string) + + if layout == nil then + meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted or lost.")) + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + -- Something went horribly wrong + return + end + + local protected_node = false + local obstructed_node = false + + local pos_diff = vector.subtract(pos, layout.controller) + layout.controller = pos + for _, node_image in pairs(layout.all) do + node_image.pos = vector.add(pos_diff, node_image.pos) + if not vector.equals(pos, node_image.pos) then + if minetest.is_protected(node_image.pos, sender:get_player_name()) and not minetest.check_player_privs(sender, "protection_bypass") then + protected_node = true + minetest.add_entity(node_image.pos, "digtron:marker_crate_bad") + elseif not minetest.registered_nodes[minetest.get_node(node_image.pos).name].buildable_to then + obstructed_node = true + minetest.add_entity(node_image.pos, "digtron:marker_crate_bad") + else + minetest.add_entity(node_image.pos, "digtron:marker_crate_good") + end + end + end + + if not fields.unpack then + return + end + + if protected_node then + meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to deploy Digtron due to protected blocks in target area")) + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + return + end + + if obstructed_node then + meta:set_string("infotext", meta:get_string("title") .. "\n" .. S("Unable to deploy Digtron due to obstruction in target area")) + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + return + end + + -- build digtron. Since the empty crate was included in the layout, that will overwrite this loaded crate and destroy it. + minetest.sound_play("machine2", {gain=1.0, pos=pos}) + layout:write_layout_image(sender) + end, + + on_dig = function(pos, node, player) + + local meta = minetest.get_meta(pos) + local to_serialize = {title=meta:get_string("title"), layout=meta:get_string("crated_layout")} + + local stack = ItemStack({name="digtron:loaded_crate", count=1, wear=0, metadata=minetest.serialize(to_serialize)}) + local inv = player:get_inventory() + local stack = inv:add_item("main", stack) + if stack:get_count() > 0 then + minetest.add_item(pos, stack) + end + -- call on_dignodes callback + minetest.remove_node(pos) + end, + + on_place = function(itemstack, placer, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing, true) + local deserialized = minetest.deserialize(itemstack:get_metadata()) + if pos and deserialized then + minetest.set_node(pos, {name="digtron:loaded_crate"}) + local meta = minetest.get_meta(pos) + + 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) + + itemstack:take_item(1) + return itemstack + end + -- after-place callbacks + end, +}) \ No newline at end of file diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua new file mode 100644 index 0000000..c12b46c --- /dev/null +++ b/nodes/node_diggers.lua @@ -0,0 +1,473 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +-- Note: diggers go in group 3 and have an execute_dig method. + +local digger_nodebox = { + {-0.5, -0.5, 0, 0.5, 0.5, 0.4375}, -- Block + {-0.4375, -0.3125, 0.4375, 0.4375, 0.3125, 0.5}, -- Cutter1 + {-0.3125, -0.4375, 0.4375, 0.3125, 0.4375, 0.5}, -- Cutter2 + {-0.5, -0.125, -0.125, 0.5, 0.125, 0}, -- BackFrame1 + {-0.125, -0.5, -0.125, 0.125, 0.5, 0}, -- BackFrame2 + {-0.25, -0.25, -0.5, 0.25, 0.25, 0}, -- Drive +} + +local dual_digger_nodebox = { + {-0.5, -0.4375, 0, 0.5, 0.5, 0.4375}, -- Block + {-0.4375, -0.3125, 0.4375, 0.4375, 0.3125, 0.5}, -- Cutter1 + {-0.3125, -0.4375, 0.4375, 0.3125, 0.4375, 0.5}, -- Cutter2 + {-0.5, 0, -0.125, 0.5, 0.125, 0}, -- BackFrame1 + {-0.25, 0, -0.5, 0.25, 0.25, 0}, -- Drive + {-0.25, 0.25, -0.25, 0.25, 0.5, 0}, -- Upper_Drive + {-0.5, -0.4375, -0.5, 0.5, 0, 0.4375}, -- Lower_Block + {-0.3125, -0.5, -0.4375, 0.3125, -0.4375, 0.4375}, -- Lower_Cutter_1 + {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}, -- Lower_Cutter_2 +} + +local intermittent_formspec = + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "field[0.5,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. + "tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" .. + "field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. + "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" .. + "button_exit[2.2,0.5;1,0.1;set;" .. S("Save") .. "]" .. + "tooltip[set;" .. S("Saves settings") .. "]" + +local intermittent_on_construct = function(pos) + local formspec = intermittent_formspec + if minetest.get_modpath("doc") then + formspec = "size[4.5,1]" .. formspec .. + "button_exit[3.2,0.5;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block") .. "]" + else + formspec = "size[3.5,1]" .. formspec + end + local meta = minetest.get_meta(pos) + meta:set_string("formspec", formspec) + meta:set_int("period", 1) + meta:set_int("offset", 0) +end + +local intermittent_on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + local period = tonumber(fields.period) + local offset = tonumber(fields.offset) + if period and period > 0 then + meta:set_int("period", math.floor(period)) + end + if offset then + meta:set_int("offset", math.floor(offset)) + end + 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 +end, + +-- Digs out nodes that are "in front" of the digger head. +minetest.register_node("digtron:digger", { + description = S("Digtron Digger Head"), + _doc_items_longdesc = digtron.doc.digger_longdesc, + _doc_items_usagehelp = digtron.doc.digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = digger_nodebox, + }, + + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90", + "digtron_plate.png^[transformR270", + "digtron_plate.png", + "digtron_plate.png^[transformR180", + { + name = "digtron_digger_yb.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_motor.png", + }, + + -- returns fuel_cost, item_produced + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then + return 0, {} + end + + return digtron.mark_diggable(digpos, nodes_dug) + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local facing = minetest.get_node(pos).param2 + digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8) + end, +}) + +-- Digs out nodes that are "in front" of the digger head. +minetest.register_node("digtron:intermittent_digger", { + description = S("Digtron Intermittent Digger Head"), + _doc_items_longdesc = digtron.doc.intermittent_digger_longdesc, + _doc_items_usagehelp = digtron.doc.intermittent_digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:intermittent_digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = digger_nodebox, + }, + + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90", + "digtron_plate.png^[transformR270", + "digtron_plate.png", + "digtron_plate.png^[transformR180", + { + name = "digtron_digger_yb.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_intermittent.png^digtron_motor.png", + }, + + on_construct = intermittent_on_construct, + + on_receive_fields = intermittent_on_receive_fields, + + -- returns fuel_cost, item_produced + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + if lateral_dig == true then + return 0, {} + end + + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then + return 0, {} + end + + local meta = minetest.get_meta(pos) + if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then + return 0, {} + end + + return digtron.mark_diggable(digpos, nodes_dug) + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local facing = minetest.get_node(pos).param2 + local targetpos = digtron.find_new_pos(pos, facing) + local meta = minetest.get_meta(pos) + if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then + digtron.damage_creatures(player, targetpos, 8) + end + end +}) + +-- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes +minetest.register_node("digtron:soft_digger", { + description = S("Digtron Soft Material Digger Head"), + _doc_items_longdesc = digtron.doc.soft_digger_longdesc, + _doc_items_usagehelp = digtron.doc.soft_digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:soft_digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = digger_nodebox, + }, + + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[transformR270^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, + { + name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, + }, + + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then + return 0, {} + end + + if digtron.is_soft_material(digpos) then + return digtron.mark_diggable(digpos, nodes_dug) + end + + return 0, {} + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local facing = minetest.get_node(pos).param2 + digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4) + end, +}) + +minetest.register_node("digtron:intermittent_soft_digger", { + description = S("Digtron Intermittent Soft Material Digger Head"), + _doc_items_longdesc = digtron.doc.intermittent_soft_digger_longdesc, + _doc_items_usagehelp = digtron.doc.intermittent_soft_digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:intermittent_soft_digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = digger_nodebox, + }, + + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[transformR270^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, + { + name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_intermittent.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, + }, + + on_construct = intermittent_on_construct, + + on_receive_fields = intermittent_on_receive_fields, + + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + if lateral_dig == true then + return 0, {} + end + + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then + return 0, {} + end + + local meta = minetest.get_meta(pos) + if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then + return 0, {} + end + + if digtron.is_soft_material(digpos) then + return digtron.mark_diggable(digpos, nodes_dug) + end + + return 0, {} + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local meta = minetest.get_meta(pos) + local facing = minetest.get_node(pos).param2 + local targetpos = digtron.find_new_pos(pos, facing) + if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then + digtron.damage_creatures(player, targetpos, 4) + end + end, +}) + +-- Digs out nodes that are "in front" of the digger head and "below" the digger head (can be rotated). +minetest.register_node("digtron:dual_digger", { + description = S("Digtron Dual Digger Head"), + _doc_items_longdesc = digtron.doc.dual_digger_longdesc, + _doc_items_usagehelp = digtron.doc.dual_digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:dual_digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = dual_digger_nodebox, + }, + + -- Aims in the +Z and -Y direction by default + tiles = { + "digtron_plate.png^digtron_motor.png", + { + name = "digtron_digger_yb.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png", + "digtron_plate.png^[transformR180", + { + name = "digtron_digger_yb.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_motor.png", + }, + + -- returns fuel_cost, items_produced + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + local digdown = digtron.find_new_pos_downward(pos, facing) + + local items = {} + local cost = 0 + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true then + local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug) + for _, item in pairs(forward_items) do + table.insert(items, item) + end + cost = cost + forward_cost + end + if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true then + local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug) + for _, item in pairs(down_items) do + table.insert(items, item) + end + cost = cost + down_cost + end + + return cost, items + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local facing = minetest.get_node(pos).param2 + digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8) + digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 8) + end, +}) + +-- Digs out soft nodes that are "in front" of the digger head and "below" the digger head (can be rotated). +minetest.register_node("digtron:dual_soft_digger", { + description = S("Digtron Dual Soft Material Digger Head"), + _doc_items_longdesc = digtron.doc.dual_soft_digger_longdesc, + _doc_items_usagehelp = digtron.doc.dual_soft_digger_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, + drop = "digtron:dual_soft_digger", + sounds = digtron.metal_sounds, + paramtype = "light", + paramtype2= "facedir", + is_ground_content = false, + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = dual_digger_nodebox, + }, + + -- Aims in the +Z and -Y direction by default + tiles = { + "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, + { + name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^[colorize:" .. digtron.soft_digger_colorize, + "digtron_plate.png^[transformR180^[colorize:" .. digtron.soft_digger_colorize, + { + name = "digtron_digger_yb.png^[colorize:" .. digtron.soft_digger_colorize, + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, + }, + + -- returns fuel_cost, items_produced + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) + local facing = minetest.get_node(pos).param2 + local digpos = digtron.find_new_pos(pos, facing) + local digdown = digtron.find_new_pos_downward(pos, facing) + + local items = {} + local cost = 0 + + if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true and digtron.is_soft_material(digpos) then + local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug) + for _, item in pairs(forward_items) do + table.insert(items, item) + end + cost = cost + forward_cost + end + if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true and digtron.is_soft_material(digdown) then + local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug) + for _, item in pairs(down_items) do + table.insert(items, item) + end + cost = cost + down_cost + end + + return cost, items + end, + + damage_creatures = function(player, pos, controlling_coordinate) + local facing = minetest.get_node(pos).param2 + digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4) + digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 4) + end, +}) \ No newline at end of file diff --git a/nodes/node_misc.lua b/nodes/node_misc.lua new file mode 100644 index 0000000..e847045 --- /dev/null +++ b/nodes/node_misc.lua @@ -0,0 +1,141 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +-- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other. +minetest.register_node("digtron:structure", { + description = S("Digtron Structure"), + _doc_items_longdesc = digtron.doc.structure_longdesc, + _doc_items_usagehelp = digtron.doc.structure_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:structure", + tiles = {"digtron_plate.png"}, + drawtype = "nodebox", + sounds = digtron.metal_sounds, + climbable = true, + walkable = false, + paramtype = "light", + is_ground_content = false, + node_box = { + type = "fixed", + fixed = { + {0.3125, 0.3125, -0.5, 0.5, 0.5, 0.5}, + {0.3125, -0.5, -0.5, 0.5, -0.3125, 0.5}, + {-0.5, 0.3125, -0.5, -0.3125, 0.5, 0.5}, + {-0.5, -0.5, -0.5, -0.3125, -0.3125, 0.5}, + {-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, + {-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, + {-0.5, -0.3125, 0.3125, -0.3125, 0.3125, 0.5}, + {0.3125, -0.3125, 0.3125, 0.5, 0.3125, 0.5}, + {-0.5, -0.3125, -0.5, -0.3125, 0.3125, -0.3125}, + {0.3125, -0.3125, -0.5, 0.5, 0.3125, -0.3125}, + {-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, + {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, + } + }, +}) + +-- A modest light source that will move with the digtron, handy for working in a tunnel you aren't bothering to install permanent lights in. +minetest.register_node("digtron:light", { + description = S("Digtron Light"), + _doc_items_longdesc = digtron.doc.light_longdesc, + _doc_items_usagehelp = digtron.doc.light_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:light", + tiles = {"digtron_plate.png^digtron_light.png"}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + light_source = 10, + sounds = default.node_sound_glass_defaults(), + paramtype2 = "wallmounted", + node_box = { + type = "wallmounted", + wall_top = {-0.25, 0.3125, -0.25, 0.25, 0.5, 0.25}, + wall_bottom = {-0.25, -0.3125, -0.25, 0.25, -0.5, 0.25}, + wall_side = {-0.5, -0.25, -0.25, -0.1875, 0.25, 0.25}, + }, +}) + +-- A simple structural panel +minetest.register_node("digtron:panel", { + description = S("Digtron Panel"), + _doc_items_longdesc = digtron.doc.panel_longdesc, + _doc_items_usagehelp = digtron.doc.panel_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:panel", + tiles = {"digtron_plate.png"}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + sounds = digtron.metal_sounds, + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5}, + }, + collision_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, + }, +}) + +-- A simple structural panel +minetest.register_node("digtron:edge_panel", { + description = S("Digtron Edge Panel"), + _doc_items_longdesc = digtron.doc.edge_panel_longdesc, + _doc_items_usagehelp = digtron.doc.edge_panel_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:edge_panel", + tiles = {"digtron_plate.png"}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + sounds = digtron.metal_sounds, + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0.375, 0.5, 0.5, 0.5}, + {-0.5, -0.5, -0.5, 0.5, -0.375, 0.375} + }, + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}, + {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.4375} + }, + }, + +}) + +minetest.register_node("digtron:corner_panel", { + description = S("Digtron Corner Panel"), + _doc_items_longdesc = digtron.doc.corner_panel_longdesc, + _doc_items_usagehelp = digtron.doc.corner_panel_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1}, + drop = "digtron:corner_panel", + tiles = {"digtron_plate.png"}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + sounds = digtron.metal_sounds, + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0.375, 0.5, 0.5, 0.5}, + {-0.5, -0.5, -0.5, 0.5, -0.375, 0.375}, + {-0.5, -0.375, -0.5, -0.375, 0.5, 0.375}, + }, + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}, + {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.4375}, + {-0.5, -0.4375, -0.5, -0.4375, 0.5, 0.4375}, + }, + }, +}) \ No newline at end of file diff --git a/nodes/node_storage.lua b/nodes/node_storage.lua new file mode 100644 index 0000000..826aa20 --- /dev/null +++ b/nodes/node_storage.lua @@ -0,0 +1,276 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +-- 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", { + description = S("Digtron Inventory Storage"), + _doc_items_longdesc = digtron.doc.inventory_longdesc, + _doc_items_usagehelp = digtron.doc.inventory_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 2, tubedevice = 1, tubedevice_receiver = 1}, + drop = "digtron:inventory", + sounds = digtron.metal_sounds, + paramtype2= "facedir", + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + tiles = { + "digtron_plate.png^digtron_crossbrace.png", + "digtron_plate.png^digtron_crossbrace.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_storage.png", + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + "size[8,9.3]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Inventory items") .. "]" .. + "list[current_name;main;0,0.6;8,4;]" .. + "list[current_player;main;0,5.15;8,1;]" .. + "list[current_player;main;0,6.38;8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.15) + ) + local inv = meta:get_inventory() + inv:set_size("main", 8*4) + end, + + can_dig = function(pos,player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + + -- Pipeworks compatibility + ---------------------------------------------------------------- + + tube = (function() if minetest.get_modpath("pipeworks") then return { + insert_object = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:add_item("main", stack) + end, + can_insert = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:room_for_item("main", stack) + end, + input_inventory = "main", + connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} + } end end)(), + + after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), + after_dig_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_dig end end)() +}) + +-- Fuel storage. Controller node draws fuel from here. +-- Note that fuel stores are digtron group 5. +minetest.register_node("digtron:fuelstore", { + description = S("Digtron Fuel Storage"), + _doc_items_longdesc = digtron.doc.fuelstore_longdesc, + _doc_items_usagehelp = digtron.doc.fuelstore_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 5, tubedevice = 1, tubedevice_receiver = 1}, + drop = "digtron:fuelstore", + sounds = digtron.metal_sounds, + paramtype2= "facedir", + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + tiles = { + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable.png^digtron_storage.png", + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + "size[8,9.3]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Fuel items") .. "]" .. + "list[current_name;fuel;0,0.6;8,4;]" .. + "list[current_player;main;0,5.15;8,1;]" .. + "list[current_player;main;0,6.38;8,3;8]" .. + "listring[current_name;fuel]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.15) + ) + local inv = meta:get_inventory() + inv:set_size("fuel", 8*4) + end, + + -- Only allow fuel items to be placed in fuel + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if listname == "fuel" then + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then + return stack:get_count() + else + return 0 + end + end + return 0 + end, + + can_dig = function(pos,player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:is_empty("fuel") + end, + + -- Pipeworks compatibility + ---------------------------------------------------------------- + + tube = (function() if minetest.get_modpath("pipeworks") then return { + insert_object = function(pos, node, stack, direction) + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:add_item("fuel", stack) + end + return stack + end, + can_insert = function(pos, node, stack, direction) + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:room_for_item("fuel", stack) + end + return false + end, + input_inventory = "fuel", + connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} + } end end)(), + + after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), + after_dig_node = (function() if minetest.get_modpath("pipeworks")then return pipeworks.after_dig end end)() +}) + +-- Combined storage. Group 6 has both an inventory and a fuel store +minetest.register_node("digtron:combined_storage", { + description = S("Digtron Combined Storage"), + _doc_items_longdesc = digtron.doc.combined_storage_longdesc, + _doc_items_usagehelp = digtron.doc.combined_storage_usagehelp, + groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 6, tubedevice = 1, tubedevice_receiver = 1}, + drop = "digtron:combined_storage", + sounds = digtron.metal_sounds, + paramtype2= "facedir", + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + tiles = { + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", + "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", + }, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + "size[8,9.9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Inventory items") .. "]" .. + "list[current_name;main;0,0.6;8,3;]" .. + "label[0,3.5;" .. S("Fuel items") .. "]" .. + "list[current_name;fuel;0,4.1;8,1;]" .. + "list[current_player;main;0,5.75;8,1;]" .. + "list[current_player;main;0,6.98;8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.75) + ) + local inv = meta:get_inventory() + inv:set_size("main", 8*3) + inv:set_size("fuel", 8*1) + end, + + -- Only allow fuel items to be placed in fuel + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if listname == "fuel" then + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then + return stack:get_count() + else + return 0 + end + end + return stack:get_count() -- otherwise, allow all drops + end, + + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + if to_list == "main" then + return count + end + + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then + return stack:get_count() + end + return 0 + end, + + can_dig = function(pos,player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:is_empty("fuel") and inv:is_empty("main") + end, + + -- Pipeworks compatibility + ---------------------------------------------------------------- + tube = (function() if minetest.get_modpath("pipeworks") then return { + insert_object = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then + return inv:add_item("fuel", stack) + end + return inv:add_item("main", stack) + end, + can_insert = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then + return inv:room_for_item("fuel", stack) + end + return inv:room_for_item("main", stack) + end, + input_inventory = "main", + connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} + } end end)(), + + after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), + after_dig_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_dig end end)() +}) + +-- Hopper compatibility +if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then + hopper:add_container({ + {"top", "digtron:inventory", "main"}, + {"bottom", "digtron:inventory", "main"}, + {"side", "digtron:inventory", "main"}, + + {"top", "digtron:fuelstore", "fuel"}, + {"bottom", "digtron:fuelstore", "fuel"}, + {"side", "digtron:fuelstore", "fuel"}, + + {"top", "digtron:combined_storage", "main"}, + {"bottom", "digtron:combined_storage", "main"}, + {"side", "digtron:combined_storage", "fuel"}, + }) +end diff --git a/nodes/recipes.lua b/nodes/recipes.lua new file mode 100644 index 0000000..9895971 --- /dev/null +++ b/nodes/recipes.lua @@ -0,0 +1,283 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +minetest.register_craftitem("digtron:digtron_core", { + description = S("Digtron Core"), + inventory_image = "digtron_core.png", + _doc_items_longdesc = digtron.doc.core_longdesc, + _doc_items_usagehelp = digtron.doc.core_usagehelp, +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"","default:steel_ingot",""}, + {"default:steel_ingot","default:mese_crystal_fragment","default:steel_ingot"}, + {"","default:steel_ingot",""} + } +}) + +minetest.register_craft({ + output = "digtron:controller", + recipe = { + {"","default:mese_crystal",""}, + {"default:mese_crystal","digtron:digtron_core","default:mese_crystal"}, + {"","default:mese_crystal",""} + } +}) + +minetest.register_craft({ + output = "digtron:auto_controller", + recipe = { + {"default:mese_crystal","default:mese_crystal","default:mese_crystal"}, + {"default:mese_crystal","digtron:digtron_core","default:mese_crystal"}, + {"default:mese_crystal","default:mese_crystal","default:mese_crystal"} + } +}) + +minetest.register_craft({ + output = "digtron:builder", + recipe = { + {"","default:mese_crystal_fragment",""}, + {"default:mese_crystal_fragment","digtron:digtron_core","default:mese_crystal_fragment"}, + {"","default:mese_crystal_fragment",""} + } +}) + +minetest.register_craft({ + output = "digtron:light", + recipe = { + {"","default:torch",""}, + {"","digtron:digtron_core",""}, + {"","",""} + } +}) + +minetest.register_craft({ + output = "digtron:digger", + recipe = { + {"","default:diamond",""}, + {"default:diamond","digtron:digtron_core","default:diamond"}, + {"","default:diamond",""} + } +}) + +minetest.register_craft({ + output = "digtron:soft_digger", + recipe = { + {"","default:steel_ingot",""}, + {"default:steel_ingot","digtron:digtron_core","default:steel_ingot"}, + {"","default:steel_ingot",""} + } +}) + +minetest.register_craft({ + output = "digtron:inventory", + recipe = { + {"","default:chest",""}, + {"","digtron:digtron_core",""}, + {"","",""} + } +}) + +minetest.register_craft({ + output = "digtron:fuelstore", + recipe = { + {"","default:furnace",""}, + {"","digtron:digtron_core",""}, + {"","",""} + } +}) + +minetest.register_craft({ + output = "digtron:combined_storage", + recipe = { + {"","default:furnace",""}, + {"","digtron:digtron_core",""}, + {"","default:chest",""} + } +}) + +minetest.register_craft({ + output = "digtron:pusher", + recipe = { + {"","default:coal_lump",""}, + {"default:coal_lump","digtron:digtron_core","default:coal_lump"}, + {"","default:coal_lump",""} + } +}) + +minetest.register_craft({ + output = "digtron:axle", + recipe = { + {"default:coal_lump","default:coal_lump","default:coal_lump"}, + {"default:coal_lump","digtron:digtron_core","default:coal_lump"}, + {"default:coal_lump","default:coal_lump","default:coal_lump"} + } +}) + +minetest.register_craft({ + output = "digtron:empty_crate", + recipe = { + {"","default:chest",""}, + {"","digtron:digtron_core",""}, + {"","default:mese_crystal",""} + } +}) + +-- Structural + +minetest.register_craft({ + output = "digtron:structure", + recipe = { + {"group:stick","","group:stick"}, + {"","digtron:digtron_core",""}, + {"group:stick","","group:stick"} + } +}) + +minetest.register_craft({ + output = "digtron:panel", + recipe = { + {"","",""}, + {"","digtron:digtron_core",""}, + {"","default:steel_ingot",""} + } +}) + +minetest.register_craft({ + output = "digtron:edge_panel", + recipe = { + {"","",""}, + {"","digtron:digtron_core","default:steel_ingot"}, + {"","default:steel_ingot",""} + } +}) + +minetest.register_craft({ + output = "digtron:corner_panel", + recipe = { + {"","",""}, + {"","digtron:digtron_core","default:steel_ingot"}, + {"","default:steel_ingot","default:steel_ingot"} + } +}) + +-- For swapping digger types +minetest.register_craft({ + output = "digtron:digger", + recipe = { + {"digtron:intermittent_digger"}, + } +}) +minetest.register_craft({ + output = "digtron:intermittent_digger", + recipe = { + {"digtron:digger"}, + } +}) +minetest.register_craft({ + output = "digtron:soft_digger", + recipe = { + {"digtron:intermittent_soft_digger"}, + } +}) +minetest.register_craft({ + output = "digtron:intermittent_soft_digger", + recipe = { + {"digtron:soft_digger"}, + } +}) + +minetest.register_craft({ + output = "digtron:dual_soft_digger", + type = "shapeless", + recipe = {"digtron:soft_digger", "digtron:soft_digger"}, +}) +minetest.register_craft({ + output = "digtron:dual_digger", + type = "shapeless", + recipe = {"digtron:digger", "digtron:digger"}, +}) +minetest.register_craft({ + output = "digtron:soft_digger 2", + recipe = { + {"digtron:dual_soft_digger"}, + } +}) +minetest.register_craft({ + output = "digtron:digger 2", + recipe = { + {"digtron:dual_digger"}, + } +}) + +-- And some recycling reactions to get digtron cores out of the "cheap" parts: + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:structure"}, + } +}) +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:panel"}, + } +}) +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:corner_panel"}, + } +}) +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:edge_panel"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:inventory"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:fuelstore"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:combined_storage"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:light"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:pusher"}, + } +}) + +minetest.register_craft({ + output = "digtron:digtron_core", + recipe = { + {"digtron:axle"}, + } +}) \ No newline at end of file diff --git a/recipes.lua b/recipes.lua deleted file mode 100644 index 9895971..0000000 --- a/recipes.lua +++ /dev/null @@ -1,283 +0,0 @@ --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - -minetest.register_craftitem("digtron:digtron_core", { - description = S("Digtron Core"), - inventory_image = "digtron_core.png", - _doc_items_longdesc = digtron.doc.core_longdesc, - _doc_items_usagehelp = digtron.doc.core_usagehelp, -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"","default:steel_ingot",""}, - {"default:steel_ingot","default:mese_crystal_fragment","default:steel_ingot"}, - {"","default:steel_ingot",""} - } -}) - -minetest.register_craft({ - output = "digtron:controller", - recipe = { - {"","default:mese_crystal",""}, - {"default:mese_crystal","digtron:digtron_core","default:mese_crystal"}, - {"","default:mese_crystal",""} - } -}) - -minetest.register_craft({ - output = "digtron:auto_controller", - recipe = { - {"default:mese_crystal","default:mese_crystal","default:mese_crystal"}, - {"default:mese_crystal","digtron:digtron_core","default:mese_crystal"}, - {"default:mese_crystal","default:mese_crystal","default:mese_crystal"} - } -}) - -minetest.register_craft({ - output = "digtron:builder", - recipe = { - {"","default:mese_crystal_fragment",""}, - {"default:mese_crystal_fragment","digtron:digtron_core","default:mese_crystal_fragment"}, - {"","default:mese_crystal_fragment",""} - } -}) - -minetest.register_craft({ - output = "digtron:light", - recipe = { - {"","default:torch",""}, - {"","digtron:digtron_core",""}, - {"","",""} - } -}) - -minetest.register_craft({ - output = "digtron:digger", - recipe = { - {"","default:diamond",""}, - {"default:diamond","digtron:digtron_core","default:diamond"}, - {"","default:diamond",""} - } -}) - -minetest.register_craft({ - output = "digtron:soft_digger", - recipe = { - {"","default:steel_ingot",""}, - {"default:steel_ingot","digtron:digtron_core","default:steel_ingot"}, - {"","default:steel_ingot",""} - } -}) - -minetest.register_craft({ - output = "digtron:inventory", - recipe = { - {"","default:chest",""}, - {"","digtron:digtron_core",""}, - {"","",""} - } -}) - -minetest.register_craft({ - output = "digtron:fuelstore", - recipe = { - {"","default:furnace",""}, - {"","digtron:digtron_core",""}, - {"","",""} - } -}) - -minetest.register_craft({ - output = "digtron:combined_storage", - recipe = { - {"","default:furnace",""}, - {"","digtron:digtron_core",""}, - {"","default:chest",""} - } -}) - -minetest.register_craft({ - output = "digtron:pusher", - recipe = { - {"","default:coal_lump",""}, - {"default:coal_lump","digtron:digtron_core","default:coal_lump"}, - {"","default:coal_lump",""} - } -}) - -minetest.register_craft({ - output = "digtron:axle", - recipe = { - {"default:coal_lump","default:coal_lump","default:coal_lump"}, - {"default:coal_lump","digtron:digtron_core","default:coal_lump"}, - {"default:coal_lump","default:coal_lump","default:coal_lump"} - } -}) - -minetest.register_craft({ - output = "digtron:empty_crate", - recipe = { - {"","default:chest",""}, - {"","digtron:digtron_core",""}, - {"","default:mese_crystal",""} - } -}) - --- Structural - -minetest.register_craft({ - output = "digtron:structure", - recipe = { - {"group:stick","","group:stick"}, - {"","digtron:digtron_core",""}, - {"group:stick","","group:stick"} - } -}) - -minetest.register_craft({ - output = "digtron:panel", - recipe = { - {"","",""}, - {"","digtron:digtron_core",""}, - {"","default:steel_ingot",""} - } -}) - -minetest.register_craft({ - output = "digtron:edge_panel", - recipe = { - {"","",""}, - {"","digtron:digtron_core","default:steel_ingot"}, - {"","default:steel_ingot",""} - } -}) - -minetest.register_craft({ - output = "digtron:corner_panel", - recipe = { - {"","",""}, - {"","digtron:digtron_core","default:steel_ingot"}, - {"","default:steel_ingot","default:steel_ingot"} - } -}) - --- For swapping digger types -minetest.register_craft({ - output = "digtron:digger", - recipe = { - {"digtron:intermittent_digger"}, - } -}) -minetest.register_craft({ - output = "digtron:intermittent_digger", - recipe = { - {"digtron:digger"}, - } -}) -minetest.register_craft({ - output = "digtron:soft_digger", - recipe = { - {"digtron:intermittent_soft_digger"}, - } -}) -minetest.register_craft({ - output = "digtron:intermittent_soft_digger", - recipe = { - {"digtron:soft_digger"}, - } -}) - -minetest.register_craft({ - output = "digtron:dual_soft_digger", - type = "shapeless", - recipe = {"digtron:soft_digger", "digtron:soft_digger"}, -}) -minetest.register_craft({ - output = "digtron:dual_digger", - type = "shapeless", - recipe = {"digtron:digger", "digtron:digger"}, -}) -minetest.register_craft({ - output = "digtron:soft_digger 2", - recipe = { - {"digtron:dual_soft_digger"}, - } -}) -minetest.register_craft({ - output = "digtron:digger 2", - recipe = { - {"digtron:dual_digger"}, - } -}) - --- And some recycling reactions to get digtron cores out of the "cheap" parts: - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:structure"}, - } -}) -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:panel"}, - } -}) -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:corner_panel"}, - } -}) -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:edge_panel"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:inventory"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:fuelstore"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:combined_storage"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:light"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:pusher"}, - } -}) - -minetest.register_craft({ - output = "digtron:digtron_core", - recipe = { - {"digtron:axle"}, - } -}) \ No newline at end of file -- cgit v1.2.3 From 46bffd82d38ded68bcf102efd25da06a96e64a5d Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 12 Sep 2017 00:20:52 -0600 Subject: standardize config settings --- class_layout.lua | 2 +- config.lua | 105 ++++++++++++++++----------------------------- init.lua | 2 +- nodes/node_axle.lua | 2 +- nodes/node_builders.lua | 8 ++-- nodes/node_controllers.lua | 8 ++-- util.lua | 10 ++--- util_execute_cycle.lua | 36 ++++++++-------- 8 files changed, 72 insertions(+), 101 deletions(-) diff --git a/class_layout.lua b/class_layout.lua index 0aa139e..d516870 100644 --- a/class_layout.lua +++ b/class_layout.lua @@ -86,7 +86,7 @@ function DigtronLayout.create(pos, player) self.water_touching = true elseif minetest.get_item_group(node.name, "lava") ~= 0 then self.lava_touching = true - if digtron.lava_impassible == true then + if digtron.config.lava_impassible then self.protected:set(testpos.x, testpos.y, testpos.z, true) end end diff --git a/config.lua b/config.lua index d2d8860..a4b905e 100644 --- a/config.lua +++ b/config.lua @@ -1,44 +1,40 @@ --- Enables the spray of particles out the back of a digger head and puffs of smoke from the controller -local particle_effects = minetest.settings:get_bool("enable_particles") - --- this causes digtrons to operate without consuming fuel or building materials. -local digtron_uses_resources = minetest.settings:get_bool("digtron_uses_resources") -if digtron_uses_resources == nil then digtron_uses_resources = true end - --- when true, lava counts as protected nodes. -local lava_impassible = minetest.settings:get_bool("digtron_lava_impassible") - --- when true, diggers deal damage to creatures when they trigger. -local damage_creatures = minetest.settings:get_bool("digtron_damage_creatures") +local CONFIG_FILE_PREFIX = "digtron_" + +digtron.config = {} + +local print_settingtypes = false + +local function setting(stype, name, default, description) + local value + if stype == "bool" then + value = minetest.setting_getbool(CONFIG_FILE_PREFIX..name) + elseif stype == "string" then + value = minetest.setting_get(CONFIG_FILE_PREFIX..name) + elseif stype == "int" or stype == "float" then + value = tonumber(minetest.setting_get(CONFIG_FILE_PREFIX..name)) + end + if value == nil then + value = default + end + digtron.config[name] = value + + if print_settingtypes then + minetest.debug(CONFIG_FILE_PREFIX..name.." ("..description..") "..stype.." "..tostring(default)) + end +end -digtron.creative_mode = not digtron_uses_resources -- default false -digtron.particle_effects = particle_effects or particle_effects == nil -- default true -digtron.lava_impassible = lava_impassible or lava_impassible == nil -- default true -digtron.diggers_damage_creatures = damage_creatures or damage_creatures == nil -- default true +setting("bool", "uses_resources", true, "Digtron uses resources when active") +setting("bool", "lava_impassible", true, "Lava counts as a protected node") +setting("bool", "damage_creatures", true, "Diggers damage creatures") --- maximum distance a builder head can extrude blocks -local maximum_extrusion = tonumber(minetest.settings:get("digtron_maximum_extrusion")) -if maximum_extrusion == nil or maximum_extrusion < 1 or maximum_extrusion > 100 then - digtron.maximum_extrusion = 25 -else - digtron.maximum_extrusion = maximum_extrusion -end +-- Enables the spray of particles out the back of a digger head and puffs of smoke from the controller +local particle_effects = minetest.settings:get_bool("enable_particles") +digtron.config.particle_effects = particle_effects or particle_effects == nil -- default true --- How many seconds a digtron waits between cycles. Auto-controllers can make this wait longer, but cannot make it shorter. -local digtron_cycle_time = tonumber(minetest.settings:get("digtron_cycle_time")) -if digtron_cycle_time == nil or digtron_cycle_time < 0 then - digtron.cycle_time = 1.0 -else - digtron.cycle_time = digtron_cycle_time -end --- How many digtron nodes can be moved for each adjacent solid node that the digtron has traction against -local digtron_traction_factor = tonumber(minetest.settings:get("digtron_traction_factor")) -if digtron_traction_factor == nil or digtron_traction_factor < 0 then - digtron.traction_factor = 3.0 -else - digtron.traction_factor = digtron_traction_factor -end +setting("int", "maximum_extrusion", 25, "Maximum builder extrusion distance") +setting("float", "cycle_time", 1.0, "Minimum Digtron cycle time") +setting("float", "traction_factor", 3.0, "Traction factor") -- fuel costs. For comparison, in the default game: -- one default tree block is 30 units @@ -47,37 +43,12 @@ end -- one book is 3 units -- how much fuel is required to dig a node if not in one of the following groups. -local digtron_dig_cost_default = tonumber(minetest.settings:get("digtron_dig_cost_default")) -if digtron_dig_cost_default == nil or digtron_dig_cost_default < 0 then - digtron.dig_cost_default = 0.5 -else - digtron.dig_cost_default = digtron_dig_cost_default -end +setting("float", "dig_cost_default", 3.0, "Default dig cost") -- eg, stone -local digtron_dig_cost_cracky = tonumber(minetest.settings:get("digtron_dig_cost_cracky")) -if digtron_dig_cost_cracky == nil or digtron_dig_cost_cracky < 0 then - digtron.dig_cost_cracky = 1.0 -else - digtron.dig_cost_cracky = digtron_dig_cost_cracky -end +setting("float", "dig_cost_cracky", 1.0, "Cracky dig cost") -- eg, dirt, sand -local digtron_dig_cost_crumbly = tonumber(minetest.settings:get("digtron_dig_cost_crumbly")) -if digtron_dig_cost_crumbly == nil or digtron_dig_cost_crumbly < 0 then - digtron.dig_cost_crumbly = 0.5 -else - digtron.dig_cost_crumbly = digtron_dig_cost_crumbly -end +setting("float", "dig_cost_crumbly", 0.5, "Crumbly dig cost") -- eg, wood -local digtron_dig_cost_choppy = tonumber(minetest.settings:get("digtron_dig_cost_choppy")) -if digtron_dig_cost_choppy == nil or digtron_dig_cost_choppy < 0 then - digtron.dig_cost_choppy = 0.75 -else - digtron.dig_cost_choppy = digtron_dig_cost_choppy -end +setting("float", "dig_cost_choppy", 0.75, "Choppy dig cost") -- how much fuel is required to build a node -local digtron_build_cost = tonumber(minetest.settings:get("digtron_build_cost")) -if digtron_build_cost == nil or digtron_build_cost < 0 then - digtron.build_cost = 1.0 -else - digtron.build_cost = digtron_build_cost -end \ No newline at end of file +setting("float", "build_cost", 1.0, "Build cost") diff --git a/init.lua b/init.lua index 4483d42..5ca91a1 100644 --- a/init.lua +++ b/init.lua @@ -115,7 +115,7 @@ minetest.register_lbm({ "list[current_name;main;0.5,0;1,1;]" .. "label[0.5,0.8;" .. S("Block to build") .. "]" .. "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. + "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. diff --git a/nodes/node_axle.lua b/nodes/node_axle.lua index 8726ab8..99dda4b 100644 --- a/nodes/node_axle.lua +++ b/nodes/node_axle.lua @@ -51,7 +51,7 @@ minetest.register_node("digtron:axle", { meta = minetest.get_meta(pos) meta:set_string("waiting", "true") meta:set_string("infotext", nil) - minetest.get_node_timer(pos):start(digtron.cycle_time*2) + minetest.get_node_timer(pos):start(digtron.config.cycle_time*2) else minetest.sound_play("buzzer", {gain=1.0, pos=pos}) meta:set_string("infotext", S("Digtron is obstructed.")) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 424eb67..19bbe9f 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -14,7 +14,7 @@ if minetest.get_modpath("doc") then "list[current_name;main;0,0;1,1;]" .. "label[0,0.8;" .. S("Block to build") .. "]" .. "field[1.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. + "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. "field[2.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. "field[3.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. @@ -40,7 +40,7 @@ else "list[current_name;main;0.5,0;1,1;]" .. "label[0.5,0.8;" .. S("Block to build") .. "]" .. "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.maximum_extrusion) .. "]" .. + "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. @@ -133,7 +133,7 @@ minetest.register_node("digtron:builder", { -- Should prevent that somehow. But not tonight. meta:set_int("build_facing", math.floor(build_facing)) end - if extrusion and extrusion > 0 and extrusion <= digtron.maximum_extrusion then + if extrusion and extrusion > 0 and extrusion <= digtron.config.maximum_extrusion then meta:set_int("extrusion", math.floor(tonumber(fields.extrusion))) else extrusion = meta:get_int("extrusion") @@ -296,7 +296,7 @@ minetest.register_node("digtron:builder", { local oldnode = minetest.get_node(buildpos) - if digtron.creative_mode then + if not digtron.config.uses_resources then local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) if success == true then minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua index a09cfbe..76bb40b 100644 --- a/nodes/node_controllers.lua +++ b/nodes/node_controllers.lua @@ -64,7 +64,7 @@ minetest.register_node("digtron:controller", { -- Start the delay before digtron can run again. minetest.get_meta(newpos):set_string("waiting", "true") - minetest.get_node_timer(newpos):start(digtron.cycle_time) + minetest.get_node_timer(newpos):start(digtron.config.cycle_time) end, on_timer = function(pos, elapsed) @@ -200,7 +200,7 @@ minetest.register_node("digtron:auto_controller", { meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) meta:set_string("formspec", auto_formspec) -- Reusing offset and period to keep the digtron node-moving code simple, and the names still fit well - meta:set_int("period", digtron.cycle_time) + meta:set_int("period", digtron.config.cycle_time) meta:set_int("offset", 0) meta:set_int("cycles", 0) meta:set_int("slope", 0) @@ -232,7 +232,7 @@ minetest.register_node("digtron:auto_controller", { local cycles = tonumber(fields.cycles) if period and period > 0 then - meta:set_int("period", math.max(digtron.cycle_time, math.floor(period))) + meta:set_int("period", math.max(digtron.config.cycle_time, math.floor(period))) end if offset then @@ -335,7 +335,7 @@ minetest.register_node("digtron:pusher", { -- Start the delay before digtron can run again. minetest.get_meta(newpos):set_string("waiting", "true") - minetest.get_node_timer(newpos):start(digtron.cycle_time) + minetest.get_node_timer(newpos):start(digtron.config.cycle_time) end, on_timer = function(pos, elapsed) diff --git a/util.lua b/util.lua index e32c16b..3f1d732 100644 --- a/util.lua +++ b/util.lua @@ -52,21 +52,21 @@ digtron.mark_diggable = function(pos, nodes_dug) local in_known_group = false local material_cost = 0 - if digtron.creative_mode ~= true then + if digtron.config.uses_resources then if minetest.get_item_group(target.name, "cracky") ~= 0 then in_known_group = true - material_cost = math.max(material_cost, digtron.dig_cost_cracky) + material_cost = math.max(material_cost, digtron.config.dig_cost_cracky) end if minetest.get_item_group(target.name, "crumbly") ~= 0 then in_known_group = true - material_cost = math.max(material_cost, digtron.dig_cost_crumbly) + material_cost = math.max(material_cost, digtron.config.dig_cost_crumbly) end if minetest.get_item_group(target.name, "choppy") ~= 0 then in_known_group = true - material_cost = math.max(material_cost, digtron.dig_cost_choppy) + material_cost = math.max(material_cost, digtron.config.dig_cost_choppy) end if not in_known_group then - material_cost = digtron.dig_cost_default + material_cost = digtron.config.dig_cost_default end end diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index 0e0e092..e671480 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -59,10 +59,10 @@ local function neighbour_test(layout, status_text, dir) minetest.sound_play("woopwoopwoop", {gain=1.0, pos=layout.controller}) end - if dir and dir.y ~= -1 and layout.traction * digtron.traction_factor < table.getn(layout.all) then + if dir and dir.y ~= -1 and layout.traction * digtron.config.traction_factor < table.getn(layout.all) then -- digtrons can't fly, though they can fall minetest.sound_play("squeal", {gain=1.0, pos=layout.controller}) - return string.format("Digtron has %d blocks but only enough traction to move %d blocks.\n", table.getn(layout.all), layout.traction * digtron.traction_factor) + return string.format("Digtron has %d blocks but only enough traction to move %d blocks.\n", table.getn(layout.all), layout.traction * digtron.config.traction_factor) .. status_text, 2 end @@ -137,7 +137,7 @@ digtron.execute_dig_cycle = function(pos, clicker) for _, itemname in pairs(dropped) do table.insert(items_dropped, itemname) end - if digtron.particle_effects then + if digtron.config.particle_effects then table.insert(particle_systems, dig_dust(vector.add(location.pos, dir), target.param2)) end end @@ -164,9 +164,9 @@ digtron.execute_dig_cycle = function(pos, clicker) end if not can_move then - -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds + -- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds minetest.get_meta(pos):set_string("waiting", "true") - minetest.get_node_timer(pos):start(digtron.cycle_time) + minetest.get_node_timer(pos):start(digtron.config.cycle_time) minetest.sound_play("squeal", {gain=1.0, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return pos, S("Digtron is obstructed.") .. "\n" .. status_text, 3 --Abort, don't dig and don't build. @@ -193,7 +193,7 @@ digtron.execute_dig_cycle = function(pos, clicker) test_build_return_code, test_build_return_items, failed_to_find = targetdef.test_build(location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller) for k, return_item in pairs(test_build_return_items) do table.insert(test_items, return_item) - test_build_fuel_cost = test_build_fuel_cost + digtron.build_cost + test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost end if test_build_return_code > 1 then can_build = false @@ -222,7 +222,7 @@ digtron.execute_dig_cycle = function(pos, clicker) if not can_build then minetest.get_meta(pos):set_string("waiting", "true") - minetest.get_node_timer(pos):start(digtron.cycle_time) + minetest.get_node_timer(pos):start(digtron.config.cycle_time) local return_string = nil local return_code = 5 if test_build_return_code == 3 then @@ -247,7 +247,7 @@ digtron.execute_dig_cycle = function(pos, clicker) local move_player = move_player_test(layout, clicker) -- damage the weak flesh - if digtron.diggers_damage_creatures then + if digtron.config.damage_creatures then for k, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] @@ -288,8 +288,8 @@ digtron.execute_dig_cycle = function(pos, clicker) -- don't interrupt the build cycle as a whole, we've already moved so might as well try to complete as much as possible. strange_failure = true build_return = (build_return * -1) - 1 - elseif not digtron.creative_mode == true then - building_fuel_cost = building_fuel_cost + (digtron.build_cost * build_return) + elseif digtron.config.uses_resources then + building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return) end else minetest.log(string.format("%s has builder group but is missing execute_build method! This is an error in mod programming, file a bug.", targetdef.name)) @@ -307,7 +307,7 @@ digtron.execute_dig_cycle = function(pos, clicker) -- acutally burn the fuel needed local fuel_cost = digging_fuel_cost + building_fuel_cost fuel_burning = fuel_burning - fuel_cost - if digtron.particle_effects then + if digtron.config.particle_effects then table.insert(particle_systems, burn_smoke(pos, fuel_cost)) end if fuel_burning < 0 then @@ -359,9 +359,9 @@ digtron.execute_move_cycle = function(pos, clicker) -- test if any digtrons are obstructed by non-digtron nodes layout:move_layout_image(dir) if not layout:can_write_layout_image() then - -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds + -- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds minetest.get_meta(pos):set_string("waiting", "true") - minetest.get_node_timer(pos):start(digtron.cycle_time) + minetest.get_node_timer(pos):start(digtron.config.cycle_time) minetest.sound_play("squeal", {gain=1.0, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return pos, S("Digtron is obstructed.") .. "\n" .. status_text, 3 --Abort, don't dig and don't build. @@ -421,7 +421,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) for _, itemname in pairs(dropped) do table.insert(items_dropped, itemname) end - if digtron.particle_effects then + if digtron.config.particle_effects then table.insert(particle_systems, dig_dust(vector.add(location.pos, dir), target.param2)) end end @@ -448,9 +448,9 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) end if not can_move then - -- mark this node as waiting, will clear this flag in digtron.cycle_time seconds + -- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds minetest.get_meta(pos):set_string("waiting", "true") - minetest.get_node_timer(pos):start(digtron.cycle_time) + minetest.get_node_timer(pos):start(digtron.config.cycle_time) minetest.sound_play("squeal", {gain=1.0, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return pos, S("Digtron is obstructed.") .. "\n" .. status_text, 3 --Abort, don't dig and don't build. @@ -465,7 +465,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) local move_player = move_player_test(layout, clicker) -- damage the weak flesh - if digtron.diggers_damage_creatures then + if digtron.config.damage_creatures then for k, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] @@ -495,7 +495,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) -- acutally burn the fuel needed fuel_burning = fuel_burning - digging_fuel_cost - if digtron.particle_effects then + if digtron.config.particle_effects then table.insert(particle_systems, burn_smoke(pos, digging_fuel_cost)) end if fuel_burning < 0 then -- cgit v1.2.3 From 576aeeade02104a41ccb60d4dda91f8e364639a1 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Thu, 14 Sep 2017 00:47:53 -0600 Subject: add ability to read node type as well as facing, simplifies programming --- nodes/node_builders.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 19bbe9f..53edaa5 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -169,10 +169,15 @@ minetest.register_node("digtron:builder", { end elseif fields.read then - local meta = minetest.get_meta(pos) local facing = minetest.get_node(pos).param2 local buildpos = digtron.find_new_pos(pos, facing) - meta:set_int("build_facing", minetest.get_node(buildpos).param2) + local target_node = minetest.get_node(buildpos) + if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_stack("main", 1, target_node.name) + meta:set_int("build_facing", target_node.param2) + end end if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built -- cgit v1.2.3 From d66cbc21642df96ca69f00624bd8d723313e416e Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 00:24:07 -0600 Subject: add builder read substitutions dictionary --- init.lua | 16 ++++++++++++++++ nodes/node_builders.lua | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 5ca91a1..d4d7832 100644 --- a/init.lua +++ b/init.lua @@ -4,6 +4,22 @@ digtron.auto_controller_colorize = "#88000030" digtron.pusher_controller_colorize = "#00880030" digtron.soft_digger_colorize = "#88880030" +-- A global dictionary is used here so that other substitutions can be added easily by other mods, if necessary +digtron.builder_read_item_substitutions = { + ["default:torch_ceiling"] = "default:torch", + ["default:torch_wall"] = "default:torch", + ["default:dirt_with_grass"] = "default:dirt", + ["default:dirt_with_grass_footsteps"] = "default:dirt", + ["default:dirt_with_dry_grass"] = "default:dirt", + ["default:dirt_with_rainforest_litter"] = "default:dirt", + ["default:dirt_with_snow"] = "default:dirt", + ["default:furnace_active"] = "default:furnace", + ["farming:soil"] = "default:dirt", + ["farming:soil_wet"] = "default:dirt", + ["farming:desert_sand_soil"] = "default:desert_sand", + ["farming:desert_sand_soil_wet"] = "default:desert_sand", +} + dofile( minetest.get_modpath( "digtron" ) .. "/config.lua" ) dofile( minetest.get_modpath( "digtron" ) .. "/util.lua" ) dofile( minetest.get_modpath( "digtron" ) .. "/doc.lua" ) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 53edaa5..683ecde 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -175,7 +175,8 @@ minetest.register_node("digtron:builder", { if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - inv:set_stack("main", 1, target_node.name) + local target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name + inv:set_stack("main", 1, target_name) meta:set_int("build_facing", target_node.param2) end end -- cgit v1.2.3 From c6ee4a89578e6c1f1aeb93e75f9c5bc5ddc35bcb Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 01:05:55 -0600 Subject: simplify code behind builder formspec --- nodes/node_builders.lua | 56 +++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 683ecde..fa8bb0a 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -4,58 +4,40 @@ local S, NS = dofile(MP.."/intllib.lua") -- Note: builders go in group 4 and have both test_build and execute_build methods. -local builder_formspec = nil - +local displace_due_to_help_button = 1.0 if minetest.get_modpath("doc") then - builder_formspec = "size[8,5.2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0,0;1,1;]" .. - "label[0,0.8;" .. S("Block to build") .. "]" .. - "field[1.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. - "field[2.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. - "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. - "field[3.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. - "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. - "button_exit[4.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. - "tooltip[set;" .. S("Saves settings") .. "]" .. - "field[5.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. - "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. - "button_exit[6.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. - "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. - "list[current_player;main;0,1.3;8,1;]" .. - default.get_hotbar_bg(0,1.3) .. - "list[current_player;main;0,2.5;8,3;8]" .. - "listring[current_player;main]" .. - "listring[current_name;main]" .. - "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. - "tooltip[help;" .. S("Show documentation about this block") .. "]" -else - builder_formspec = "size[8,5.2]" .. + displace_due_to_help_button = 0.0 +end + +local builder_formspec = + "size[8,5.2]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots .. - "list[current_name;main;0.5,0;1,1;]" .. - "label[0.5,0.8;" .. S("Block to build") .. "]" .. - "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. + "list[current_name;main;".. tostring(displace_due_to_help_button/2) ..",0;1,1;]" .. + "label[" .. tostring(displace_due_to_help_button/2).. ",0.8;" .. S("Block to build") .. "]" .. + "field[" .. tostring(displace_due_to_help_button + 1.3) ..",0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. - "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. + "field[" .. tostring(displace_due_to_help_button + 2.3) ..",0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. - "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. + "field[" .. tostring(displace_due_to_help_button + 3.3) ..",0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. - "button_exit[5.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. + "button_exit[" .. tostring(displace_due_to_help_button + 4.0) ..",0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" .. - "field[6.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. + "field[" .. tostring(displace_due_to_help_button + 5.3) .. ",0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. - "button_exit[7.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. + "button_exit[" .. tostring(displace_due_to_help_button + 6.0) ..",0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. "list[current_player;main;0,1.3;8,1;]" .. default.get_hotbar_bg(0,1.3) .. "list[current_player;main;0,2.5;8,3;8]" .. "listring[current_player;main]" .. "listring[current_name;main]" + +if minetest.get_modpath("doc") then + builder_formspec = builder_formspec .. + "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. + "tooltip[help;" .. S("Show documentation about this block") .. "]" end -- Builds objects in the targeted node. This is a complicated beastie. -- cgit v1.2.3 From ade365df1bedc3203c316b87f699b37d770e3637 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 22:57:40 -0600 Subject: making formspecs more systematic and upgradable --- init.lua | 143 +++++++-------------------------------------- nodes/node_builders.lua | 1 + nodes/node_controllers.lua | 2 +- nodes/node_crate.lua | 1 + nodes/node_diggers.lua | 17 +++--- nodes/node_storage.lua | 96 ++++++++++++++++-------------- upgrades.lua | 57 ++++++++++++++++++ 7 files changed, 143 insertions(+), 174 deletions(-) create mode 100644 upgrades.lua diff --git a/init.lua b/init.lua index d4d7832..7beb8ee 100644 --- a/init.lua +++ b/init.lua @@ -20,21 +20,25 @@ digtron.builder_read_item_substitutions = { ["farming:desert_sand_soil_wet"] = "default:desert_sand", } -dofile( minetest.get_modpath( "digtron" ) .. "/config.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/util.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/doc.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/awards.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/class_pointset.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/class_layout.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/entities.lua" ) -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_misc.lua" ) -- contains structure and light nodes -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_storage.lua" ) -- contains inventory and fuel storage nodes -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_diggers.lua" ) -- contains all diggers -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_builders.lua" ) -- contains all builders (there's just one currently) -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_controllers.lua" ) -- controllers -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_axle.lua" ) -- Rotation controller -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/node_crate.lua" ) -- Digtron portability support -dofile( minetest.get_modpath( "digtron" ) .. "/nodes/recipes.lua" ) +local digtron_modpath = minetest.get_modpath( "digtron" ) + +dofile( digtron_modpath .. "/config.lua" ) +dofile( digtron_modpath .. "/util.lua" ) +dofile( digtron_modpath .. "/doc.lua" ) +dofile( digtron_modpath .. "/awards.lua" ) +dofile( digtron_modpath .. "/class_pointset.lua" ) +dofile( digtron_modpath .. "/class_layout.lua" ) +dofile( digtron_modpath .. "/entities.lua" ) +dofile( digtron_modpath .. "/nodes/node_misc.lua" ) -- contains structure and light nodes +dofile( digtron_modpath .. "/nodes/node_storage.lua" ) -- contains inventory and fuel storage nodes +dofile( digtron_modpath .. "/nodes/node_diggers.lua" ) -- contains all diggers +dofile( digtron_modpath .. "/nodes/node_builders.lua" ) -- contains all builders (there's just one currently) +dofile( digtron_modpath .. "/nodes/node_controllers.lua" ) -- controllers +dofile( digtron_modpath .. "/nodes/node_axle.lua" ) -- Rotation controller +dofile( digtron_modpath .. "/nodes/node_crate.lua" ) -- Digtron portability support +dofile( digtron_modpath .. "/nodes/recipes.lua" ) + +dofile( digtron_modpath .. "/upgrades.lua" ) -- various LBMs for upgrading older versions of Digtron. -- digtron group numbers: -- 1 - generic digtron node, nothing special is done with these. They're just dragged along. @@ -44,113 +48,8 @@ dofile( minetest.get_modpath( "digtron" ) .. "/nodes/recipes.lua" ) -- 5 - fuel-holding digtron, has a "fuel" invetory that the control node can draw fuel items from. Separate from general inventory, nothing gets put here automatically. -- 6 - holds both fuel and main inventories -minetest.register_lbm({ - name = "digtron:sand_digger_upgrade", - nodenames = {"digtron:sand_digger"}, - action = function(pos, node) - local meta = minetest.get_meta(pos) - local offset = meta:get_string("offset") - local period = meta:get_string("period") - minetest.set_node(pos, {name = "digtron:soft_digger", - param2 = node.param2}) - meta:set_string("offset", offset) - meta:set_string("period", period) - end -}) - -minetest.register_lbm({ - name = "digtron:fuelstore_upgrade", - nodenames = {"digtron:fuelstore"}, - action = function(pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local list = inv:get_list("main") - inv:set_list("main", {}) - inv:set_list("fuel", list) - meta:set_string("formspec", - "size[8,9.3]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;Fuel items]" .. - "list[current_name;fuel;0,0.6;8,4;]" .. - "list[current_player;main;0,5.15;8,1;]" .. - "list[current_player;main;0,6.38;8,3;8]" .. - "listring[current_name;fuel]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.15) - ) - end -}) - -minetest.register_lbm({ - name = "digtron:autocontroller_lateral_upgrade", - nodenames = {"digtron:auto_controller"}, - action = function(pos, node) - local meta = minetest.get_meta(pos) - local cycles = meta:get_int("offset") - meta:set_int("cycles", cycles) - meta:set_int("offset", 0) - meta:set_int("slope", 0) - meta:set_string("formspec", - "size[3.5,2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "field[0.5,0.8;1,0.1;cycles;Cycles;${cycles}]" .. - "tooltip[cycles;When triggered, this controller will try to run for the given number of cycles.\nThe cycle count will decrement as it runs, so if it gets halted by a problem\nyou can fix the problem and restart.]" .. - "button_exit[1.2,0.5;1,0.1;set;Set]" .. - "tooltip[set;Saves the cycle setting without starting the controller running]" .. - "button_exit[2.2,0.5;1,0.1;execute;Set &\nExecute]" .. - "tooltip[execute;Begins executing the given number of cycles]" .. - "field[0.5,2.0;1,0.1;slope;Slope;${slope}]" .. - "tooltip[slope;For diagonal digging. After every X nodes the auto controller moves forward,\nthe controller will add an additional cycle moving the digtron laterally in the\ndirection of the arrows on the side of this controller.\nSet to 0 for no lateral digging.]" .. - "field[1.5,2.0;1,0.1;offset;Offset;${offset}]" .. - "tooltip[offset;Sets the offset of the lateral motion defined in the Slope field.\nNote: this offset is relative to the controller's location.\nThe controller will move down when it reaches the indicated point.]" .. - "field[2.5,2.0;1,0.1;period;Delay;${period}]" .. - "tooltip[period;Number of seconds to wait between each cycle]" - ) - end -}) - --- internationalization boilerplate -local MP = minetest.get_modpath(minetest.get_current_modname()) -local S, NS = dofile(MP.."/intllib.lua") - -minetest.register_lbm({ - name = "digtron:builder_extrusion_upgrade", - nodenames = {"digtron:builder"}, - action = function(pos, node) - local meta = minetest.get_meta(pos) - meta:set_int("extrusion", 1) - meta:set_string("formspec", - "size[8,5.2]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0.5,0;1,1;]" .. - "label[0.5,0.8;" .. S("Block to build") .. "]" .. - "field[2.3,0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. - "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. - "field[3.3,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. - "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. - "field[4.3,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. - "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. - "button_exit[5.0,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. - "tooltip[set;" .. S("Saves settings") .. "]" .. - "field[6.3,0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. - "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. - "button_exit[7.0,0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. - "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. - "list[current_player;main;0,1.3;8,1;]" .. - default.get_hotbar_bg(0,1.3) .. - "list[current_player;main;0,2.5;8,3;8]" .. - "listring[current_player;main]" .. - "listring[current_name;main]" - ) - end -}) - +-- This code was added for use with FaceDeer's fork of the [catacomb] mod. Paramat's version doesn't support customized protected nodes, which causes +-- it to "eat" Digtrons sometimes. if minetest.get_modpath("catacomb") and catacomb ~= nil and catacomb.chamber_protected_nodes ~= nil and catacomb.passage_protected_nodes ~= nil then local digtron_nodes = { minetest.get_content_id("digtron:inventory"), diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index fa8bb0a..fac1d4b 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -45,6 +45,7 @@ minetest.register_node("digtron:builder", { description = S("Digtron Builder Module"), _doc_items_longdesc = digtron.doc.builder_longdesc, _doc_items_usagehelp = digtron.doc.builder_usagehelp, + _digtron_formspec = builder_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 4}, drop = "digtron:builder", sounds = digtron.metal_sounds, diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua index 76bb40b..a7eda2e 100644 --- a/nodes/node_controllers.lua +++ b/nodes/node_controllers.lua @@ -172,6 +172,7 @@ minetest.register_node("digtron:auto_controller", { description = S("Digtron Automatic Control Module"), _doc_items_longdesc = digtron.doc.auto_controller_longdesc, _doc_items_usagehelp = digtron.doc.auto_controller_usagehelp, + _digtron_formspec = auto_formspec, groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1}, drop = "digtron:auto_controller", sounds = digtron.metal_sounds, @@ -289,7 +290,6 @@ minetest.register_node("digtron:auto_controller", { on_timer = function(pos, elapsed) minetest.get_meta(pos):set_string("waiting", nil) end, - }) --------------------------------------------------------------------------------------------------------------- diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index 017023d..7e30207 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -80,6 +80,7 @@ minetest.register_node("digtron:loaded_crate", { description = S("Digtron Crate (Loaded)"), _doc_items_longdesc = digtron.doc.loaded_crate_longdesc, _doc_items_usagehelp = digtron.doc.loaded_crate_usagehelp, + _digtron_formspec = loaded_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1}, stack_max = 1, sounds = default.node_sound_wood_defaults(), diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua index c12b46c..78d5200 100644 --- a/nodes/node_diggers.lua +++ b/nodes/node_diggers.lua @@ -36,17 +36,17 @@ local intermittent_formspec = "button_exit[2.2,0.5;1,0.1;set;" .. S("Save") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" -local intermittent_on_construct = function(pos) - local formspec = intermittent_formspec - if minetest.get_modpath("doc") then - formspec = "size[4.5,1]" .. formspec .. +if minetest.get_modpath("doc") then + intermittent_formspec = "size[4.5,1]" .. intermittent_formspec .. "button_exit[3.2,0.5;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block") .. "]" else - formspec = "size[3.5,1]" .. formspec + intermittent_formspec = "size[3.5,1]" .. intermittent_formspec end + +local intermittent_on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", formspec) + meta:set_string("formspec", intermittent_formspec) meta:set_int("period", 1) meta:set_int("offset", 0) end @@ -72,6 +72,7 @@ minetest.register_node("digtron:digger", { description = S("Digtron Digger Head"), _doc_items_longdesc = digtron.doc.digger_longdesc, _doc_items_usagehelp = digtron.doc.digger_usagehelp, + _digtron_formspec = intermittent_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, drop = "digtron:digger", sounds = digtron.metal_sounds, @@ -125,6 +126,7 @@ minetest.register_node("digtron:intermittent_digger", { description = S("Digtron Intermittent Digger Head"), _doc_items_longdesc = digtron.doc.intermittent_digger_longdesc, _doc_items_usagehelp = digtron.doc.intermittent_digger_usagehelp, + _digtron_formspec = intermittent_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, drop = "digtron:intermittent_digger", sounds = digtron.metal_sounds, @@ -250,6 +252,7 @@ minetest.register_node("digtron:intermittent_soft_digger", { description = S("Digtron Intermittent Soft Material Digger Head"), _doc_items_longdesc = digtron.doc.intermittent_soft_digger_longdesc, _doc_items_usagehelp = digtron.doc.intermittent_soft_digger_usagehelp, + _digtron_formspec = intermittent_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3}, drop = "digtron:intermittent_soft_digger", sounds = digtron.metal_sounds, @@ -283,7 +286,7 @@ minetest.register_node("digtron:intermittent_soft_digger", { on_construct = intermittent_on_construct, on_receive_fields = intermittent_on_receive_fields, - + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig) if lateral_dig == true then return 0, {} diff --git a/nodes/node_storage.lua b/nodes/node_storage.lua index 826aa20..56d19aa 100644 --- a/nodes/node_storage.lua +++ b/nodes/node_storage.lua @@ -2,12 +2,27 @@ local MP = minetest.get_modpath(minetest.get_current_modname()) local S, NS = dofile(MP.."/intllib.lua") + +local inventory_formspec = + "size[8,9.3]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Inventory items") .. "]" .. + "list[current_name;main;0,0.6;8,4;]" .. + "list[current_player;main;0,5.15;8,1;]" .. + "list[current_player;main;0,6.38;8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.15) + -- 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", { description = S("Digtron Inventory Storage"), _doc_items_longdesc = digtron.doc.inventory_longdesc, _doc_items_usagehelp = digtron.doc.inventory_usagehelp, + _digtron_formspec = inventory_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 2, tubedevice = 1, tubedevice_receiver = 1}, drop = "digtron:inventory", sounds = digtron.metal_sounds, @@ -26,19 +41,7 @@ minetest.register_node("digtron:inventory", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.3]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Inventory items") .. "]" .. - "list[current_name;main;0,0.6;8,4;]" .. - "list[current_player;main;0,5.15;8,1;]" .. - "list[current_player;main;0,6.38;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.15) - ) + meta:set_string("formspec", inventory_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) end, @@ -48,7 +51,7 @@ minetest.register_node("digtron:inventory", { local inv = meta:get_inventory() return inv:is_empty("main") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- @@ -71,12 +74,26 @@ minetest.register_node("digtron:inventory", { after_dig_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_dig end end)() }) +local fuelstore_formspec = + "size[8,9.3]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Fuel items") .. "]" .. + "list[current_name;fuel;0,0.6;8,4;]" .. + "list[current_player;main;0,5.15;8,1;]" .. + "list[current_player;main;0,6.38;8,3;8]" .. + "listring[current_name;fuel]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.15) + -- Fuel storage. Controller node draws fuel from here. -- Note that fuel stores are digtron group 5. minetest.register_node("digtron:fuelstore", { description = S("Digtron Fuel Storage"), _doc_items_longdesc = digtron.doc.fuelstore_longdesc, _doc_items_usagehelp = digtron.doc.fuelstore_usagehelp, + _digtron_formspec = fuelstore_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 5, tubedevice = 1, tubedevice_receiver = 1}, drop = "digtron:fuelstore", sounds = digtron.metal_sounds, @@ -95,19 +112,7 @@ minetest.register_node("digtron:fuelstore", { on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.3]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Fuel items") .. "]" .. - "list[current_name;fuel;0,0.6;8,4;]" .. - "list[current_player;main;0,5.15;8,1;]" .. - "list[current_player;main;0,6.38;8,3;8]" .. - "listring[current_name;fuel]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.15) - ) + meta:set_string("formspec", fuelstore_formspec) local inv = meta:get_inventory() inv:set_size("fuel", 8*4) end, @@ -129,7 +134,7 @@ minetest.register_node("digtron:fuelstore", { local inv = meta:get_inventory() return inv:is_empty("fuel") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- @@ -158,11 +163,28 @@ minetest.register_node("digtron:fuelstore", { after_dig_node = (function() if minetest.get_modpath("pipeworks")then return pipeworks.after_dig end end)() }) +local combined_storage_formspec = + "size[8,9.9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "label[0,0;" .. S("Inventory items") .. "]" .. + "list[current_name;main;0,0.6;8,3;]" .. + "label[0,3.5;" .. S("Fuel items") .. "]" .. + "list[current_name;fuel;0,4.1;8,1;]" .. + "list[current_player;main;0,5.75;8,1;]" .. + "list[current_player;main;0,6.98;8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.75) + + -- Combined storage. Group 6 has both an inventory and a fuel store minetest.register_node("digtron:combined_storage", { description = S("Digtron Combined Storage"), _doc_items_longdesc = digtron.doc.combined_storage_longdesc, _doc_items_usagehelp = digtron.doc.combined_storage_usagehelp, + _digtron_formspec = combined_storage_formspec, groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 6, tubedevice = 1, tubedevice_receiver = 1}, drop = "digtron:combined_storage", sounds = digtron.metal_sounds, @@ -179,21 +201,7 @@ minetest.register_node("digtron:combined_storage", { }, on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9.9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "label[0,0;" .. S("Inventory items") .. "]" .. - "list[current_name;main;0,0.6;8,3;]" .. - "label[0,3.5;" .. S("Fuel items") .. "]" .. - "list[current_name;fuel;0,4.1;8,1;]" .. - "list[current_player;main;0,5.75;8,1;]" .. - "list[current_player;main;0,6.98;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,5.75) - ) + meta:set_string("formspec", combined_storage_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*3) inv:set_size("fuel", 8*1) @@ -230,7 +238,7 @@ minetest.register_node("digtron:combined_storage", { local inv = meta:get_inventory() return inv:is_empty("fuel") and inv:is_empty("main") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- tube = (function() if minetest.get_modpath("pipeworks") then return { diff --git a/upgrades.lua b/upgrades.lua new file mode 100644 index 0000000..8f0c6fb --- /dev/null +++ b/upgrades.lua @@ -0,0 +1,57 @@ +-- re-applies the "_digtron_formspec" property from all digtron node defs to the digtron node's metadata. +minetest.register_lbm({ + name = "digtron:generic_formspec_sanitizer", + nodenames = {"group:digtron"}, + action = function(pos, node) + local node_def = minetest.registered_nodes[node.name] + local meta = minetest.get_meta(pos) + meta:set_string("formspec", node_def._digtron_formspec) + end +}) + +minetest.register_lbm({ + name = "digtron:sand_digger_upgrade", + nodenames = {"digtron:sand_digger"}, + action = function(pos, node) + local meta = minetest.get_meta(pos) + local offset = meta:get_string("offset") + local period = meta:get_string("period") + minetest.set_node(pos, {name = "digtron:soft_digger", + param2 = node.param2}) + meta:set_string("offset", offset) + meta:set_string("period", period) + end +}) + +minetest.register_lbm({ + name = "digtron:fuelstore_upgrade", + nodenames = {"digtron:fuelstore"}, + action = function(pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local list = inv:get_list("main") + inv:set_list("main", {}) + inv:set_list("fuel", list) + end +}) + +minetest.register_lbm({ + name = "digtron:autocontroller_lateral_upgrade", + nodenames = {"digtron:auto_controller"}, + action = function(pos, node) + local meta = minetest.get_meta(pos) + local cycles = meta:get_int("offset") + meta:set_int("cycles", cycles) + meta:set_int("offset", 0) + meta:set_int("slope", 0) + end +}) + +minetest.register_lbm({ + name = "digtron:builder_extrusion_upgrade", + nodenames = {"digtron:builder"}, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_int("extrusion", 1) + end +}) \ No newline at end of file -- cgit v1.2.3 From 3bc0eb82fa4796c32b6800e5833953262f8e0b0c Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 23:13:31 -0600 Subject: add formspec auto-upgrade when layout is read --- class_layout.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/class_layout.lua b/class_layout.lua index d516870..63ce529 100644 --- a/class_layout.lua +++ b/class_layout.lua @@ -6,9 +6,13 @@ DigtronLayout.__index = DigtronLayout local get_node_image = function(pos, node) local node_image = {node=node, pos={x=pos.x, y=pos.y, z=pos.z}} - node_image.paramtype2 = minetest.registered_nodes[node.name].paramtype2 + local node_def = minetest.registered_nodes[node.name] + node_image.paramtype2 = node_def.paramtype2 local meta = minetest.get_meta(pos) node_image.meta = meta:to_table() + if node_image.meta ~= nil then + node_image.meta.fields.formspec = node_def._digtron_formspec -- causes formspec to be automatically upgraded whenever Digtron moves + end -- Record what kind of thing we've got in a builder node so its facing can be rotated properly if minetest.get_item_group(node.name, "digtron") == 4 then -- cgit v1.2.3 From 04228904f52214d508831b8df28adcab28e88ae8 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 23:25:11 -0600 Subject: reuse period/offset markers for intermittent diggers --- nodes/node_builders.lua | 28 +--------------------------- nodes/node_diggers.lua | 5 ++++- util.lua | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index fac1d4b..bfd7c00 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -123,33 +123,7 @@ minetest.register_node("digtron:builder", { end if fields.set then - local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2) - local x_pos = math.floor((buildpos.x+offset)/period)*period - offset - minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker") - if x_pos >= buildpos.x then - minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker") - end - if x_pos <= buildpos.x then - minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker") - end - - local y_pos = math.floor((buildpos.y+offset)/period)*period - offset - minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical") - if y_pos >= buildpos.y then - minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical") - end - if y_pos <= buildpos.y then - minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical") - end - - local z_pos = math.floor((buildpos.z+offset)/period)*period - offset - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708) - if z_pos >= buildpos.z then - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708) - end - if z_pos <= buildpos.z then - minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708) - end + digtron.show_offset_markers(pos, offset, period) elseif fields.read then local facing = minetest.get_node(pos).param2 diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua index 78d5200..bf48f71 100644 --- a/nodes/node_diggers.lua +++ b/nodes/node_diggers.lua @@ -33,7 +33,7 @@ local intermittent_formspec = "tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" .. "field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" .. - "button_exit[2.2,0.5;1,0.1;set;" .. S("Save") .. "]" .. + "button_exit[2.2,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" if minetest.get_modpath("doc") then @@ -65,6 +65,9 @@ local intermittent_on_receive_fields = function(pos, formname, fields, sender) local node_name = minetest.get_node(pos).name minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true) end + if fields.set then + digtron.show_offset_markers(pos, offset, period) + end end, -- Digs out nodes that are "in front" of the digger head. diff --git a/util.lua b/util.lua index 3f1d732..63903b1 100644 --- a/util.lua +++ b/util.lua @@ -240,4 +240,34 @@ digtron.is_soft_material = function(target) return true end return false +end + +digtron.show_offset_markers = function(pos, offset, period) + local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2) + local x_pos = math.floor((buildpos.x+offset)/period)*period - offset + minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker") + if x_pos >= buildpos.x then + minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker") + end + if x_pos <= buildpos.x then + minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker") + end + + local y_pos = math.floor((buildpos.y+offset)/period)*period - offset + minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical") + if y_pos >= buildpos.y then + minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical") + end + if y_pos <= buildpos.y then + minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical") + end + + local z_pos = math.floor((buildpos.z+offset)/period)*period - offset + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708) + if z_pos >= buildpos.z then + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708) + end + if z_pos <= buildpos.z then + minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708) + end end \ No newline at end of file -- cgit v1.2.3 From 860890b10061d76c5ea011fe0befca435be5f243 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 19 Sep 2017 23:44:59 -0600 Subject: update localization --- locale/template.pot | 290 +++++++++++++++++++++------------------------ nodes/node_builders.lua | 4 +- nodes/node_controllers.lua | 10 +- util_execute_cycle.lua | 17 ++- 4 files changed, 153 insertions(+), 168 deletions(-) diff --git a/locale/template.pot b/locale/template.pot index 7489c3a..614fa41 100644 --- a/locale/template.pot +++ b/locale/template.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-10 19:05-0600\n" +"POT-Creation-Date: 2017-09-19 23:37-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -890,51 +890,87 @@ msgid "" "pass through the structure as it's being built." msgstr "" -#: node_axle.lua:6 -msgid "Digtron Rotation Axle" +#: util_execute_cycle.lua:51 +msgid "Digtron is adjacent to unloaded nodes." +msgstr "" + +#: util_execute_cycle.lua:65 +msgid "Digtron has @1 blocks but only enough traction to move @2 blocks.\n" +msgstr "" + +#: util_execute_cycle.lua:110 +#: util_execute_cycle.lua:316 +#: util_execute_cycle.lua:393 +#: util_execute_cycle.lua:504 +#: nodes\node_controllers.lua:48 +#: nodes\node_controllers.lua:201 +msgid "Heat remaining in controller furnace: @1" msgstr "" -#: node_axle.lua:57 #: util_execute_cycle.lua:172 -#: util_execute_cycle.lua:367 -#: util_execute_cycle.lua:456 +#: util_execute_cycle.lua:366 +#: util_execute_cycle.lua:455 +#: nodes\node_axle.lua:57 msgid "Digtron is obstructed." msgstr "" -#: node_builders.lua:13 +#: util_execute_cycle.lua:220 +msgid "Digtron needs more fuel." +msgstr "" + +#: util_execute_cycle.lua:230 +msgid "" +"Digtron connected to at least one builder with no output material assigned." +msgstr "" + +#: util_execute_cycle.lua:234 +msgid "Digtron has insufficient building materials. Needed: @1" +msgstr "" + +#: util_execute_cycle.lua:303 +msgid "" +"Digtron unexpectedly failed to execute one or more build operations, likely " +"due to an inventory error." +msgstr "" + +#: nodes\node_axle.lua:6 +msgid "Digtron Rotation Axle" +msgstr "" + +#: nodes\node_builders.lua:18 msgid "Block to build" msgstr "" -#: node_builders.lua:14 +#: nodes\node_builders.lua:19 msgid "Extrusion" msgstr "" -#: node_builders.lua:15 +#: nodes\node_builders.lua:20 msgid "" "Builder will extrude this many blocks in the direction it is facing.\n" "Can be set from 1 to @1.\n" "Note that Digtron won't build into unloaded map regions." msgstr "" -#: node_builders.lua:16 -#: node_diggers.lua:32 +#: nodes\node_builders.lua:21 +#: nodes\node_diggers.lua:32 msgid "Periodicity" msgstr "" -#: node_builders.lua:17 +#: nodes\node_builders.lua:22 msgid "" "Builder will build once every n steps.\n" "These steps are globally aligned, so all builders with the\n" "same period and offset will build on the same location." msgstr "" -#: node_builders.lua:18 -#: node_controllers.lua:91 -#: node_diggers.lua:34 +#: nodes\node_builders.lua:23 +#: nodes\node_controllers.lua:91 +#: nodes\node_diggers.lua:34 msgid "Offset" msgstr "" -#: node_builders.lua:19 +#: nodes\node_builders.lua:24 msgid "" "Offsets the start of periodicity counting by this amount.\n" "For example, a builder with period 2 and offset 0 builds\n" @@ -942,83 +978,68 @@ msgid "" "offset 1 builds every odd-numbered block." msgstr "" -#: node_builders.lua:20 +#: nodes\node_builders.lua:25 +#: nodes\node_diggers.lua:36 msgid "" "Save &\n" "Show" msgstr "" -#: node_builders.lua:21 -#: node_diggers.lua:37 +#: nodes\node_builders.lua:26 +#: nodes\node_diggers.lua:37 msgid "Saves settings" msgstr "" -#: node_builders.lua:22 +#: nodes\node_builders.lua:27 msgid "Facing" msgstr "" -#: node_builders.lua:23 +#: nodes\node_builders.lua:28 msgid "" "Value from 0-23. Not all block types make use of this.\n" "Use the 'Read & Save' button to copy the facing of the block\n" "currently in the builder output location." msgstr "" -#: node_builders.lua:24 +#: nodes\node_builders.lua:29 msgid "" "Read &\n" "Save" msgstr "" -#: node_builders.lua:25 +#: nodes\node_builders.lua:30 msgid "" "Reads the facing of the block currently in the build location,\n" "then saves all settings." msgstr "" -#: node_builders.lua:34 -#: node_controllers.lua:106 -#: node_crate.lua:62 -#: node_diggers.lua:43 +#: nodes\node_builders.lua:39 +#: nodes\node_controllers.lua:106 +#: nodes\node_crate.lua:62 +#: nodes\node_diggers.lua:41 msgid "Help" msgstr "" -#: node_builders.lua:35 -#: node_controllers.lua:107 -#: node_crate.lua:63 -#: node_diggers.lua:44 +#: nodes\node_builders.lua:40 +#: nodes\node_controllers.lua:107 +#: nodes\node_crate.lua:63 +#: nodes\node_diggers.lua:42 msgid "Show documentation about this block" msgstr "" -#: node_builders.lua:40 +#: nodes\node_builders.lua:45 msgid "Digtron Builder Module" msgstr "" -#: node_builders.lua:279 -#: node_builders.lua:294 -#, lua-format -msgid "%s uses Digtron to build %s at (%d, %d, %d), displacing %s" -msgstr "" - -#: node_controllers.lua:20 +#: nodes\node_controllers.lua:20 msgid "Digtron Control Module" msgstr "" -#: node_controllers.lua:48 -#: node_controllers.lua:200 -#: util_execute_cycle.lua:110 -#: util_execute_cycle.lua:317 -#: util_execute_cycle.lua:394 -#: util_execute_cycle.lua:505 -#, lua-format -msgid "Heat remaining in controller furnace: %d" -msgstr "" - -#: node_controllers.lua:83 +#: nodes\node_controllers.lua:83 msgid "Cycles" msgstr "" -#: node_controllers.lua:84 +#: nodes\node_controllers.lua:84 msgid "" "When triggered, this controller will try to run for the given number of " "cycles.\n" @@ -1027,29 +1048,29 @@ msgid "" "you can fix the problem and restart." msgstr "" -#: node_controllers.lua:85 +#: nodes\node_controllers.lua:85 msgid "Set" msgstr "" -#: node_controllers.lua:86 +#: nodes\node_controllers.lua:86 msgid "Saves the cycle setting without starting the controller running" msgstr "" -#: node_controllers.lua:87 +#: nodes\node_controllers.lua:87 msgid "" "Set &\n" "Execute" msgstr "" -#: node_controllers.lua:88 +#: nodes\node_controllers.lua:88 msgid "Begins executing the given number of cycles" msgstr "" -#: node_controllers.lua:89 +#: nodes\node_controllers.lua:89 msgid "Slope" msgstr "" -#: node_controllers.lua:90 +#: nodes\node_controllers.lua:90 msgid "" "For diagonal digging. After moving forward this number of nodes the auto " "controller\n" @@ -1058,127 +1079,126 @@ msgid "" "Set to 0 for no lateral digging." msgstr "" -#: node_controllers.lua:92 +#: nodes\node_controllers.lua:92 msgid "" "Sets the offset of the lateral motion defined in the Slope field.\n" "Note: this offset is relative to the controller's location.\n" "The controller will move laterally when it reaches the indicated point." msgstr "" -#: node_controllers.lua:93 +#: nodes\node_controllers.lua:93 msgid "Delay" msgstr "" -#: node_controllers.lua:94 +#: nodes\node_controllers.lua:94 msgid "Number of seconds to wait between each cycle" msgstr "" -#: node_controllers.lua:96 +#: nodes\node_controllers.lua:96 msgid "Stop block" msgstr "" -#: node_controllers.lua:128 -#: node_controllers.lua:147 -#: node_controllers.lua:160 -#, lua-format -msgid "Cycles remaining: %d" +#: nodes\node_controllers.lua:128 +#: nodes\node_controllers.lua:147 +#: nodes\node_controllers.lua:160 +msgid "Cycles remaining: @1" msgstr "" -#: node_controllers.lua:128 -#: node_controllers.lua:147 +#: nodes\node_controllers.lua:128 +#: nodes\node_controllers.lua:147 msgid "Halted!" msgstr "" -#: node_controllers.lua:172 +#: nodes\node_controllers.lua:172 msgid "Digtron Automatic Control Module" msgstr "" -#: node_controllers.lua:284 +#: nodes\node_controllers.lua:285 msgid "Interrupted!" msgstr "" -#: node_controllers.lua:300 +#: nodes\node_controllers.lua:300 msgid "Digtron Pusher Module" msgstr "" -#: node_crate.lua:6 +#: nodes\node_crate.lua:6 msgid "Digtron Crate (Empty)" msgstr "" -#: node_crate.lua:22 +#: nodes\node_crate.lua:22 msgid "Digtron can't be packaged, it contains protected blocks" msgstr "" -#: node_crate.lua:42 -#: node_crate.lua:43 +#: nodes\node_crate.lua:42 +#: nodes\node_crate.lua:43 msgid "Crated Digtron" msgstr "" -#: node_crate.lua:55 -#: node_crate.lua:70 +#: nodes\node_crate.lua:55 +#: nodes\node_crate.lua:70 msgid "Digtron Name" msgstr "" -#: node_crate.lua:56 -#: node_crate.lua:71 +#: nodes\node_crate.lua:56 +#: nodes\node_crate.lua:71 msgid "" "Save\n" "Title" msgstr "" -#: node_crate.lua:57 -#: node_crate.lua:72 +#: nodes\node_crate.lua:57 +#: nodes\node_crate.lua:72 msgid "Saves the title of this Digtron" msgstr "" -#: node_crate.lua:58 -#: node_crate.lua:73 +#: nodes\node_crate.lua:58 +#: nodes\node_crate.lua:73 msgid "" "Show\n" "Blocks" msgstr "" -#: node_crate.lua:59 -#: node_crate.lua:74 +#: nodes\node_crate.lua:59 +#: nodes\node_crate.lua:74 msgid "Shows which blocks the packed Digtron will occupy if unpacked" msgstr "" -#: node_crate.lua:60 -#: node_crate.lua:75 +#: nodes\node_crate.lua:60 +#: nodes\node_crate.lua:75 msgid "Unpack" msgstr "" -#: node_crate.lua:61 -#: node_crate.lua:76 +#: nodes\node_crate.lua:61 +#: nodes\node_crate.lua:76 msgid "Attempts to unpack the Digtron on this location" msgstr "" -#: node_crate.lua:80 +#: nodes\node_crate.lua:80 msgid "Digtron Crate (Loaded)" msgstr "" -#: node_crate.lua:114 +#: nodes\node_crate.lua:115 msgid "" "Unable to read layout from crate metadata, regrettably this Digtron may be " "corrupted or lost." msgstr "" -#: node_crate.lua:145 +#: nodes\node_crate.lua:146 msgid "Unable to deploy Digtron due to protected blocks in target area" msgstr "" -#: node_crate.lua:151 +#: nodes\node_crate.lua:152 msgid "Unable to deploy Digtron due to obstruction in target area" msgstr "" -#: node_diggers.lua:33 +#: nodes\node_diggers.lua:33 msgid "" "Digger will dig once every n steps.\n" "These steps are globally aligned, all diggers with\n" "the same period and offset will dig on the same location." msgstr "" -#: node_diggers.lua:35 +#: nodes\node_diggers.lua:35 msgid "" "Offsets the start of periodicity counting by this amount.\n" "For example, a digger with period 2 and offset 0 digs\n" @@ -1186,106 +1206,72 @@ msgid "" "offset 1 digs every odd-numbered block." msgstr "" -#: node_diggers.lua:36 -msgid "Save" -msgstr "" - -#: node_diggers.lua:72 +#: nodes\node_diggers.lua:75 msgid "Digtron Digger Head" msgstr "" -#: node_diggers.lua:125 +#: nodes\node_diggers.lua:129 msgid "Digtron Intermittent Digger Head" msgstr "" -#: node_diggers.lua:195 +#: nodes\node_diggers.lua:200 msgid "Digtron Soft Material Digger Head" msgstr "" -#: node_diggers.lua:250 +#: nodes\node_diggers.lua:255 msgid "Digtron Intermittent Soft Material Digger Head" msgstr "" -#: node_diggers.lua:323 +#: nodes\node_diggers.lua:329 msgid "Digtron Dual Digger Head" msgstr "" -#: node_diggers.lua:400 +#: nodes\node_diggers.lua:406 msgid "Digtron Dual Soft Material Digger Head" msgstr "" -#: node_misc.lua:7 +#: nodes\node_misc.lua:7 msgid "Digtron Structure" msgstr "" -#: node_misc.lua:40 +#: nodes\node_misc.lua:40 msgid "Digtron Light" msgstr "" -#: node_misc.lua:62 +#: nodes\node_misc.lua:62 msgid "Digtron Panel" msgstr "" -#: node_misc.lua:85 +#: nodes\node_misc.lua:85 msgid "Digtron Edge Panel" msgstr "" -#: node_misc.lua:114 +#: nodes\node_misc.lua:114 msgid "Digtron Corner Panel" msgstr "" -#: node_storage.lua:8 -msgid "Digtron Inventory Storage" -msgstr "" - -#: node_storage.lua:34 -#: node_storage.lua:187 +#: nodes\node_storage.lua:11 +#: nodes\node_storage.lua:171 msgid "Inventory items" msgstr "" -#: node_storage.lua:77 -msgid "Digtron Fuel Storage" +#: nodes\node_storage.lua:22 +msgid "Digtron Inventory Storage" msgstr "" -#: node_storage.lua:103 -#: node_storage.lua:189 +#: nodes\node_storage.lua:82 +#: nodes\node_storage.lua:173 msgid "Fuel items" msgstr "" -#: node_storage.lua:163 -msgid "Digtron Combined Storage" -msgstr "" - -#: recipes.lua:6 -msgid "Digtron Core" -msgstr "" - -#: util_execute_cycle.lua:51 -msgid "Digtron is adjacent to unloaded nodes." -msgstr "" - -#: util_execute_cycle.lua:220 -msgid "Digtron needs more fuel." -msgstr "" - -#: util_execute_cycle.lua:230 -msgid "" -"Digtron connected to at least one builder with no output material assigned." -msgstr "" - -#: util_execute_cycle.lua:234 -#, lua-format -msgid "Digtron has insufficient building materials. Needed: %s" +#: nodes\node_storage.lua:93 +msgid "Digtron Fuel Storage" msgstr "" -#: util_execute_cycle.lua:304 -msgid "" -"Digtron unexpectedly failed to execute one or more build operations, likely " -"due to an inventory error." +#: nodes\node_storage.lua:184 +msgid "Digtron Combined Storage" msgstr "" -#: util_execute_cycle.lua:329 -#: util_execute_cycle.lua:517 -#, lua-format -msgid "%s uses Digtron to dig %s at (%d, %d, %d)" +#: nodes\recipes.lua:6 +msgid "Digtron Core" msgstr "" diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index bfd7c00..ecb76cd 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -262,7 +262,7 @@ minetest.register_node("digtron:builder", { if not digtron.config.uses_resources then local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) if success == true then - minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) + minetest.log("action", string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) built_count = built_count + 1 else @@ -277,7 +277,7 @@ minetest.register_node("digtron:builder", { end local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) if success == true then - minetest.log("action", string.format(S("%s uses Digtron to build %s at (%d, %d, %d), displacing %s"), player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) + minetest.log("action", string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) --flag this node as *not* to be dug. nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) digtron.award_item_built(item_stack:get_name(), player:get_player_name()) diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua index a7eda2e..4382734 100644 --- a/nodes/node_controllers.lua +++ b/nodes/node_controllers.lua @@ -45,7 +45,7 @@ minetest.register_node("digtron:controller", { on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_float("fuel_burning", 0.0) - meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) + meta:set_string("infotext", S("Heat remaining in controller furnace: @1", 0)) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) @@ -125,7 +125,7 @@ digtron.auto_cycle = function(pos) local newpos, status, return_code = digtron.execute_downward_dig_cycle(pos, player) if vector.equals(pos, newpos) then - status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) + status = status .. "\n" .. S("Cycles remaining: @1", cycle) .. "\n" .. S("Halted!") meta:set_string("infotext", status) if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) @@ -144,7 +144,7 @@ digtron.auto_cycle = function(pos) local newpos, status, return_code = digtron.execute_dig_cycle(pos, player) if vector.equals(pos, newpos) then - status = status .. string.format("\n" .. S("Cycles remaining: %d") .. "\n" .. S("Halted!"), cycle) + status = status .. "\n" .. S("Cycles remaining: @1", cycle) .. "\n" .. S("Halted!") meta:set_string("infotext", status) if return_code == 1 then --return code 1 happens when there's unloaded nodes adjacent, just keep trying. minetest.after(meta:get_int("period"), digtron.auto_cycle, newpos) @@ -157,7 +157,7 @@ digtron.auto_cycle = function(pos) meta = minetest.get_meta(newpos) cycle = meta:get_int("cycles") - 1 meta:set_int("cycles", cycle) - status = status .. string.format("\n" .. S("Cycles remaining: %d"), cycle) + status = status .. "\n" .. S("Cycles remaining: @1", cycle) meta:set_string("infotext", status) meta:set_string("lateral_done", nil) @@ -198,7 +198,7 @@ minetest.register_node("digtron:auto_controller", { on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_float("fuel_burning", 0.0) - meta:set_string("infotext", string.format(S("Heat remaining in controller furnace: %d"), 0)) + meta:set_string("infotext", S("Heat remaining in controller furnace: @1", 0)) meta:set_string("formspec", auto_formspec) -- Reusing offset and period to keep the digtron node-moving code simple, and the names still fit well meta:set_int("period", digtron.config.cycle_time) diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index e671480..38f4381 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -62,7 +62,7 @@ local function neighbour_test(layout, status_text, dir) if dir and dir.y ~= -1 and layout.traction * digtron.config.traction_factor < table.getn(layout.all) then -- digtrons can't fly, though they can fall minetest.sound_play("squeal", {gain=1.0, pos=layout.controller}) - return string.format("Digtron has %d blocks but only enough traction to move %d blocks.\n", table.getn(layout.all), layout.traction * digtron.config.traction_factor) + return S("Digtron has @1 blocks but only enough traction to move @2 blocks.\n", table.getn(layout.all), layout.traction * digtron.config.traction_factor) .. status_text, 2 end @@ -107,7 +107,7 @@ digtron.execute_dig_cycle = function(pos, clicker) local facing = minetest.get_node(pos).param2 local dir = minetest.facedir_to_dir(facing) local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle - local status_text = string.format(S("Heat remaining in controller furnace: %d"), math.max(0, fuel_burning)) + local status_text = S("Heat remaining in controller furnace: @1", math.max(0, fuel_burning)) local layout = DigtronLayout.create(pos, clicker) @@ -231,8 +231,7 @@ digtron.execute_dig_cycle = function(pos, clicker) return_code = 6 elseif test_build_return_code == 2 then minetest.sound_play("dingding", {gain=1.0, pos=pos}) -- Insufficient inventory - return_string = string.format(S("Digtron has insufficient building materials. Needed: %s") .. "\n", - failed_to_find:get_name()) + return_string = S("Digtron has insufficient building materials. Needed: @1", failed_to_find:get_name()) .. "\n" return_code = 7 end return pos, return_string .. status_text, return_code --Abort, don't dig and don't build. @@ -314,7 +313,7 @@ digtron.execute_dig_cycle = function(pos, clicker) fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false) end meta:set_float("fuel_burning", fuel_burning) - status_text = status_text .. string.format(S("Heat remaining in controller furnace: %d"), math.max(0, fuel_burning)) + status_text = status_text .. S("Heat remaining in controller furnace: @1", math.max(0, fuel_burning)) -- Eyecandy for _, particles in pairs(particle_systems) do @@ -326,7 +325,7 @@ digtron.execute_dig_cycle = function(pos, clicker) local node_to_dig, whether_to_dig = layout.nodes_dug:pop() while node_to_dig ~= nil do if whether_to_dig == true then - minetest.log("action", string.format(S("%s uses Digtron to dig %s at (%d, %d, %d)"), clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) + minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) minetest.remove_node(node_to_dig) end -- all of the digtron's nodes wind up in nodes_dug, so this is an ideal place to stick @@ -391,7 +390,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) local facing = minetest.get_node(pos).param2 local dir = digtron.facedir_to_down_dir(facing) local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle - local status_text = string.format(S("Heat remaining in controller furnace: %d"), math.max(0, fuel_burning)) + local status_text = S("Heat remaining in controller furnace: @1", math.max(0, fuel_burning)) local layout = DigtronLayout.create(pos, clicker) @@ -502,7 +501,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false) end meta:set_float("fuel_burning", fuel_burning) - status_text = status_text .. string.format(S("Heat remaining in controller furnace: %d"), math.max(0, fuel_burning)) + status_text = status_text .. S("Heat remaining in controller furnace: @1", math.max(0, fuel_burning)) -- Eyecandy for _, particles in pairs(particle_systems) do @@ -514,7 +513,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) local node_to_dig, whether_to_dig = layout.nodes_dug:pop() while node_to_dig ~= nil do if whether_to_dig == true then - minetest.log("action", string.format(S("%s uses Digtron to dig %s at (%d, %d, %d)"), clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) + minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) minetest.remove_node(node_to_dig) end -- all of the digtron's nodes wind up in nodes_dug, so this is an ideal place to stick -- cgit v1.2.3