Compare commits

...

3 Commits

Author SHA1 Message Date
Pascal Abresch 4026a0a12d simplified code 2019-10-02 04:07:03 +02:00
Pascal Abresch 175b5f4e46 added crafting recipes 2019-10-02 03:09:30 +02:00
Pascal Abresch 09fec87c5d quicker rebuild 2019-10-02 02:51:29 +02:00
1 changed files with 76 additions and 67 deletions

View File

@ -127,7 +127,27 @@ local function marker_construct(pos, player)
on_marker_placed(pos, quarry_pos, player)
end
local function clear_area(pos, pos2)
local function place_strut(position, quarrypos)
if minetest.get_node(position).name == "air" then
minetest.debug("PLACE")
local placed = false
if try_remove_item(quarrypos, "quarry", NAME .. ":static_strut") then
minetest.debug("ENERGY")
if try_drain_energy(quarrypos, ENERGYCOST.static_strut) then
minetest.debug("CONFIRM")
minetest.set_node(position, { name = NAME .. ":static_strut"})
placed = true
else
-- TODO Restore items
end
end
return true, placed
end
return false, false
end
local function prepare_area(pos, pos2)
local placement_done = true
local minx, maxx = order(pos.x, pos2.x)
local miny, maxy = order(pos.y, pos2.y)
local minz, maxz = order(pos.z, pos2.z)
@ -135,66 +155,42 @@ local function clear_area(pos, pos2)
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
if dig_node(Position(x, y, z), pos) then
return false
if not (x == pos.x and y == pos.y and z == pos.z) then
local count = 0
if x == pos.x then count = count +1 end
if x == pos2.x then count = count +1 end
if y == pos.y then count = count +1 end
if y == pos2.y then count = count +1 end
if z == pos.z then count = count +1 end
if z == pos2.z then count = count +1 end
if count >= 2 then
local node = minetest.get_node(Position(x, y, z))
if node.name ~= NAME .. ":static_strut" then
if node.name ~= "air" then
dig_node(Position(x, y, z), pos)
return false
end
local incomplete, placed = place_strut(Position(x, y, z), pos)
if placed then
return false
end
if incomplete then
placement_done = false
end
end
else
if dig_node(Position(x, y, z), pos) then
return false
end
end
end
end
end
end
return true
return placement_done --true: cleared
end
local function place_strut(position, quarrypos)
if minetest.get_node(position).name == "air" then
minetest.debug("PLACE")
if try_remove_item(quarrypos, "quarry", NAME .. ":static_strut") then
minetest.debug("ENERGY")
if try_drain_energy(quarrypos, ENERGYCOST.static_strut) then
minetest.debug("CONFIRM")
minetest.set_node(position, { name = NAME .. ":static_strut"})
else
-- Restore items
end
end
return true
end
return false
end
local function strut_line_x(x, y, z, x2, quarrypos)
local minx, maxx = order(x, x2)
for x3=minx, maxx do
if place_strut(Position(x3, y, z), quarrypos) then
return false
end
end
return true
end
local function strut_line_y(x, y, z, y2, quarrypos)
local miny, maxy = order(y, y2)
for y3=miny, maxy do
if place_strut(Position(x, y3, z), quarrypos) then
return false
end
end
return true
end
local function strut_line_z(x, y, z, z2, quarrypos)
local minz, maxz = order(z, z2)
for z3=minz, maxz do
if place_strut(Position(x, y, z3), quarrypos) then
return false
end
end
return true
end
local function timer_trigger(pos, elapsed)
local meta = minetest.get_meta(pos)
@ -229,23 +225,11 @@ local function timer_trigger(pos, elapsed)
elseif framenum == 1 then
minetest.debug("Clear area")
-- preparation phase
if clear_area(pos, marker_pos) then
if prepare_area(pos, marker_pos) then
framenum = 0
end
else
minetest.debug("Build strats")
if not strut_line_x(pos.x, pos.y, pos.z, marker_pos.x, pos) then break end
if not strut_line_x(pos.x, marker_pos.y, pos.z, marker_pos.x, pos) then break end
if not strut_line_x(pos.x, pos.y, marker_pos.z, marker_pos.x, pos) then break end
if not strut_line_x(pos.x, marker_pos.y, marker_pos.z, marker_pos.x, pos) then break end
if not strut_line_z(pos.x, pos.y, pos.z, marker_pos.z, pos) then break end
if not strut_line_z(marker_pos.x, pos.y, pos.z, marker_pos.z, pos) then break end
if not strut_line_z(pos.x, marker_pos.y, pos.z, marker_pos.z, pos) then break end
if not strut_line_z(marker_pos.x, marker_pos.y, pos.z, marker_pos.z, pos) then break end
if not strut_line_y(marker_pos.x, pos.y, marker_pos.z, marker_pos.y, pos) then break end
if not strut_line_y(pos.x, pos.y, marker_pos.z, marker_pos.y, pos) then break end
if not strut_line_y(marker_pos.x, pos.y, pos.z, marker_pos.y, pos) then break end
if not strut_line_y(pos.x, pos.y, pos.z, marker_pos.y, pos) then break end
--shrink the operational area here to a 2d space with one piece of border taken away to drill there
--
local posx, pos2x = order(pos.x, marker_pos.x)
@ -337,3 +321,28 @@ minetest.register_node( NAME .. ":lv_quarry", {
allow_metadata_inventory_put = function(_,_,_, stack) return stack:get_count() end,
allow_metadata_inventory_take = function(_, _, _, stack) return stack:get_count() end
})
minetest.register_craft({
output = NAME .. ":lv_quarry",
recipe = {
{ NAME .. ":static_strut", "sparktool:handdrill", NAME .. ":static_strut" },
{ NAME .. ":static_strut", "group:steel_chasis", NAME .. ":static_strut" },
{ NAME .. ":static_strut", "sparkcore:cable", NAME .. ":static_strut" }
}
})
minetest.register_craft({
output = NAME .. ":quarry_marker",
recipe = {
{ NAME .. ":static_strut", NAME .. ":static_strut" },
{ "default:steel_ingot", "default:copper_ingot" }
}
})
minetest.register_craft({
output = NAME .. ":static_strut 16",
recipe = {
{ "group:steel_plate", "group:steel_plate", "group:steel_plate" },
{ "", "", "" },
{ "group:steel_plate", "group:steel_plate", "group:steel_plate" }
}
})