From f9b0906a82382af30475dc3cb040c4686d54bcf8 Mon Sep 17 00:00:00 2001 From: SmallJoker <mk939@ymail.com> Date: Wed, 08 Jun 2022 21:57:46 +0200 Subject: [PATCH] Switching station: Begin optimizations --- technic/machines/HV/quarry.lua | 41 ++++++++++++++++++++++++++--------------- 1 files changed, 26 insertions(+), 15 deletions(-) diff --git a/technic/machines/HV/quarry.lua b/technic/machines/HV/quarry.lua index c1ee1bb..1bf1ad6 100644 --- a/technic/machines/HV/quarry.lua +++ b/technic/machines/HV/quarry.lua @@ -7,7 +7,7 @@ minetest.register_craft({ recipe = { {"technic:carbon_plate", "pipeworks:filter", "technic:composite_plate"}, - {"technic:motor", "technic:machine_casing", "technic:diamond_drill_head"}, + {"basic_materials:motor", "technic:machine_casing", "technic:diamond_drill_head"}, {"technic:carbon_steel_block", "technic:hv_cable", "technic:carbon_steel_block"}}, output = "technic:quarry", }) @@ -47,19 +47,30 @@ local radius = meta:get_int("size") local diameter = radius*2 + 1 local machine_name = S("%s Quarry"):format("HV") - if meta:get_int("enabled") == 0 or meta:get_int("purge_on") == 1 then - meta:set_string("infotext", S(meta:get_int("purge_on") == 1 and "%s purging cache" or "%s Disabled"):format(machine_name)) + local do_purge = meta:get_int("purge_on") == 1 + if meta:get_int("enabled") == 0 or do_purge then + local infotext = do_purge and + S("%s purging cache") or S("%s Disabled") + meta:set_string("infotext", infotext:format(machine_name)) meta:set_int("HV_EU_demand", 0) elseif meta:get_int("dug") == diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) then meta:set_string("infotext", S("%s Finished"):format(machine_name)) meta:set_int("HV_EU_demand", 0) else - meta:set_string("infotext", S(meta:get_int("HV_EU_input") >= quarry_demand and "%s Active" or "%s Unpowered"):format(machine_name)) + local infotext = meta:get_int("HV_EU_input") >= quarry_demand + and S("%s Active") or S("%s Unpowered") + meta:set_string("infotext", infotext:format(machine_name)) meta:set_int("HV_EU_demand", quarry_demand) end end local function quarry_receive_fields(pos, formname, fields, sender) + local player_name = sender:get_player_name() + if minetest.is_protected(pos, player_name) then + minetest.chat_send_player(player_name, "You are not allowed to edit this!") + minetest.record_protection_violation(pos, player_name) + return + end local meta = minetest.get_meta(pos) if fields.size and string.find(fields.size, "^[0-9]+$") then local size = tonumber(fields.size) @@ -112,6 +123,11 @@ if meta:get_int("enabled") and meta:get_int("HV_EU_input") >= quarry_demand and meta:get_int("purge_on") == 0 then 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 @@ -122,18 +138,9 @@ vector.new(0, quarry_dig_above_nodes, 0)), pdir), vector.multiply(qdir, -radius)) - local endpos = vector.add(vector.add(vector.add(startpos, - vector.new(0, -quarry_dig_above_nodes-quarry_max_depth, 0)), - vector.multiply(pdir, diameter-1)), - vector.multiply(qdir, diameter-1)) - local vm = VoxelManip() - local minpos, maxpos = vm:read_from_map(startpos, endpos) - local area = VoxelArea:new({MinEdge=minpos, MaxEdge=maxpos}) - local data = vm:get_data() - local c_air = minetest.get_content_id("air") local owner = meta:get_string("owner") local nd = meta:get_int("dug") - while nd ~= diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) do + while nd < diameter*diameter * (quarry_dig_above_nodes+1+quarry_max_depth) do local ry = math.floor(nd / (diameter*diameter)) local ndl = nd % (diameter*diameter) if ry % 2 == 1 then @@ -154,7 +161,11 @@ 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} - if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, nil)) then + -- 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 end end -- Gitblit v1.8.0