diff --git a/sparkmachine/lua/quarry.lua b/sparkmachine/lua/quarry.lua index ca03ccf..007611c 100644 --- a/sparkmachine/lua/quarry.lua +++ b/sparkmachine/lua/quarry.lua @@ -11,17 +11,101 @@ local function on_construct(pos, player) end local function marker_construct(pos, player) - local quarry_pos = player:get_meta():get_string(MOD_NAME .. ":quarry_pos", pos) + local quarry_pos = player:get_meta():get_string(MOD_NAME .. ":quarry_pos") local quarry = minetest.get_node_at(quarry_pos) quarry:get_definition()._sparktech_lamp_construct(pos, quarry_pos, player) 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) + local metatable = meta:to_table() + metatable.marker = pos + metatable.current_frame = 1 -- Preparation phase, 0 means completed + + meta:from_table(metatable) + + + timer = minetest.get_node_timer(quarry_pos).start(1.0) end -minetest.register_node( MOD_NAME .. "lq_quarry_marker", { +local function clear_area(pos, pos2) + for x=pos.x , pos2.x do + for y=pos.y, pos2.y do + for z=pos.z, pos2.z do + minetest.dig_node({ x=x, y=y, z=z }) + end + end + end +end + +local function struct_line(pos, pos2) + for x=pos.x , pos2.x do + for y=pos.y, pos2.y do + for z=pos.z, pos2.z do + minetest.dig_node({ x=x, y=y, z=z }) + minetest.place_node({x=x, y=y, z=z}, MOD_NAME .. ":static_strut") + end + end + end +end + +local function timer_trigger(pos, elapsed) + local meta = minetest.get_meta(pos) + local metatable = meta:to_table() + local framenum = metatable.current_frame + local marker_pos = metatable.marker + + if framenum == 0 then + -- Operation Phase + -- + else + -- preparation phase + if framenum == 13 then -- stripmine area + clear_area(pos, marker_pos) + elseif framenum == 12 then + struct_line(pos, { x = marker_pos.x, y = pos.y, z = pos.z }) + elseif framenum == 11 then + struct_line(pos, { x = pos.x, y = marker_pos.y, z = pos.z }) + elseif framenum == 10 then + struct_line( { x = pos.x, y = marker_pos.y, z = pos.z }, { x = pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif framenum == 9 then + struct_line( { x = marker_pos.x, y = pos.y, z = pos.z }, { x = pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif framenum == 8 then + struct_line( { x = pos.x, y = pos.y, z = pos.z }, { x = pos.x, y = pos.y, z = marker_pos.z }) + elseif framenum == 7 then + struct_line( { x = marker_pos.x, y = pos.y, z = pos.z }, { x = marker_pos.x, y = pos.y, z = marker_pos.z }) + elseif framenum == 6 then + struct_line( { x = pos.x, y = marker_pos.y, z = pos.z }, { x = pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif frmaenum == 5 then + struct_line( { x = marker_pos.x, y = marker_pos.y, z = pos.z }, { x = marker_pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif framenum == 4 then + struct_line( { x = pos.x, y = pos.y, z = marker_pos.z }, { x = marker_pos.x, y = pos.y, z = marker_pos.z }) + elseif framenum == 3 then + struct_line( { x = pos.x, y = pos.y, z = marker_pos.z }, { x = pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif framenum == 2 then + struct_line( { x = marker_pos.x, y = pos.y, z = marker_pos.z }, { x = marker_pos.x, y = marker_pos.y, z = marker_pos.z }) + elseif framenum == 1 then + struct_line( { x = pos.x, y = marker_pos.y, z = marker_pos.z }, { x = marker_pos.x, y = marker_pos.y, z = marker_pos.z }) + end + end + + meta:from_table(metatable) + minetest.get_node_timer(pos).start(1.0) +end + +minetest.register_node( MOD_NAME .. "lv_quarry_marker", { descritption = "quarry marker", on_construct = marker_construct, @@ -53,11 +137,12 @@ minetest.register_node( NAME .. ":lv_quarry", { spark_energy_timer = 2 }, - on_timer = mytime, -- add a mytimer function + on_timer = timer_trigger, on_construct = on_construct, _sparktech_lamp_construct = on_marker_placed, + on_destruct = function(pos, player) player:get_meta():set_string(MOD_NAME .. ":quarry_pos" , "") end allow_metadata_inventory_put = function() return false end, allow_metadata_inventory_take = function(_, _, _, stack) return stack:get_count() end, -- Might want to improve this })