local NAME = minetest.get_current_modname() local ENERGYCOST = { static_struts = 20, dynamic_struct = 24, hardness_mod = 1 } local function on_construct(pos, player) player:get_meta():set_string(NAME .. ":quarry_pos" , minetest.pos_to_string(pos)) end local function on_marker_placed(pos, quarry_pos, player) -- Validate position if quarry_pos.x == pos.x and quarry_pos.y == pos.y and quarry_pos.z == pos.z then -- Invalid position, marker replaced quarry somehow return -- TODO Report failure? -- TODO clear clipboard in quarry on_break end -- TODO Possibly do a size check -- Set quarry metadata local meta = minetest.get_meta(quarry_pos) meta:set_string("marker", minetest.pos_to_string(pos)) meta:set_int("current_frame", 13) minetest.get_node_timer(quarry_pos):start(1.0) end local function marker_construct(pos, player) local quarry_pos = minetest.string_to_pos(player:get_meta():get_string(NAME .. ":quarry_pos")) local quarry = minetest.get_node(quarry_pos) on_marker_placed(pos, quarry_pos, player) end local function order(x, y) if x <= y then return x, y else return y,x end end local function clear_area(pos, pos2) local minx, maxx = order(pos.x, pos2.x) local miny, maxy = order(pos.y, pos2.y) local minz, maxz = order(pos.z, pos2.z) for x=minx , maxx do for y=miny, maxy do for z=minz, maxz do -- dont remove quarry or marker if not ((x == pos.x and y == pos.y and z == pos.z) or (x == pos2.x and y == pos2.y and z == pos2.z)) then minetest.dig_node({ x=x, y=y, z=z }) end end end end end local function place_strut(x, y, z) local position = { x=x, y=y, z=z } if minetest.get_node(position).name == "air" then minetest.set_node(position, { name = NAME .. ":static_strut"}) end end local function strut_line_x(x, y, z, x2) local minx, maxx = order(x, x2) minetest.debug(" x:" .. minx .. ":" .. maxx) for x3=minx, maxx do minetest.debug("x") place_strut(x3, y, z) end end local function strut_line_y(x, y, z, y2) local miny, maxy = order(y, y2) minetest.debug(" y:" .. miny .. ":" .. maxy) for y3=miny, maxy do minetest.debug("y") place_strut(x, y3, z) end end local function strut_line_z(x, y, z, z2) local minz, maxz = order(z, z2) minetest.debug(" z:" .. minz .. ":" .. maxz) for z3=minz, maxz do minetest.debug("z") place_strut(x, y, z3) end end local function timer_trigger(pos, elapsed) local meta = minetest.get_meta(pos) local framenum = meta:get_int("current_frame") local marker_pos = minetest.string_to_pos(meta:get_string("marker")) if not framenum then framenum = 13 end if framenum < 0 then -- Operation Phase -- else -- preparation phase if framenum == 13 then -- stripmine area clear_area(pos, marker_pos) elseif framenum == 12 then strut_line_x(pos.x, pos.y, pos.z, marker_pos.x) elseif framenum == 11 then strut_line_x(pos.x, marker_pos.y, pos.z, marker_pos.x) elseif framenum == 10 then strut_line_x(pos.x, pos.y, marker_pos.z, marker_pos.x) elseif framenum == 9 then strut_line_x(pos.x, marker_pos.y, marker_pos.z, marker_pos.x) elseif framenum == 8 then strut_line_z(pos.x, pos.y, pos.z, marker_pos.z) elseif framenum == 7 then strut_line_z(marker_pos.x, pos.y, pos.z, marker_pos.z) elseif framenum == 6 then strut_line_z(pos.x, marker_pos.y, pos.z, marker_pos.z) elseif framenum == 5 then strut_line_z(marker_pos.x, marker_pos.y, pos.z, marker_pos.z) elseif framenum == 4 then strut_line_y(marker_pos.x, pos.y, marker_pos.z, marker_pos.y) elseif framenum == 3 then strut_line_y(pos.x, pos.y, marker_pos.z, marker_pos.y) elseif framenum == 2 then strut_line_y(marker_pos.x, pos.y, pos.z, marker_pos.y) elseif framenum == 1 then strut_line_y(pos.x, pos.y, pos.z, marker_pos.y) elseif framenum == 0 then --shrink the operational area here to a 2d space with one piece of border taken away to drill there posx, pos2x = order(pos.x, marker_pos.x) posy, pos2y = order(pos.y, marker_pos.y) posz, pos2z = order(pos.z, marker_pos.z) posx = posx +1 pos2x = pos2x -1 posy = posy + 1 pos2y = pos2y -1 meta:set_string("dig_area_start", { x= posx, y= posy, z= posz}) meta:set_string("dig_area_end", { x= pos2x, y= pos2y, z= posz}) -- can use this last z as counter, or ignore it end minetest.debug(framenum) end meta:set_int("current_frame", framenum -1) minetest.get_node_timer(pos):start(1.0) end minetest.register_node( NAME .. ":quarry_marker", { descritption = "quarry marker", tiles = { "marker.png" }, groups = { oddly_breakable_by_hand = 1 }, after_place_node = marker_construct, }) minetest.register_node( NAME .. ":static_strut", { description = "supporting strut", drawtype = "nodebox", paramtype = "light", connects_to = { NAME .. ":static_strut", NAME .. ":quarry_marker", NAME .. ":lv_quarry" }, tiles = { "strut.png" }, node_box = { type = "connected", fixed = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2}, connect_top = {-0.2, 0.2, -0.2, 0.2, 0.5, 0.2}, connect_bottom = {-0.2, -0.5, -0.2, 0.2, -0.2, 0.2}, connect_back = {-0.2, -0.2, 0.2, 0.2, 0.2, 0.5}, connect_right = {0.2, -0.2, -0.2, 0.5, 0.2, 0.2}, connect_front = {-0.2, -0.2, -0.5, 0.2, 0.2, -0.2}, connect_left = {-0.5, -0.2, -0.2, -0.2, 0.2, 0.2}, }, groups = { oddly_breakable_by_hand = 1 } }) minetest.register_node( NAME .. ":lv_quarry", { description = "Electric Quarry", tiles = { "quarry.png", "quarry.png", "quarry.png", "quarry.png", "backplate.png", "quarry_frontplate.png" }, paramtype2 = "facedir", groups = { sparktech_techy = 1, sparktech_struty = 1, sparktech_energy_type = 4, sparktech_net_trigger = 1, sparktech_energy_max = 3000, spark_energy_timer = 2 }, on_timer = timer_trigger, after_place_node = on_construct, --on_destruct = function(pos, player) player:get_meta():set_string(NAME .. ":quarry_pos" , "") end, allow_metadata_inventory_put = function() return false end, allow_metadata_inventory_take = function(_, _, _, stack) return stack:get_count() end })