Search in sources :

Example 1 with IMultiblockLogic

use of forestry.api.multiblock.IMultiblockLogic in project ForestryMC by ForestryMC.

the class MultiblockWorldRegistry method attachToNeighbors.

// /// Multiblock Connection Base Logic
private Set<IMultiblockControllerInternal> attachToNeighbors(IMultiblockComponent part) {
    Set<IMultiblockControllerInternal> controllers = new HashSet<>();
    IMultiblockControllerInternal bestController = null;
    MultiblockLogic logic = (MultiblockLogic) part.getMultiblockLogic();
    Class<?> controllerClass = logic.getControllerClass();
    // Look for a compatible controller in our neighboring parts.
    List<IMultiblockComponent> partsToCheck = MultiblockUtil.getNeighboringParts(world, part);
    for (IMultiblockComponent neighborPart : partsToCheck) {
        IMultiblockLogic neighborLogic = neighborPart.getMultiblockLogic();
        if (neighborLogic.isConnected()) {
            IMultiblockControllerInternal candidate = (IMultiblockControllerInternal) neighborLogic.getController();
            if (!controllerClass.isAssignableFrom(candidate.getClass())) {
                // Skip multiblocks with incompatible types
                continue;
            }
            if (!controllers.contains(candidate) && (bestController == null || candidate.shouldConsume(bestController))) {
                bestController = candidate;
            }
            controllers.add(candidate);
        }
    }
    // If we've located a valid neighboring controller, attach to it.
    if (bestController != null) {
        // attachBlock will call onAttached, which will set the controller.
        bestController.attachBlock(part);
    }
    return controllers;
}
Also used : IMultiblockLogic(forestry.api.multiblock.IMultiblockLogic) IMultiblockLogic(forestry.api.multiblock.IMultiblockLogic) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) HashSet(java.util.HashSet)

Aggregations

IMultiblockComponent (forestry.api.multiblock.IMultiblockComponent)1 IMultiblockLogic (forestry.api.multiblock.IMultiblockLogic)1 HashSet (java.util.HashSet)1