Package: com.codex.composer.api.v1.block
Canonical Name: com.codex.composer.api.v1.block.MultiblockControllerBlock
Common interface for multiblock controllers (blocks that are the main acting block entity in a multiblock).
Inheritors need to implement the following:
@NotNull Identifier multiblock(); // Provides the multiblock to check for. Not nullable.
Also provides the following utility / overrideable methods:
/* Checks the horizontal facing of the given blockstate, and inverts it if NORTH or SOUTH.*/default Direction getOrientation(BlockState state) {...}/* Checks whether the given multiblock is complete at the given location.It's pretty expensive, so don't run it every thick, just hook intoonMultiblockFormed and onMultiblockBroken and store their value. */default boolean isComplete(BlockView world, BlockPos pos)/* Internal methods! Called when the controller block is broken or placed. It creates and destroys the multiblockinstance in the world data component, so don't override them if you don't know what you are doing.*/default void onPlaced(World world, BlockPos pos) {...}default void onBroken(World world, BlockPos pos) {...}/* If you want event hooks for that, use: */default void onMultiblockFormed() { }default void onMultiblockBroken() { }
Example implementation:
From Starstruck (Code currently private, sorry)
public class KilnBlockEntity extends AbstractFuranceBlockEntity implements MultiblockControllerBlock {private boolean multiblockFormed = false;public KilnBlockEntity(BlockPos pos, BlockState state) {...}@Overridepublic Identifier multiblock() {return ModMultiblocks.KILN; // Identifier constant}@Overridepublic void onMultiblockFormed() {multiblockFormed = true;}@Overridepublic void onMultiblockBroken() {multiblockFormed = false;}public boolean isMultiblockFormed() {return multiblockFormed;}public static void tickServer(ServerWorld world, BlockPos pos, BlockState state, KilnBlockEntity be) {if (!be.isMultiblockFormed()) {[...]world.setBlockState(pos, state.with(Properties.LIT, false));return;} else {[...]world.setBlockState(pos, state.with(Properties.LIT, be.litTimeRemaining > 0));}[super].tick([...]);}public static void tickClient(KilnBlockEntity be) {...}@Overrideprotected void writeData(WriteView view) {super.writeData(view);view.putBoolean("multiblockFormed", multiblockFormed);}@Overrideprotected void readData(ReadView view) {super.readData(view);multiblockFormed = view.getBoolean("multiblockFormed", false);}{...extra overrides...}}