[0.16] Factorio Blueprint API for Java

Enhance Your Overall Game-Play.
Mod-Database, Calculators, Cheatsheets, Multiplayer, Scripts, Libs and Other Useful Stuff.

[0.16] Factorio Blueprint API for Java

Postby Shuriken255 » Tue Dec 26, 2017 12:02 am

This API provides you easy way to create blueprint strings for Factorio game in Java.
It will automaticly generate blueprint string, so you won't need to care about building JSON file, compressing it or generate Base64 string.

This API offers you:
- All entities you can build in 0.16 game version;
- Easy way to create, edit and add entities;
- Access to all entity settings including special settings for each type of entity;
- Full circuit network support;

This API is currently in beta state, so it can contain some bugs. Please, leave issue message here or on Git-Hub so i can fix it.

Download: https://github.com/Shuriken255/factorio ... i-v0.9.jar
Git-Hub: https://github.com/Shuriken255/factorio-blueprint-api
Java-doc: https://github.com/Shuriken255/factorio ... avadoc.zip

Example on how to create simple blueprint
Java code:
Code: Select all
import ua.kiev.shuriken.blueprint.Blueprint;
import ua.kiev.shuriken.blueprint.Signals;
import ua.kiev.shuriken.blueprint.entity.logistics.Inserter;
import ua.kiev.shuriken.blueprint.entity.logistics.IronChest;
import ua.kiev.shuriken.blueprint.entity.logistics.SmallElectricPole;
import ua.kiev.shuriken.blueprint.entity.production.AssemblingMachine2;

public class Test {
   public static void main(String[] args) {
      Blueprint blueprint = new Blueprint();
      blueprint.setIcon(0, Signals.Virtual.SIGNAL_T);
      blueprint.setIcon(1, Signals.Virtual.SIGNAL_E);
      blueprint.setIcon(2, Signals.Virtual.SIGNAL_S);
      blueprint.setIcon(3, Signals.Virtual.SIGNAL_T);
      blueprint.setName("For tutorial");
      int value = 4;
      Inserter[] inserters = new Inserter[value*2];
      IronChest[] chests = new IronChest[value*2];
      AssemblingMachine2[] machines = new AssemblingMachine2[value];
      SmallElectricPole[] poles = new SmallElectricPole[value];
      for(int i = 0; i < value; i++) {
         inserters[i] = new Inserter(-1, -value*1.5f+i*3,
         inserters[i+1] = new Inserter(-1, -value*1.5f+2+i*3,
         chests[i] = new IronChest(-2, -value*1.5f+i*3);
         chests[i+1] = new IronChest(-2, -value*1.5f+2+i*3);
         poles[i] = new SmallElectricPole(-1, -value*1.5f+i*3+1);
         machines[i] = new AssemblingMachine2(1, -value*1.5f+i*3+1);

Output will be:
Code: Select all


1. Basics
To start work with this library, you need to create Blueprint object first:
Code: Select all
Blueprint b = new Blueprint();

Then you will need to set at least one icon for this blueprint because blueprint won't be exported if it doesn't have any icon. You should use constants from "Signals" class, that is placed in "ua.kiev.shuriken.blueprint" package. Remember, that all indexes in this API starts from "0", unlike in blueprint's JSON representation.
Code: Select all
b.setIcon(0, Signals.Virtual.SIGNAL_A);

Once you're done with icon, you can start adding entities to it. To add entity into blueprint, you need to create object that extends of entity class and then add it into blueprint using "add(Entity entity)" method. You can find all entities in 3 "ua.kiev.shuriken.blueprint" inner packages. Each inner package represents entities from "Logistic", "Production" or "Combat" categories. All entities require at least 2 arguments to be created: "x" and "y" position. There can be more for different types of entities. Let's create wooden chest and put it in middle of our blueprint:
Code: Select all
Entity woodenChest = new WoodenChest(0, 0);

You also can set name of the blueprint, using "setName(String name)" method:
Code: Select all
b.setName("Blueprint for tutorial");

Once you are finished with your blueprint, you may export it into blueprint string, that you may import from your blueprint library. To get this string, you can use "toString()" method:
Code: Select all
String blueprintString = b.toString();
System.out.println(b.toString); // This will output blueprint string into console

Whole code:
Code: Select all
Blueprint b = new Blueprint();
b.setIcon(0, Signals.Virtual.SIGNAL_A);
Entity woodenChest = new WoodenChest(0, 0);
b.setName("Blueprint for tutorial");
String blueprintString = b.toString();
System.out.println(b.toString); // This will output blueprint string into console

2. Positioning
Blueprint uses 2 ordinates to place entities: "x" (horisontal) and "y" (vertical), which will be shown as [x, y] in this tutorial. [0, 0] is allways central point. Factorio will use Increasing "x", you go east, while decreasing "x", you go west. Increasing "y" you go south and decreasing "y" you go north. Each block here has scale of one, so placing entity at [2, 0] means you place it 2 blocks to east. When you place entity, you set coorinates of central point of this entity:
Notice, that when you have object with even number scale, you will have to place it using a fractional number for it's coordinates.

Many objects in Factorio may have their own direction. Each entity has his own direction constants in it's object's class. All their names start with "DIRECTION_" part. All objects that can be rotated has "int direction" parameter.

3. Shortly about circuit network
All entities can be connected to each other using method "connectTo(Entity entity, int color)". Example:
Code: Select all
Entity inserter = new Inserter(-1, 0, Inserter.DIRECTION_FROM_WEST_TO_EAST);
Entity chest = new IronChest(0, 0);
inserter.connectTo(chest, Connection.COLOR_RED);

But it goes different if you are going to use arithmetic or decider combinators! You will need to use method "connectTo(Entity entity, int typeFrom, int typeTo, int color)". Arithmetic and decider combinators have only 2 types of connection: "TYPE_INPUT" and "TYPE_OUTPUT". Any other entities have only "TYPE_GENERAL". That means if you want to create connection between combinator and other regular entity, you have to use "TYPE_GENERAL" for normal entity and "TYPE_INPUT" or "TYPE_OUTPUT" for combinator one. Example:
Code: Select all
StorageChest chest1 = new StorageChest(-1, 0);
ArithmeticCombinator combinator = new ArithmeticCombinator(0.5f, 0,
      new ArithmeticCombinator.Term(Signals.Items.BATTERY),
      0xFF, Signals.Items.BATTERY);
RequesterChest chest2 = new RequesterChest(2, 0);

chest1.connectTo(combinator, Connection.TYPE_GENERAL, Connection.TYPE_INPUT, Connection.COLOR_GREEN);
combinator.connectTo(chest2, Connection.TYPE_OUTPUT, Connection.TYPE_GENERAL, Connection.COLOR_GREEN);

If you worked with factorio blueprint strings, then you know that factorio describes connection in both ends for case if entites will be put in other order. Don't worry, this library automaticly creates connection on other side at once.

If someone will be interested in this library, there will be more tutorials.
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sat Aug 26, 2017 11:05 am

Return to Tools

Who is online

Users browsing this forum: No registered users and 1 guest