203 lines
5.6 KiB
Lua
203 lines
5.6 KiB
Lua
local MOD_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(MOD_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(MOD_NAME .. ":quarry_pos"))
|
|
local quarry = minetest.get_node(quarry_pos)
|
|
on_marker_placed(pos, quarry_pos, player)
|
|
end
|
|
|
|
local function clear_area(pos, pos2)
|
|
local minx = pos.x
|
|
local maxx = pos2.x
|
|
if pos2.x < pos.x then
|
|
minx = pos2.x
|
|
maxx = pos.x
|
|
end
|
|
local miny = pos.y
|
|
local maxy = pos2.y
|
|
if pos2.y < pos.y then
|
|
miny = pos2.y
|
|
maxy = pos.y
|
|
end
|
|
local minz = pos.z
|
|
local maxz = pos2.z
|
|
if pos2.z < pos.z then
|
|
minz = pos2.z
|
|
maxz = pos.z
|
|
end
|
|
for x=minx , maxx do
|
|
for y=miny, maxy do
|
|
for z=minz, maxz do
|
|
-- dont remove quarry or marker
|
|
if x == pos.x and y == pos.y and z == pos.z then
|
|
|
|
elseif x == pos2.x and y == pos2.y and z == pos2.z then
|
|
|
|
else
|
|
minetest.dig_node({ x=x, y=y, z=z })
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function struct_line(pos, pos2)
|
|
local minx = pos.x
|
|
local maxx = pos2.x
|
|
if pos2.x < pos.x then
|
|
minx = pos2.x
|
|
maxx = pos.x
|
|
end
|
|
local miny = pos.y
|
|
local maxy = pos2.y
|
|
if pos2.y < pos.y then
|
|
miny = pos2.y
|
|
maxy = pos.y
|
|
end
|
|
local minz = pos.z
|
|
local maxz = pos2.z
|
|
if pos2.z < pos.z then
|
|
minz = pos2.z
|
|
maxz = pos.z
|
|
end
|
|
for x=minx , maxx do
|
|
for y=miny, maxy do
|
|
for z=minz, maxz do
|
|
if x == pos.x and y == pos.y and z == pos.z then
|
|
|
|
elseif x == pos2.x and y == pos2.y and z == pos2.z then
|
|
|
|
else
|
|
-- dont remove quarry or marker
|
|
minetest.debug(x .. ": " .. y .. ": " .. z .. ": " .. MOD_NAME)
|
|
minetest.place_node({x=x, y=y, z=z}, MOD_NAME .. ":static_strut")
|
|
-- WHY THE FLYING FUCK DOES THIS TRIGGER "not a string" bullshit
|
|
end
|
|
end
|
|
end
|
|
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
|
|
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 framenum == 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 })
|
|
elseif framenum == 0 then
|
|
--shrink the operational area here to a 2d space with one piece of border taken away to drill there
|
|
end
|
|
end
|
|
meta:set_int("current_frame", framenum -1)
|
|
|
|
minetest.get_node_timer(pos):start(1.0)
|
|
end
|
|
|
|
minetest.register_node( MOD_NAME .. ":quarry_marker", {
|
|
descritption = "quarry marker",
|
|
tiles = {
|
|
"marker.png"
|
|
},
|
|
after_place_node = marker_construct,
|
|
})
|
|
|
|
minetest.register_node( MOD_NAME .. ":static_strut", {
|
|
desctiption = "supporting strut",
|
|
tiles = {
|
|
"strut.png"
|
|
}
|
|
})
|
|
|
|
minetest.register_node( MOD_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(MOD_NAME .. ":quarry_pos" , "") end,
|
|
allow_metadata_inventory_put = function() return false end,
|
|
allow_metadata_inventory_take = function(_, _, _, stack) return stack:get_count() end
|
|
})
|