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;
}
Aggregations