Skip to content

Instantly share code, notes, and snippets.

@kellbot
Created June 14, 2023 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellbot/600f53f42d823d99e3f1e7389f79f749 to your computer and use it in GitHub Desktop.
Save kellbot/600f53f42d823d99e3f1e7389f79f749 to your computer and use it in GitHub Desktop.
const Blueprint = require('factorio-blueprint');
const bp = new Blueprint();
Blueprint.setEntityData({
'aai_strongbox_passive_provider':
{
type: 'item', // 'item', 'fluid', 'virtual', 'tile', or 'recipe'
width: 2,
height: 2,
recipe: true,
modules: 4,
inventorySize: 96, // How many slots this container has (such as a chest)
filterAmount: false, // Set to false for filter inserters which have filters but no "amounts" on the filters
directionType: false // true for underground belts
}
});
let startY = 1;
let segment = 1;
let flipped = false;
let lastSubstation;
//Start with some substations
for (let i = 0; i < 40; i += 18) {
flipped = (segment % 2 == 0) ? true : false;
let lastSegment = (i + 18 < 40) ? true : false;
let topDirection = flipped ? Blueprint.RIGHT : Blueprint.LEFT;
let bottomDirection = flipped ? Blueprint.LEFT : Blueprint.RIGHT;
let midDirection = flipped ? Blueprint.DOWN : Blueprint.UP;
bp.createEntity('fast_underground_belt', { x: i, y: startY - 1} , Blueprint.DOWN);
bp.createEntity('fast_underground_belt', { x: i+1, y: startY - 1} , Blueprint.DOWN);
let substation = bp.createEntity('substation', { x: i, y: startY }, Blueprint.RIGHT);
if (lastSubstation) {
substation.connect(lastSubstation, null, null, 'red');
substation.connect(lastSubstation, null, null, 'green');
}
lastSubstation = substation;
if (flipped) {
bp.createEntity('fast_underground_belt', { x: i, y: startY + 2} , Blueprint.DOWN).setDirectionType('output');
bp.createEntity('fast_underground_belt', { x: i+1, y: startY + 2} , Blueprint.DOWN).setDirectionType('output');
} else {
bp.createEntity('fast_underground_belt', { x: i, y: startY + 2} , Blueprint.UP);
bp.createEntity('fast_underground_belt', { x: i+1, y: startY + 2} , Blueprint.UP);
}
// Put 2x2 boxes between them
if (lastSegment) {
for (let j = 2; j < 18; j +=2 ) {
bp.createEntity('aai_strongbox_passive_provider', { x: j + i, y: startY + 1}, Blueprint.RIGHT);
bp.createEntity('aai_strongbox_passive_provider', { x: j + i, y: startY - 1}, Blueprint.RIGHT);
if (flipped) {
bp.createEntity('stack_filter_inserter', { x: j + i, y: startY + 3 }, Blueprint.UP);
bp.createEntity('stack_inserter', { x: j + i + 1, y: startY + 3 }, Blueprint.DOWN);
bp.createEntity('stack_filter_inserter', { x: j + i, y: startY - 2 }, Blueprint.DOWN);
bp.createEntity('stack_inserter', { x: j + i + 1, y: startY - 2 }, Blueprint.UP);
} else {
bp.createEntity('stack_filter_inserter', { x: j + i + 1, y: startY + 3 }, Blueprint.DOWN);
bp.createEntity('stack_inserter', { x: j + i, y: startY + 3 }, Blueprint.UP);
bp.createEntity('stack_filter_inserter', { x: j + i + 1, y: startY - 2 }, Blueprint.DOWN);
bp.createEntity('stack_inserter', { x: j + i, y: startY - 2 }, Blueprint.UP);
}
}
// Add belts
for (let k = 2; k < 18; k++) {
bp.createEntity('fast_transport_belt', { x: k + i, y: 5}, topDirection);
bp.createEntity('fast_transport_belt', { x: k + i, y: -2}, bottomDirection);
}
}
if (!flipped) {
bp.createEntity('fast_transport_belt', { x: 1 + i, y: -2}, Blueprint.RIGHT);
bp.createEntity('fast_transport_belt', { x: i, y: -2}, Blueprint.LEFT);
bp.createEntity('fast_transport_belt', { x: i, y: 5}, midDirection);
bp.createEntity('fast_transport_belt', { x: 1 + i, y: 5}, midDirection);
} else {
bp.createEntity('fast_transport_belt', { x: 1 + i, y: -2}, midDirection);
bp.createEntity('fast_transport_belt', { x: i, y: -2}, midDirection);
bp.createEntity('fast_transport_belt', { x: i, y: 5}, Blueprint.LEFT);
bp.createEntity('fast_transport_belt', { x: 1 + i, y: 5}, Blueprint.RIGHT);
}
bp.createEntity('fast_transport_belt', { x: 1 + i, y: 4}, midDirection);
bp.createEntity('fast_transport_belt', { x: 1 + i, y: -1}, midDirection);
bp.createEntity('fast_transport_belt', { x: i, y: 4}, midDirection);
bp.createEntity('fast_transport_belt', { x: i, y: -1}, midDirection);
segment++;
}
// Center the blueprint around the entities instead of position (0,0)
bp.fixCenter();
// Output the blueprint string!
console.log(bp.encode({version: 'latest', autoConnectPoles: true}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment