Old
Code: Select all
-- On a lower interval rate, look for chests behind the belt to copy item type
if tick.tick % chest_detection_rate == 0 then
x = belt.entity.position.x;
y = belt.entity.position.y;
if belt.entity.direction == 0 then
y = y + 1;
elseif belt.entity.direction == 2 then
x = x - 1;
elseif belt.entity.direction == 4 then
y = y - 1;
elseif belt.entity.direction == 6 then
x = x + 1;
end
chests = belt.entity.surface.find_entities_filtered({area = {{x,y},{x,y}}, type="container"});
if #chests > 0 then
inventory = chests[1].get_inventory(defines.inventory.chest);
if inventory ~= nil
and inventory.valid == true
and inventory.is_empty() == false
and inventory[1].valid == true
and inventory[1].valid_for_read == true then
belt.item = inventory[1].name;
end
end
end
Code: Select all
-- On a lower interval rate, look for chests behind the belt to copy item type
if tick.tick % chest_detection_rate == 0 then
x = belt.entity.position.x;
y = belt.entity.position.y;
if belt.entity.direction == 0 then
chests = belt.entity.surface.find_entities_filtered{area = {{x,y},{x,y+1}}, type="container"};
elseif belt.entity.direction == 2 then
chests = belt.entity.surface.find_entities_filtered{area = {{x-1,y},{x,y}}, type="container"};
elseif belt.entity.direction == 4 then
chests = belt.entity.surface.find_entities_filtered{area = {{x,y-1},{x,y}}, type="container"};
elseif belt.entity.direction == 6 then
chests = belt.entity.surface.find_entities_filtered{area = {{x,y},{x+1,y}}, type="container"};
end
if #chests > 0 then
inventory = chests[1].get_inventory(defines.inventory.chest);
if inventory ~= nil
and inventory.valid == true
and inventory.is_empty() == false
and inventory[1].valid == true
and inventory[1].valid_for_read == true then
belt.item = inventory[1].name;
end
end
end