From 2695c6103383996fedfd12098cf3f28c5fc43fe2 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Fri, 30 Dec 2016 23:38:18 -0700 Subject: Initial commit Initial commit. Contains digger head, sand digger, builder, controller, pusher, structure node, light, inventory, and digtron core crafting item. --- node_diggers.lua | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 node_diggers.lua (limited to 'node_diggers.lua') diff --git a/node_diggers.lua b/node_diggers.lua new file mode 100644 index 0000000..f2ffdff --- /dev/null +++ b/node_diggers.lua @@ -0,0 +1,147 @@ +-- 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 +} + +-- Digs out nodes that are "in front" of the digger head. +minetest.register_node("digtron:digger", { + description = "Digger Head", + groups = {cracky = 3, stone = 1, digtron = 3}, + drop = 'digtron:digger', + paramtype = "light", + paramtype2= 'facedir', + + 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.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_motor.png", + }, + + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("formspec", + "size[3.5,1]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "field[0.5,0.8;1,0.1;period;Periodicity;${period}]" .. + "tooltip[period;Digger will dig once every n steps. These steps are globally aligned, all diggers with the same period and offset will dig on the same location.]" .. + "field[1.5,0.8;1,0.1;offset;Offset;${offset}]" .. + "tooltip[offset;Offsets the start of periodicity counting by this amount. For example, a digger with period 2 and offset 0 digs every even-numbered node and one with period 2 and offset 1 digs every odd-numbered node.]" .. + "button_exit[2.2,0.5;1,0.1;set;Save]" .. + "tooltip[set;Saves settings]" + ) + meta:set_string("period", 1) + meta:set_string("offset", 0) + + 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) + if period and period > 0 then + meta:set_string("period", math.floor(tonumber(fields.period))) + end + if offset then + meta:set_string("offset", math.floor(tonumber(fields.offset))) + end + end, + + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate) + 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 nil + end + + local meta = minetest.get_meta(pos) + if (digpos[controlling_coordinate] + meta:get_string("offset")) % meta:get_string("period") ~= 0 then + return nil + end + + return digtron.mark_diggable(digpos, nodes_dug) + 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:sand_digger", { + description = "Sand Digger Head", + groups = {cracky = 3, stone = 1, digtron = 3}, + drop = 'digtron:sand_digger', + paramtype = "light", + paramtype2= 'facedir', + + drawtype="nodebox", + node_box = { + type = "fixed", + fixed = digger_nodebox, + }, + + -- Aims in the +Z direction by default + tiles = { + "digtron_plate.png^[transformR90^[colorize:#88880030", + "digtron_plate.png^[transformR270^[colorize:#88880030", + "digtron_plate.png^[colorize:#88880030", + "digtron_plate.png^[transformR180^[colorize:#88880030", + { + name = "digtron_digger.png^[colorize:#88880030", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 1.0, + }, + }, + "digtron_motor.png^[colorize:#88880030", + }, + + can_dig = function(pos,player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:is_empty("main") and inv:is_empty("inv") + end, + + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate) + 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 nil + end + + local target_node = minetest.get_node(digpos) + if minetest.get_item_group(target_node.name, "falling_node") ~= 0 then + return digtron.mark_diggable(digpos, nodes_dug) + end + + return nil + end, +}) \ No newline at end of file -- cgit v1.2.3