diff --git a/src/README b/src/README
index 776cebc..3c90c94 100644
--- a/src/README
+++ b/src/README
@@ -18,3 +18,4 @@ Deviations from BurnerLeech
- If the "cheat" is enabled (the default), Burner inserters wich ran out of fuel get a minuscule amount of energy out of thin air once in a while to allow them to slowly grab themselves some fuel.
- Inserters honor filters (you can limit the types of fuel that may be leeched by using an inserter, that supports
filters - even a modded burner-tech one).
+- Option to allow inserters to leech from their drop target in addition to their pickup target
diff --git a/src/changelog.txt b/src/changelog.txt
index 3efecab..d19dce3 100644
--- a/src/changelog.txt
+++ b/src/changelog.txt
@@ -36,3 +36,8 @@ Date: 2020-05-03
- Fixed fuel cheat trying to feed inserters items in their fuel category wich have a fuel value of 0. If you defined such an item, please fix your mod too. Items having a fuel category should also have a positive fuel value.
Info:
- Synced README with mod portal.
+---------------------------------------------------------------------------------------------------
+Version: 0.2.6
+Date: ????
+ Features:
+ - Optional leech from inserter drop target
diff --git a/src/control.lua b/src/control.lua
index 840a519..1ab309b 100644
--- a/src/control.lua
+++ b/src/control.lua
@@ -82,17 +82,33 @@ function process_inserter(inserter)
return
end
- -- Grab fuel for target:
- if not inserter.held_stack.valid_for_read
- and inserter.drop_target and inserter.drop_target.burner
- and inserter_is_at_pickup_pos(inserter) then
- local source = pickup_target_of_inserter(inserter)
- if source and source.burner then
- local src_fuel = source.burner.inventory
- local dest_fuel = inserter.drop_target.burner.inventory
- if src_fuel and not src_fuel.is_empty()
- and dest_fuel and needs_refuelling(dest_fuel) then
- inserter_leech_fuel(src_fuel, inserter, dest_fuel)
+ if not inserter.held_stack.valid_for_read then
+ -- Grab fuel for target:
+ if inserter.drop_target and inserter.drop_target.burner
+ and inserter_is_at_pickup_pos(inserter) then
+ local source = pickup_target_of_inserter(inserter)
+ if source and source.burner then
+ local src_fuel = source.burner.inventory
+ local dest_fuel = inserter.drop_target.burner.inventory
+ if src_fuel and not src_fuel.is_empty()
+ and dest_fuel and needs_refuelling(dest_fuel) then
+ return inserter_leech_fuel(src_fuel, inserter, dest_fuel)
+ end
+ end
+ end
+
+ if settingsCache.pickup_from_drop then
+ -- Grab fuel for self from target:
+ if inserter_is_at_drop_pos(inserter) then
+ local source = drop_target_of_inserter(inserter)
+ if source and source.burner then
+ local src_fuel = source.burner.inventory
+ local dest_fuel = inserter.burner.inventory
+ if src_fuel and not src_fuel.is_empty()
+ and dest_fuel and needs_refuelling(dest_fuel, 1) then
+ return inserter_leech_fuel(src_fuel, inserter, dest_fuel)
+ end
+ end
end
end
end
@@ -157,8 +173,19 @@ function inserter_is_at_pickup_pos(inserter)
)
end
-function needs_refuelling(fuel_inv)
- local min_count = settingsCache.min_fuel_items
+function inserter_is_at_drop_pos(inserter)
+ -- Quick and dirty check for hand hovering over drop position.
+ local hand_pos = inserter.held_stack_position
+ local drop_pos = inserter.drop_position
+ local max_variation = settingsCache.pickup_pos_variation
+ return ( -- Inaccurate, but cheap:
+ math.abs(hand_pos.x - drop_pos.x) <= max_variation
+ and math.abs(hand_pos.y - drop_pos.y) <= max_variation
+ )
+end
+
+function needs_refuelling(fuel_inv, min_count)
+ min_count = min_count or settingsCache.min_fuel_items
local count = 0
local stack
for i = 1, #fuel_inv, 1 do
@@ -213,6 +240,18 @@ function pickup_target_of_inserter(inserter)
return entities[1] -- Returns nil if none found
end
+function drop_target_of_inserter(inserter)
+ local entity = inserter.drop_target
+ if entity then
+ return entity
+ end
+ -- Inserters only know a drop target if the entity at
+ -- drop_position has a regular inventory.
+ local entities = inserter.surface.find_entities_filtered{
+ position=inserter.drop_position}
+ return entities[1] -- Returns nil if none found
+end
+
function stack_size_of_inserter(inserter)
local def_stack_size = 1
if inserter.prototype.stack then
@@ -239,6 +278,8 @@ function initSettingsCache()
settingsCache.min_fuel_items = val
val = settings.global["inserter-fuel-leech-self-refuel-cheat-enabled"].value
settingsCache.self_refuel_cheat_enabled = val
+ val = settings.global["inserter-fuel-leech-pickup-from-drop"].value
+ settingsCache.pickup_from_drop = val
end
script.on_init(function()
diff --git a/src/info.json b/src/info.json
index a70df9c..2dd1990 100644
--- a/src/info.json
+++ b/src/info.json
@@ -8,5 +8,5 @@
"factorio_version": "0.18",
"dependencies": ["base >= 0.18.7"],
"license": "GNU GPL-3.0",
- "version": "0.2.5"
+ "version": "0.2.6"
}
diff --git a/src/locale/en/locale.cfg b/src/locale/en/locale.cfg
index 801a2ec..a345092 100644
--- a/src/locale/en/locale.cfg
+++ b/src/locale/en/locale.cfg
@@ -11,6 +11,8 @@ inserter-fuel-leech-pickup-pos-variation=Maximum pickup distance variation
inserter-fuel-leech-self-refuel-cheat-enabled=Use trickle-fuel cheat
+inserter-fuel-leech-pickup-from-drop=Pick up from drop target?
+
[mod-setting-description]
inserter-fuel-leech-min-fuel-items=Inserters leech appropriate fuel items from pickup target's burner inventories until a drop target's burner inventory holds at least this amount of items.\nDefault is 5.
@@ -20,3 +22,5 @@ inserter-fuel-leech-ticks-between-updates=Each tick, N / T inserters get updated
inserter-fuel-leech-pickup-pos-variation=Maximum distance (measured in tiles) between the hand of an inserter and its pickup location to consider it hovering over its pickup target. Keep this small to prevent visible teleporting of items.\nSet this to 10.0 to get BurnerLeech's teleport-to-hand behaviour.\nDefault is 0.3.
inserter-fuel-leech-self-refuel-cheat-enabled=Every once in a while, out-of-fuel burner inserters get a minuscule amount of free fuel. This allows them to grab more fuel from their pickup location and get themselves properly fueled.\n
+
+inserter-fuel-leech-pickup-from-drop=Should burner inserters leech fuel from their drop target?\nDefault is no.
diff --git a/src/settings.lua b/src/settings.lua
index e428c87..92f5ae7 100644
--- a/src/settings.lua
+++ b/src/settings.lua
@@ -30,6 +30,13 @@ data:extend({
maximum_value = 10.00,
default_value = 0.3,
},
+ {
+ name = "inserter-fuel-leech-pickup-from-drop",
+ type = "bool-setting",
+ order = "40",
+ setting_type = "runtime-global",
+ default_value = false,
+ },
{
name = "inserter-fuel-leech-self-refuel-cheat-enabled",
type = "bool-setting",