Search in sources :

Example 11 with IMultiblockComponent

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"));
    }
}
Also used : TileFarmGearbox(forestry.farming.tiles.TileFarmGearbox) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) MultiblockValidationException(forestry.core.multiblock.MultiblockValidationException)

Example 12 with IMultiblockComponent

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;
}
Also used : ICamouflagedTile(forestry.api.core.ICamouflagedTile) BlockPos(net.minecraft.util.math.BlockPos) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) PacketCamouflageSelectionServer(forestry.greenhouse.network.packets.PacketCamouflageSelectionServer)

Example 13 with IMultiblockComponent

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();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent)

Example 14 with IMultiblockComponent

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);
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent)

Example 15 with IMultiblockComponent

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;
}
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)22 BlockPos (net.minecraft.util.math.BlockPos)13 TileEntity (net.minecraft.tileentity.TileEntity)7 ICamouflagedTile (forestry.api.core.ICamouflagedTile)6 HashSet (java.util.HashSet)6 IChunkProvider (net.minecraft.world.chunk.IChunkProvider)6 ICamouflageHandler (forestry.api.core.ICamouflageHandler)4 IMultiblockController (forestry.api.multiblock.IMultiblockController)4 Nullable (javax.annotation.Nullable)3 IMultiblockLogic (forestry.api.multiblock.IMultiblockLogic)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Set (java.util.Set)2 ItemStack (net.minecraft.item.ItemStack)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 GameProfile (com.mojang.authlib.GameProfile)1 MultiblockValidationException (forestry.core.multiblock.MultiblockValidationException)1 TileUtil (forestry.core.tiles.TileUtil)1