summaryrefslogtreecommitdiff
path: root/util_execute_cycle.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util_execute_cycle.lua')
-rw-r--r--util_execute_cycle.lua31
1 files changed, 24 insertions, 7 deletions
diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua
index 29edcdb..d5f23f0 100644
--- a/util_execute_cycle.lua
+++ b/util_execute_cycle.lua
@@ -207,10 +207,25 @@ digtron.execute_dig_cycle = function(pos, clicker)
local test_fuel_needed = test_build_fuel_cost + digging_fuel_cost - fuel_burning
local test_fuel_burned = 0
-
- if test_fuel_needed > 0 then
- -- check for the available electrical power
- test_fuel_burned = digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true)
+
+ local power_from_cables = 0
+ if minetest.get_modpath("technic") then
+ local power_inputs = {}
+ for _, power_connector in pairs(layout.power_connectors) do
+ if power_connector.meta.fields.HV_network and power_connector.meta.fields.HV_EU_input then
+ power_inputs[power_connector.meta.fields.HV_network] = tonumber(power_connector.meta.fields.HV_EU_input)
+ end
+ end
+ for _, power in pairs(power_inputs) do
+ power_from_cables = power_from_cables + power
+ end
+ power_from_cables = power_from_cables / digtron.config.power_ratio
+ test_fuel_burned = power_from_cables
+
+ if test_fuel_needed - test_fuel_burned > 0 then
+ -- check for the available electrical power
+ test_fuel_burned = test_fuel_burned + digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true)
+ end
end
if (test_fuel_needed < test_fuel_burned) then
exhaust = 0 -- all power needs met by electricity, don't blow smoke
@@ -312,11 +327,13 @@ digtron.execute_dig_cycle = function(pos, clicker)
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
status_text = S("Digtron unexpectedly failed to execute one or more build operations, likely due to an inventory error.") .. "\n"
end
-
+
+ local total_fuel_cost = math.max(digging_fuel_cost + building_fuel_cost - power_from_cables, 0)
+
-- actually burn the fuel needed
- fuel_burning = fuel_burning - digging_fuel_cost
+ fuel_burning = fuel_burning - total_fuel_cost
if digtron.config.particle_effects and exhaust == 1 then
- table.insert(particle_systems, burn_smoke(pos, digging_fuel_cost))
+ table.insert(particle_systems, burn_smoke(pos, total_fuel_cost))
end
if fuel_burning < 0 then
-- we tap into the batteries either way