data.lua
{
type = "custom-input",
name = "inserter-Pickup-long-distance-toggle",
key_sequence = "CONTROL + C",
consuming = "script-only"
},
{
type = "custom-input",
name = "inserter-Drop-long-distance-toggle",
key_sequence = "CONTROL + SHIFT + C",
consuming = "script-only"
},
control.lua
script.on_event("inserter-Pickup-long-distance-toggle", function(event)
local selection = game.players[event.player_index].selected
if selection and string.find(selection.name, "long") and (selection.type == "inserter" or (selection.type == "entity-ghost" and selection.ghost_type == "inserter")) then
TogglePickupDistanceLong(selection)
end
end)
script.on_event("inserter-Drop-long-distance-toggle", function(event)
local selection = game.players[event.player_index].selected
if selection and string.find(selection.name, "long") and (selection.type == "inserter" or (selection.type == "entity-ghost" and selection.ghost_type == "inserter")) then
ToggleDropDistanceLong(selection)
end
end)
....
function TogglePickupDistanceLong(entity)
if string.find(entity.name, "long") then
local OFFSET = 1
local px = entity.pickup_position.x - entity.position.x
local py = entity.pickup_position.y - entity.position.y
local dx = entity.drop_position.x - entity.position.x
local dy = entity.drop_position.y - entity.position.y
local dir = GetPickupDirection(entity)
if dir == defines.direction.north then
if py < 1.5 then
py = py + OFFSET
else
py = py - OFFSET
end
elseif dir == defines.direction.south then
if py < -1.5 then
py = py + OFFSET
else
py = py - OFFSET
end
elseif dir == defines.direction.west then
if px < 1.5 then
px = px + OFFSET
else
px = px - OFFSET
end
elseif dir == defines.direction.east then
if px < -1.5 then
px = px + OFFSET
else
px = px - OFFSET
end
end
entity.pickup_position =
{
entity.position.x + px,
entity.position.y + py
}
if GetPickupDirection(entity) == entity.direction and math.abs(px - dx) < 0.5 and math.abs(py - dy) < 0.5 then
ToggleDropDistanceLong(entity)
end
end
end
function ToggleDropDistanceLong(entity)
if string.find(entity.name, "long") then
local OFFSET = 1
local px = entity.pickup_position.x - entity.position.x
local py = entity.pickup_position.y - entity.position.y
local dx = entity.drop_position.x - entity.position.x
local dy = entity.drop_position.y - entity.position.y
local dir = entity.direction
if dir == defines.direction.north then
if dy < 1.5 then
dy = dy + OFFSET
else
dy = dy - OFFSET
end
elseif dir == defines.direction.south then
if dy < -1.5 then
dy = dy + OFFSET
else
dy = dy - OFFSET
end
elseif dir == defines.direction.west then
if dx < 1.5 then
dx = dx + OFFSET
else
dx = dx - OFFSET
end
elseif dir == defines.direction.east then
if dx < -1.5 then
dx = dx + OFFSET
else
dx = dx - OFFSET
end
end
entity.drop_position = {entity.position.x + dx, entity.position.y + dy}
-- set direction to force update of insert location when hand is already full
entity.direction = entity.direction
if GetPickupDirection(entity) == entity.direction and math.abs(px - dx) < 0.5 and math.abs(py - dy) < 0.5 then
TogglePickupDistanceLong(entity)
end
end
end
....
*Change in function RotatePickup*
if GetPickupDirection(entity) == entity.direction and math.abs(px - dx) < 0.5 and math.abs(py - dy) < 0.5 then
ApplyPickupRotation(entity, clockwise)
end