mirror of
https://github.com/minetest-mods/technic.git
synced 2025-02-23 07:10:19 +01:00
quarry rewrite/optimization
This commit is contained in:
parent
6c02359187
commit
7c8d6fbdaf
@ -1,103 +1,78 @@
|
|||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
local tube_entry = "^pipeworks_tube_connection_metallic.png"
|
local quarry_dig_above_nodes = tonumber(minetest.settings:get("technic.quarry.dig_above_nodes") or "3")
|
||||||
local cable_entry = "^technic_cable_connection_overlay.png"
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
recipe = {
|
|
||||||
{"technic:carbon_plate", "pipeworks:filter", "technic:composite_plate"},
|
|
||||||
{"basic_materials:motor", "technic:machine_casing", "technic:diamond_drill_head"},
|
|
||||||
{"technic:carbon_steel_block", "technic:hv_cable", "technic:carbon_steel_block"}},
|
|
||||||
output = "technic:quarry",
|
|
||||||
})
|
|
||||||
|
|
||||||
local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes
|
|
||||||
local quarry_max_depth = tonumber(minetest.settings:get("technic.quarry.maxdepth") or "100")
|
local quarry_max_depth = tonumber(minetest.settings:get("technic.quarry.maxdepth") or "100")
|
||||||
|
local quarry_time_limit = tonumber(minetest.settings:get("technic.quarry.time_limit") or "1000")
|
||||||
|
|
||||||
local quarry_demand = 10000
|
local quarry_demand = 10000
|
||||||
local quarry_eject_dir = vector.new(0, 1, 0)
|
local quarry_eject_dir = vector.new(0, 1, 0)
|
||||||
|
|
||||||
|
|
||||||
-- per player quota
|
|
||||||
local quota_map = {}
|
|
||||||
|
|
||||||
local enable_quota = minetest.settings:get_bool("technic.quarry.quota.enable", false)
|
|
||||||
|
|
||||||
-- quota reset timer
|
|
||||||
if enable_quota then
|
|
||||||
local timer = 0
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
timer = timer + dtime
|
|
||||||
if timer < 1 then return end
|
|
||||||
timer=0
|
|
||||||
|
|
||||||
-- reset quota map
|
|
||||||
quota_map = {}
|
|
||||||
|
|
||||||
-- this many blocks per second
|
|
||||||
local init_quota = tonumber(minetest.settings:get("technic.quarry.quota.limit") or "10")
|
|
||||||
|
|
||||||
local players = minetest.get_connected_players()
|
|
||||||
for i, player in pairs(players) do
|
|
||||||
local name = player:get_player_name()
|
|
||||||
quota_map[name] = init_quota
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local cache_timer = 0
|
|
||||||
local can_dig_cache = {} -- hash -> bool
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
cache_timer = cache_timer + dtime
|
|
||||||
if cache_timer < 30 then return end
|
|
||||||
cache_timer=0
|
|
||||||
|
|
||||||
-- clear cache
|
|
||||||
can_dig_cache = {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
local function set_quarry_formspec(meta)
|
|
||||||
local radius = meta:get_int("size")
|
|
||||||
local formspec = "size[6,4.3]"..
|
|
||||||
"list[context;cache;0,1;4,3;]"..
|
|
||||||
"item_image[4.8,0;1,1;technic:quarry]"..
|
|
||||||
"label[0,0.2;"..S("%s Quarry"):format("HV").."]"..
|
|
||||||
"field[4.3,3.5;2,1;size;"..S("Radius:")..";"..radius.."]"
|
|
||||||
if meta:get_int("enabled") == 0 then
|
|
||||||
formspec = formspec.."button[4,1;2,1;enable;"..S("Disabled").."]"
|
|
||||||
else
|
|
||||||
formspec = formspec.."button[4,1;2,1;disable;"..S("Enabled").."]"
|
|
||||||
end
|
|
||||||
local diameter = radius*2 + 1
|
|
||||||
local nd = meta:get_int("dug")
|
|
||||||
local rel_y = quarry_dig_above_nodes - math.floor(nd / (diameter*diameter))
|
|
||||||
formspec = formspec.."label[0,4;"..minetest.formspec_escape(
|
|
||||||
nd == 0 and S("Digging not started") or
|
|
||||||
(rel_y < -quarry_max_depth and S("Digging finished") or
|
|
||||||
(meta:get_int("purge_on") == 1 and S("Purging cache") or
|
|
||||||
S("Digging %d m "..(rel_y > 0 and "above" or "below").." machine")
|
|
||||||
:format(math.abs(rel_y))))
|
|
||||||
).."]"
|
|
||||||
formspec = formspec.."button[4,2;2,1;restart;"..S("Restart").."]"
|
|
||||||
meta:set_string("formspec", formspec)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_quarry_demand(meta)
|
|
||||||
local radius = meta:get_int("size")
|
|
||||||
local diameter = radius*2 + 1
|
|
||||||
local machine_name = S("%s Quarry"):format("HV")
|
local machine_name = S("%s Quarry"):format("HV")
|
||||||
if meta:get_int("enabled") == 0 or meta:get_int("purge_on") == 1 then
|
local quarry_formspec =
|
||||||
meta:set_string("infotext", S(meta:get_int("purge_on") == 1 and "%s purging cache" or "%s Disabled"):format(machine_name))
|
"size[8,9]"..
|
||||||
|
"item_image[7,0;1,1;technic:quarry]"..
|
||||||
|
"list[context;cache;1,1;4,3;]"..
|
||||||
|
"listring[context;cache]"..
|
||||||
|
"list[current_player;main;0,5;8,4;]"..
|
||||||
|
"listring[current_player;main]"..
|
||||||
|
"label[0,0;"..machine_name.."]"..
|
||||||
|
"button[5,1.9;2,1;restart;"..S("Restart").."]"
|
||||||
|
|
||||||
|
-- hard-coded spiral dig pattern for up to 17x17 dig area
|
||||||
|
local quarry_dig_pattern = {
|
||||||
|
0,1,2,2,3,3,0,0,0,1,1,1,2,2,2,2,3,3,3,3,0,0,0,0,0,1,1,1,1,1,2,2,
|
||||||
|
2,2,2,2,3,3,3,3,3,3,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,
|
||||||
|
3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,
|
||||||
|
2,2,2,2,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,
|
||||||
|
1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,
|
||||||
|
2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
|
||||||
|
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
}
|
||||||
|
|
||||||
|
local function reset_quarry(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local node = technic.get_or_load_node(pos) or minetest.get_node(pos)
|
||||||
|
meta:set_int("quarry_dir", node.param2)
|
||||||
|
meta:set_string("quarry_pos", minetest.pos_to_string(pos))
|
||||||
|
meta:set_string("dig_pos", "")
|
||||||
|
meta:set_int("dig_level", pos.y + quarry_dig_above_nodes)
|
||||||
|
local radius = meta:get_int("size")
|
||||||
|
local diameter = (radius*2)+1
|
||||||
|
meta:set_int("dig_steps", diameter*diameter)
|
||||||
|
meta:set_int("dig_index", 0)
|
||||||
|
meta:set_int("purge_on", 1)
|
||||||
|
meta:set_int("finished", 0)
|
||||||
|
meta:set_int("dug", 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function set_quarry_status(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local formspec = quarry_formspec.."field[5.3,3.4;2,1;size;"..S("Radius:")..";"..meta:get_int("size").."]"
|
||||||
|
local status = S("Digging not started")
|
||||||
|
if meta:get_int("enabled") == 1 then
|
||||||
|
formspec = formspec.."button[5,0.9;2,1;disable;"..S("Enabled").."]"
|
||||||
|
if meta:get_int("purge_on") == 1 then
|
||||||
|
status = S("Purging cache")
|
||||||
|
meta:set_string("infotext", S("%s purging cache"):format(machine_name))
|
||||||
meta:set_int("HV_EU_demand", 0)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
elseif meta:get_int("dug") == diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) then
|
elseif meta:get_int("finished") == 1 then
|
||||||
|
status = S("Digging finished")
|
||||||
meta:set_string("infotext", S("%s Finished"):format(machine_name))
|
meta:set_string("infotext", S("%s Finished"):format(machine_name))
|
||||||
meta:set_int("HV_EU_demand", 0)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
else
|
else
|
||||||
|
local rel_y = meta:get_int("dig_level") - pos.y
|
||||||
|
status = S("Digging %d m "..(rel_y > 0 and "above" or "below").." machine"):format(math.abs(rel_y))
|
||||||
meta:set_string("infotext", S(meta:get_int("HV_EU_input") >= quarry_demand and "%s Active" or "%s Unpowered"):format(machine_name))
|
meta:set_string("infotext", S(meta:get_int("HV_EU_input") >= quarry_demand and "%s Active" or "%s Unpowered"):format(machine_name))
|
||||||
meta:set_int("HV_EU_demand", quarry_demand)
|
meta:set_int("HV_EU_demand", quarry_demand)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
formspec = formspec.."button[5,0.9;2,1;enable;"..S("Disabled").."]"
|
||||||
|
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
||||||
|
meta:set_int("HV_EU_demand", 0)
|
||||||
|
end
|
||||||
|
meta:set_string("formspec", formspec.."label[0,4.1;"..minetest.formspec_escape(status).."]")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function quarry_receive_fields(pos, formname, fields, sender)
|
local function quarry_receive_fields(pos, formname, fields, sender)
|
||||||
@ -110,19 +85,15 @@ local function quarry_receive_fields(pos, formname, fields, sender)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if fields.size and string.find(fields.size, "^[0-9]+$") then
|
if fields.size and string.find(fields.size, "^[0-9]+$") then
|
||||||
local size = tonumber(fields.size)
|
local size = tonumber(fields.size)
|
||||||
if size >= 2 and size <= 8 and size ~= meta:get_int("size") then
|
if size >= 1 and size <= 8 and size ~= meta:get_int("size") then
|
||||||
meta:set_int("size", size)
|
meta:set_int("size", size)
|
||||||
meta:set_int("dug", 0)
|
reset_quarry(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if fields.enable then meta:set_int("enabled", 1) end
|
if fields.enable then meta:set_int("enabled", 1) end
|
||||||
if fields.disable then meta:set_int("enabled", 0) end
|
if fields.disable then meta:set_int("enabled", 0) end
|
||||||
if fields.restart then
|
if fields.restart then reset_quarry(pos) end
|
||||||
meta:set_int("dug", 0)
|
set_quarry_status(pos)
|
||||||
meta:set_int("purge_on", 1)
|
|
||||||
end
|
|
||||||
set_quarry_formspec(meta)
|
|
||||||
set_quarry_demand(meta)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function quarry_handle_purge(pos)
|
local function quarry_handle_purge(pos)
|
||||||
@ -130,6 +101,7 @@ local function quarry_handle_purge(pos)
|
|||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local cache = inv:get_list("cache")
|
local cache = inv:get_list("cache")
|
||||||
if not cache then
|
if not cache then
|
||||||
|
inv:set_size("cache", 12)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local i = 0
|
local i = 0
|
||||||
@ -150,120 +122,82 @@ local function quarry_handle_purge(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function quarry_run(pos, node)
|
local function can_dig_node(pos, node, digger)
|
||||||
|
if node.name == "air" or node.name == "vacuum:vacuum" then
|
||||||
local meta = minetest.get_meta(pos)
|
return false
|
||||||
local owner = meta:get_string("owner")
|
end
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
local inv = meta:get_inventory()
|
if not def or not def.diggable then
|
||||||
-- initialize cache for the case we load an older world
|
return false
|
||||||
inv:set_size("cache", 12)
|
end
|
||||||
-- toss a coin whether we do an automatic purge. Chance 1:200
|
if def.can_dig and not def.can_dig(pos, digger) then
|
||||||
local purge_rand = math.random()
|
return false
|
||||||
if purge_rand <= 0.005 then
|
end
|
||||||
meta:set_int("purge_on", 1)
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local digging_allowed = true
|
local function find_ground(quarry_pos, quarry_dir, meta)
|
||||||
local quota = quota_map[owner]
|
local dir = minetest.facedir_to_dir(quarry_dir % 4)
|
||||||
|
|
||||||
if enable_quota then
|
|
||||||
digging_allowed = quota and quota > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
if digging_allowed and meta:get_int("enabled") and meta:get_int("HV_EU_input") >= quarry_demand and meta:get_int("purge_on") == 0 then
|
|
||||||
|
|
||||||
-- decrement quota
|
|
||||||
if enable_quota then
|
|
||||||
quota = quota - 1
|
|
||||||
quota_map[owner] = quota
|
|
||||||
end
|
|
||||||
|
|
||||||
local pdir = minetest.facedir_to_dir(node.param2)
|
|
||||||
if pdir.y ~= 0 then
|
|
||||||
-- faces up or down, not valid, otherwise depth-check would run endless and hang up the server
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local qdir = pdir.x == 1 and vector.new(0,0,-1) or
|
|
||||||
(pdir.z == -1 and vector.new(-1,0,0) or
|
|
||||||
(pdir.x == -1 and vector.new(0,0,1) or
|
|
||||||
vector.new(1,0,0)))
|
|
||||||
local radius = meta:get_int("size")
|
local radius = meta:get_int("size")
|
||||||
local diameter = radius*2 + 1
|
local dig_level = meta:get_int("dig_level")
|
||||||
local startpos = vector.add(vector.add(vector.add(pos,
|
local middle_pos = vector.add(quarry_pos, vector.multiply(dir, radius + 1))
|
||||||
vector.new(0, quarry_dig_above_nodes, 0)),
|
local pos1 = vector.new(middle_pos.x - radius, dig_level, middle_pos.z - radius)
|
||||||
pdir),
|
local pos2 = vector.new(middle_pos.x + radius, dig_level, middle_pos.z + radius)
|
||||||
vector.multiply(qdir, -radius))
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"air", "vacuum:vacuum"})
|
||||||
|
if #nodes < meta:get_int("dig_steps") then
|
||||||
|
return vector.new(middle_pos.x, dig_level, middle_pos.z)
|
||||||
|
end
|
||||||
|
meta:set_int("dig_level", dig_level - 1)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_dig_pos(quarry_pos, quarry_dir, dig_pos, dig_index, dig_steps, meta)
|
||||||
|
if dig_index > 0 and dig_index < dig_steps then
|
||||||
|
local facedir = (quarry_dir + quarry_dig_pattern[dig_index]) % 4
|
||||||
|
dig_pos = vector.add(dig_pos, minetest.facedir_to_dir(facedir))
|
||||||
|
elseif dig_index >= dig_steps then
|
||||||
|
local dig_level = meta:get_int("dig_level")
|
||||||
|
if (quarry_pos.y - dig_level) >= quarry_max_depth then
|
||||||
|
return nil, dig_index
|
||||||
|
end
|
||||||
|
local dir = minetest.facedir_to_dir(quarry_dir % 4)
|
||||||
|
dig_pos = vector.add(quarry_pos, vector.multiply(dir, meta:get_int("size") + 1))
|
||||||
|
dig_pos.y = dig_level - 1
|
||||||
|
meta:set_int("dig_level", dig_pos.y)
|
||||||
|
dig_index = 0
|
||||||
|
end
|
||||||
|
dig_index = dig_index + 1
|
||||||
|
return dig_pos, dig_index
|
||||||
|
end
|
||||||
|
|
||||||
|
local function execute_dig(pos, node, meta)
|
||||||
|
local dig_pos = minetest.string_to_pos(meta:get_string("dig_pos"))
|
||||||
|
local quarry_dir = meta:get_int("quarry_dir")
|
||||||
|
if not dig_pos then
|
||||||
|
-- quarry has not hit ground yet
|
||||||
|
dig_pos = find_ground(pos, quarry_dir, meta)
|
||||||
|
else
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
local nd = meta:get_int("dug")
|
local digger = pipeworks.create_fake_player({name = owner})
|
||||||
|
local dig_steps = meta:get_int("dig_steps")
|
||||||
|
local dig_index = meta:get_int("dig_index")
|
||||||
local t0 = minetest.get_us_time()
|
local t0 = minetest.get_us_time()
|
||||||
|
-- search for something to dig
|
||||||
while nd < diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) do
|
while (minetest.get_us_time() - t0) < quarry_time_limit do
|
||||||
|
dig_pos, dig_index = get_dig_pos(pos, quarry_dir, dig_pos, dig_index, dig_steps, meta)
|
||||||
local us_used = minetest.get_us_time() - t0
|
if not dig_pos then
|
||||||
if us_used > 10000 then
|
-- finished digging
|
||||||
-- abort if this quarry takes too much time
|
meta:set_int("finished", 1)
|
||||||
|
meta:set_int("purge_on", 1)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
if not minetest.is_protected(dig_pos, owner) then
|
||||||
local ry = math.floor(nd / (diameter*diameter))
|
local dig_node = technic.get_or_load_node(dig_pos) or minetest.get_node(dig_pos)
|
||||||
local ndl = nd % (diameter*diameter)
|
if can_dig_node(dig_pos, dig_node, digger) then
|
||||||
if ry % 2 == 1 then
|
-- found something to dig, dig it and stop searching
|
||||||
ndl = diameter*diameter - 1 - ndl
|
minetest.remove_node(dig_pos)
|
||||||
end
|
local inv = meta:get_inventory()
|
||||||
local rq = math.floor(ndl / diameter)
|
local drops = minetest.get_node_drops(dig_node.name, "")
|
||||||
local rp = ndl % diameter
|
|
||||||
if rq % 2 == 1 then rp = diameter - 1 - rp end
|
|
||||||
local digpos = vector.add(vector.add(vector.add(startpos,
|
|
||||||
vector.new(0, -ry, 0)),
|
|
||||||
vector.multiply(pdir, rp)),
|
|
||||||
vector.multiply(qdir, rq))
|
|
||||||
local can_dig = true
|
|
||||||
|
|
||||||
local hash = minetest.hash_node_position(digpos)
|
|
||||||
if can_dig_cache[hash] == false then
|
|
||||||
can_dig = false
|
|
||||||
end
|
|
||||||
|
|
||||||
if can_dig and minetest.is_protected and minetest.is_protected(digpos, owner) then
|
|
||||||
can_dig = false
|
|
||||||
can_dig_cache[hash] = true
|
|
||||||
end
|
|
||||||
local dignode
|
|
||||||
if can_dig then
|
|
||||||
dignode = technic.get_or_load_node(digpos) or minetest.get_node(digpos)
|
|
||||||
local dignodedef = minetest.registered_nodes[dignode.name] or {diggable=false}
|
|
||||||
-- doors mod among other thing does NOT like a nil digger...
|
|
||||||
local fakedigger = pipeworks.create_fake_player({
|
|
||||||
name = owner
|
|
||||||
})
|
|
||||||
if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, fakedigger)) then
|
|
||||||
can_dig = false
|
|
||||||
can_dig_cache[hash] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
if can_dig then
|
|
||||||
-- test above blocks if diggable
|
|
||||||
for ay = startpos.y, digpos.y+1, -1 do
|
|
||||||
local checkpos = {x=digpos.x, y=ay, z=digpos.z}
|
|
||||||
local checknode = technic.get_or_load_node(checkpos) or minetest.get_node(checkpos)
|
|
||||||
if checknode.name ~= "air" and checknode.name ~= "vacuum:vacuum" then
|
|
||||||
can_dig = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
nd = nd + 1
|
|
||||||
if can_dig then
|
|
||||||
minetest.remove_node(digpos)
|
|
||||||
local drops = minetest.get_node_drops(dignode.name, "")
|
|
||||||
for _, dropped_item in ipairs(drops) do
|
for _, dropped_item in ipairs(drops) do
|
||||||
local left = inv:add_item("cache", dropped_item)
|
local left = inv:add_item("cache", dropped_item)
|
||||||
while not left:is_empty() do
|
while not left:is_empty() do
|
||||||
@ -272,42 +206,42 @@ local function quarry_run(pos, node)
|
|||||||
left = inv:add_item("cache", left)
|
left = inv:add_item("cache", left)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
meta:set_int("dug", meta:get_int("dug") + 1)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if nd == diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) then
|
|
||||||
-- if a quarry is finished, we enable purge mode
|
|
||||||
meta:set_int("purge_on", 1)
|
|
||||||
end
|
end
|
||||||
meta:set_int("dug", nd)
|
meta:set_int("dig_index", dig_index)
|
||||||
else
|
|
||||||
-- if a quarry is disabled or has no power, we enable purge mode
|
|
||||||
meta:set_int("purge_on", 1)
|
|
||||||
end
|
end
|
||||||
-- if something triggered a purge, we handle it
|
if dig_pos then
|
||||||
if meta:get_int("purge_on") == 1 then
|
meta:set_string("dig_pos", minetest.pos_to_string(dig_pos))
|
||||||
quarry_handle_purge(pos)
|
|
||||||
end
|
end
|
||||||
set_quarry_formspec(meta)
|
|
||||||
set_quarry_demand(meta)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function send_move_error(player)
|
local function quarry_run(pos, node)
|
||||||
minetest.chat_send_player(player:get_player_name(),
|
local meta = minetest.get_meta(pos)
|
||||||
S("Manually taking/removing from cache by hand is not possible. "..
|
if minetest.pos_to_string(pos) ~= meta:get_string("quarry_pos") then
|
||||||
"If you can't wait, restart or disable the quarry to start automatic purge."))
|
-- quarry has been moved since last dig
|
||||||
return 0
|
reset_quarry(pos)
|
||||||
|
elseif meta:get_int("purge_on") == 1 then
|
||||||
|
quarry_handle_purge(pos)
|
||||||
|
elseif meta:get_int("enabled") and meta:get_int("HV_EU_input") >= quarry_demand and meta:get_int("finished") == 0 then
|
||||||
|
execute_dig(pos, node, meta)
|
||||||
|
elseif not meta:get_inventory():is_empty("cache") then
|
||||||
|
meta:set_int("purge_on", 1)
|
||||||
|
end
|
||||||
|
set_quarry_status(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("technic:quarry", {
|
minetest.register_node("technic:quarry", {
|
||||||
description = S("%s Quarry"):format("HV"),
|
description = S("%s Quarry"):format("HV"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"technic_carbon_steel_block.png"..tube_entry,
|
"technic_carbon_steel_block.png^pipeworks_tube_connection_metallic.png",
|
||||||
"technic_carbon_steel_block.png"..cable_entry,
|
"technic_carbon_steel_block.png^technic_cable_connection_overlay.png",
|
||||||
"technic_carbon_steel_block.png"..cable_entry,
|
"technic_carbon_steel_block.png^technic_cable_connection_overlay.png",
|
||||||
"technic_carbon_steel_block.png"..cable_entry,
|
"technic_carbon_steel_block.png^technic_cable_connection_overlay.png",
|
||||||
"technic_carbon_steel_block.png^default_tool_mesepick.png",
|
"technic_carbon_steel_block.png^default_tool_mesepick.png",
|
||||||
"technic_carbon_steel_block.png"..cable_entry
|
"technic_carbon_steel_block.png^technic_cable_connection_overlay.png"
|
||||||
},
|
},
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, tubedevice=1, technic_machine=1, technic_hv=1},
|
groups = {cracky=2, tubedevice=1, technic_machine=1, technic_hv=1},
|
||||||
@ -327,33 +261,38 @@ minetest.register_node("technic:quarry", {
|
|||||||
},
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", S("%s Quarry"):format("HV"))
|
|
||||||
meta:set_int("size", 4)
|
meta:set_int("size", 4)
|
||||||
set_quarry_formspec(meta)
|
meta:get_inventory():set_size("cache", 12)
|
||||||
set_quarry_demand(meta)
|
reset_quarry(pos)
|
||||||
|
set_quarry_status(pos)
|
||||||
end,
|
end,
|
||||||
after_place_node = function(pos, placer, itemstack)
|
after_place_node = function(pos, placer, itemstack)
|
||||||
local meta = minetest.get_meta(pos)
|
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||||
meta:set_string("owner", placer:get_player_name())
|
|
||||||
pipeworks.scan_for_tube_objects(pos)
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
return minetest.get_meta(pos):get_inventory():is_empty("cache")
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("cache")
|
|
||||||
end,
|
end,
|
||||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||||
on_receive_fields = quarry_receive_fields,
|
on_receive_fields = quarry_receive_fields,
|
||||||
technic_run = quarry_run,
|
technic_run = quarry_run,
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
return send_move_error(player)
|
return minetest.is_protected(pos, player:get_player_name()) and 0 or count
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
return send_move_error(player)
|
return minetest.is_protected(pos, player:get_player_name()) and 0 or stack:get_count()
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
return send_move_error(player)
|
return minetest.is_protected(pos, player:get_player_name()) and 0 or stack:get_count()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
recipe = {
|
||||||
|
{"technic:carbon_plate", "pipeworks:filter", "technic:composite_plate"},
|
||||||
|
{"basic_materials:motor", "technic:machine_casing", "technic:diamond_drill_head"},
|
||||||
|
{"technic:carbon_steel_block", "technic:hv_cable", "technic:carbon_steel_block"}},
|
||||||
|
output = "technic:quarry"
|
||||||
|
})
|
||||||
|
|
||||||
technic.register_machine("HV", "technic:quarry", technic.receiver)
|
technic.register_machine("HV", "technic:quarry", technic.receiver)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user