Repository navigation
Creating a multiblock
The multiblock will stem from a Block Entity that extends MultiBlockEntity. There will be a number of methods that your IDE will ask you to implement. Aside from these methods, there is only a couple other things to do.
Create a block entity as normal, but instead of extending block entity, extend MultiBlockEntity.
It will ask you to implement "getStructureMatrixList()" and "structureCanRotateVertically()" methods. You will have to implement both. Please note that at the moment, structures not capable of rotating vertically. This is planned to be added in a future release.
Get Structure Matrix List asks for a Matrix of Arrays of Blocks. The first 3 layers are the y, x and z, and the fourth is an array of blocks which are valid for that location. I'd recommend an implementation similar to what I have done with Milkevs Ore Miners here
Be sure to have your controller block (aka "this") be in the Structure Matrix in exactly one location!
Other than this, you can create your block entity as normal.
Call MilkevsMultiBlockLibrary.registerMultiblock(MultiBlockEntity); with a reference to your multiblock entity. While this technically is not required, this is what enables the preview render for the multiblock structure.
It is up to the user to decide when and how the structure is validated. You can attempt to validate the structure at any time using the validateStructure() function. You can read the current validity of the structure by using isStructureValid(). Id personally recommend setting up some sort of timer on your tick function to periodically check the validity of the structure. I don't recommend running it too often though, as it is not a cheap function.
You can override validateStructure() to add your own checks for structure validity. Id recommend calling super.validateStructure(), and then adding your own code to check if the structure is still valid, such as if the structure contains a certain block. You can use invalidateStructure(MutableText) to invalidate the structure. MutableText should be passed through as a Text.translatable and will be displayed to the player when they right click on the multiblock entity with a multiblock builder. You can grab the current invalid reason by using getInvalidReason().
Use togglePreview(PlayerEntity) to toggle the preview of the multiblock. Id recommend calling this on your block when its interacted with. Currently this method only triggers if the player has an empty hand and off hand and is crouching, but I will remove these restrictions at some point.
The Block Entity, while technically directional, doesnt really care about the direction of the controller block. The direction the block entity stores is purely used for the preview. All 4 directions are always checked for structure validity. If you have a directional block for your controller then (TOOD) you can use getDirection() to get the direction the multiblock has been determined as valid in (or what direction the preview is in if the structure is incomplete) and use that to orient your controller block.
If you have any questions, feel free to reach out on my discord or post an issue on this github and I'll do my best to help.