Structures - A library that simplifies working with structures.
en | ru
Before starting work, you need to import the library.
IMPORT("Structures", "*"); // Import all modules
// Or
IMPORT("Structures", "Structure"); // Import module of structures
IMPORT("Structures", "Rotate"); // Import module of turns
IMPORT("Structures", "TileEntityRandomize"); // Import module TileEntityRandomize
IMPORT("Structures", "TileEntityFiller"); // Import module TileEntityFiller
IMPORT("Structures", "DefaultTileEntityFiller"); // Import DefaultTileEntityFiller
IMPORT("Structures", "APOFiller"); // Import filler from APOCraft
Create a structure using the Structure constructor
let struct = new Structure();
Then add data to the structure with the addBlock and addTileEntity methods
struct.addBlock(1, 1, 0, 5, 2);
struct.addBlock(0, 2, 0, 5, 2);
struct.addBlock(0, 3, 0, 5, 4);
struct.addBlock(0, 4, 0, 54, 0, "chest1");
struct.addTileEntity("chest1", new DefaultTileEntityFiller({
0:{ id:5, count:64 }
}));
Invoke writeInFile method
struct.writeInFile("structName");
To set the structure in the world, use the build (x, y, z, rotates, random ?, region?) Method, where:
- int x - X coordinate
- int y - Y coordinate
- int z - Z coordinate
- Rotate | Array rotates - Rotation or array of rotations. Rotation will be randomly selected from the array
- java.util.Random random - A random object to get random values
- BlockSource region
Callback.addCallback("ItemUse", function(coords, item, block, isExteral, player){
let region = BlockSourse.getDefaultForActor(player);
struct.build(coords.x,
coords.y,
coords.z, Structure.ROTATE_NONE, null, region);
})
{
"version":3,//int - file structure version
"structures":[], // An array of blocks of the format [int x, int y, int z, ItemInstance item, TileEntityRandomize? radom_te]
"tile_entities":{} // List of TE filler
}
TileEntityRandomize is an object of the format "Chance":"Filler Name". The chance is indicated from 0 to 1.
{
"1":"test_te"
}
TE fillers have the format "Filler Name": {Filler Data}
"test_te":{ // TE filler named test_te
"type":"default_filler", // Filler type (REQUIRED)
... // Filler data
}
DefaultTileEntityFiller fill the TileEntity with the specified content. Supports native and custom TileEntity. The file has the following format:
{
"type":"default_filler",
"slots":{},//Object of format "Slot name": ItemInstance.
"data":{} //TileEntity data
}
APOFiller migrated straight from A.P.O. Craft. Supports only native TileEntity. The file has the following format:
{
"type":"apo_filler",
"items":[// Array of items that can be generated inside TileEntity
{
"id": 5, // int - item ID
"data": 1, // int - item data
"rarity": 1, // float - Item Generation Chance, from 0 to 1
"count": 4 // int | {"min":int, "max":int} - The amount of generated item. If the quantity is specified as an object, then it is generated randomly.
},
]
}
class CustomTileEntityFiller extends TileEntityFiller{
/**
* Filling TileEntity
*/
public fill(TE:ItemContainer | TileEntity | NativeTileEntity, random:java.lang.Random): void {}
/**
* Read from file
*/
public parseJSON(json:ITileEntityFiller): void {}
/**
* Write in file
*/
public toJSON(): ITileEntityFiller {
//Get JSON from parent filler. (Required)
let json = super.toJSON();
//Here adding your data
return json;
}
}
//Register filler (Required)
TileEntityFiller.register("custom_filler", CustomTileEntityFiller);
For use in JavaScript, you can use the extends library
IMPORT("extends", "__extends");
function CustomTileEntityFiller(){
TileEntityFiller.call(this)
};
__extends(CustomTileEntityFiller, TileEntityFiller);
/**
* Filling TileEntity
*/
CustomTileEntityFiller.prototype.fill = function(TE, random){}
/**
* Read from file
*/
CustomTileEntityFiller.prototype.parseJSON = function(json){}
/**
* Write in file
*/
CustomTileEntityFiller.prototype.toJSON = function(){
//Get JSON from parent filler. (Required)
let json = TileEntityFiller.prototype.toJSON.call(this);
//Here adding your data
return json;
}
//Register filler (Required)
TileEntityFiller.register("custom_filler", CustomTileEntityFiller);