use of forestry.api.multiblock.IMultiblockComponent in project ForestryMC by ForestryMC.
the class FarmController method isMachineWhole.
@Override
protected void isMachineWhole() throws MultiblockValidationException {
super.isMachineWhole();
boolean hasGearbox = false;
for (IMultiblockComponent part : connectedParts) {
if (part instanceof TileFarmGearbox) {
hasGearbox = true;
break;
}
}
if (!hasGearbox) {
throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.farm.error.needGearbox"));
}
}
use of forestry.api.multiblock.IMultiblockComponent in project ForestryMC by ForestryMC.
the class GreenhouseController method setCamouflageBlock.
@Override
public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) {
if (!ItemStackUtil.isIdenticalItem(camouflageBlock, camouflage)) {
camouflage = camouflageBlock;
if (sendClientUpdate && world.isRemote) {
for (IMultiblockComponent comp : connectedParts) {
if (comp instanceof ICamouflagedTile) {
ICamouflagedTile camBlock = (ICamouflagedTile) comp;
BlockPos coordinates = camBlock.getCoordinates();
world.markBlockRangeForRenderUpdate(coordinates, coordinates);
}
}
NetworkUtil.sendToServer(new PacketCamouflageSelectionServer(this, CamouflageHandlerType.STRUCTURE));
}
return true;
}
return false;
}
use of forestry.api.multiblock.IMultiblockComponent in project ForestryMC by ForestryMC.
the class MultiblockControllerBase method getPartsListString.
@Override
public String getPartsListString() {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (IMultiblockComponent part : connectedParts) {
if (!first) {
sb.append(", ");
}
BlockPos partCoord = part.getCoordinates();
sb.append(String.format("(%d: %d, %d, %d)", part.hashCode(), partCoord.getX(), partCoord.getY(), partCoord.getZ()));
first = false;
}
return sb.toString();
}
use of forestry.api.multiblock.IMultiblockComponent in project ForestryMC by ForestryMC.
the class MultiblockControllerForestry method onMachineAssembled.
@Override
protected void onMachineAssembled() {
super.onMachineAssembled();
if (world.isRemote) {
return;
}
// Figure out who owns the multiblock, by majority
Multiset<GameProfile> owners = HashMultiset.create();
for (IMultiblockComponent part : connectedParts) {
GameProfile owner = part.getOwner();
if (owner != null) {
owners.add(owner);
}
}
GameProfile owner = null;
int max = 0;
for (Multiset.Entry<GameProfile> entry : owners.entrySet()) {
int count = entry.getCount();
if (count > max) {
max = count;
owner = entry.getElement();
}
}
if (owner != null) {
getOwnerHandler().setOwner(owner);
}
}
use of forestry.api.multiblock.IMultiblockComponent 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