Search in sources :

Example 6 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class TileGearbox method updateServerSide.

@Override
protected void updateServerSide() {
    super.updateServerSide();
    if (energyManager.getTotalEnergyStored() == 0) {
        ITileStructure central = getCentralTE();
        if (!(central instanceof TileForestry)) {
            return;
        }
        TileForestry centralHousing = (TileForestry) central;
        centralHousing.setErrorState(EnumErrorCode.NOPOWER);
        return;
    }
    if (activationDelay > 0) {
        activationDelay--;
        return;
    }
    // Hard limit to 4 cycles / second.
    if (workCounter < WORK_CYCLES && energyManager.consumeEnergyToDoWork()) {
        workCounter++;
    }
    if (workCounter >= WORK_CYCLES && updateOnInterval(5)) {
        ITileStructure central = getCentralTE();
        if (!(central instanceof IFarmHousing)) {
            return;
        }
        if (((IFarmHousing) central).doWork()) {
            workCounter = 0;
            previousDelays = 0;
        } else {
            // If the central TE doesn't have work, we add to the activation delay to throttle the CPU usage.
            activationDelay = 10 * previousDelays < 120 ? 10 * previousDelays : 120;
            // First delay is free!
            previousDelays++;
        }
    }
}
Also used : ITileStructure(forestry.api.core.ITileStructure) IFarmHousing(forestry.api.farming.IFarmHousing) TileForestry(forestry.core.gadgets.TileForestry)

Example 7 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class TriggerLowLiquid method isTriggerActive.

/**
 * Return true if the tile given in parameter activates the trigger, given
 * the parameters.
 */
@Override
public boolean isTriggerActive(TileEntity tile, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters) {
    if (!(tile instanceof TileHatch)) {
        return false;
    }
    ITileStructure central = ((TileHatch) tile).getCentralTE();
    if (central == null || !(central instanceof TileFarmPlain)) {
        return false;
    }
    TankManager tankManager = ((TileFarmPlain) central).getTankManager();
    FluidTankInfo info = tankManager.getTankInfo(0);
    if (info.fluid == null) {
        return true;
    }
    return ((float) info.fluid.amount / info.capacity) <= threshold;
}
Also used : ITileStructure(forestry.api.core.ITileStructure) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) TankManager(forestry.core.fluids.TankManager) TileHatch(forestry.farming.gadgets.TileHatch) TileFarmPlain(forestry.farming.gadgets.TileFarmPlain)

Example 8 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class BlockStructure method onNeighborBlockChange.

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
    super.onNeighborBlockChange(world, x, y, z, neighbor);
    if (!Proxies.common.isSimulating(world)) {
        return;
    }
    TileEntity tile = world.getTileEntity(x, y, z);
    if (!(tile instanceof ITileStructure)) {
        return;
    }
    ((ITileStructure) tile).validateStructure();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure)

Example 9 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class StructureLogic method resetStructureBlocks.

protected void resetStructureBlocks(Schemata schemata) {
    Vect dimensions = schemata.getDimensions(isRotated);
    int offsetX = schemata.getxOffset();
    int offsetZ = schemata.getzOffset();
    if (isRotated) {
        offsetX = schemata.getzOffset();
        offsetZ = schemata.getxOffset();
    }
    for (int i = 0; i < dimensions.x; i++) {
        for (int j = 0; j < schemata.getHeight(); j++) {
            for (int k = 0; k < dimensions.z; k++) {
                int x = structureTile.xCoord + i + offsetX;
                int y = structureTile.yCoord + j + schemata.getyOffset();
                int z = structureTile.zCoord + k + offsetZ;
                TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
                if (!(tile instanceof ITileStructure)) {
                    continue;
                }
                ITileStructure part = (ITileStructure) tile;
                if (!part.getTypeUID().equals(getTypeUID())) {
                    continue;
                }
                part.onStructureReset();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure) Vect(forestry.core.vect.Vect)

Example 10 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class StructureLogic method validateStructure.

@Override
public void validateStructure() {
    ITileStructure master = structure.getCentralTE();
    if (!structure.isMaster() && master != null) {
        master.validateStructure();
        return;
    }
    EnumStructureState state = EnumStructureState.INDETERMINATE;
    boolean rotate;
    for (int i = 0; i < schematas.length; i++) {
        if (!schematas[i].isEnabled()) {
            continue;
        }
        state = determineMasterState(schematas[i], false);
        rotate = false;
        if (state == EnumStructureState.INVALID && schematas[i].getWidth() != schematas[i].getDepth()) {
            state = determineMasterState(schematas[i], true);
            rotate = true;
        }
        if (state == EnumStructureState.VALID) {
            activeSchemata = (short) i;
            isRotated = rotate;
            break;
        }
    }
    // Structure state is indeterminate, possibly caused by chunkloading. Remain calm, do nothing.
    if (state == EnumStructureState.INDETERMINATE) {
        return;
    }
    if (state == EnumStructureState.VALID) {
        // ((TileEntity)structure).zCoord));
        if (!structure.isMaster()) {
            structure.makeMaster();
            markStructureBlocks(schematas[activeSchemata]);
        }
    /*
			 * int offsetX = schematas[activeSchemata].getxOffset(); int offsetZ = schematas[activeSchemata].getzOffset(); if(isRotated) { offsetX =
			 * schematas[activeSchemata].getzOffset(); offsetZ = schematas[activeSchemata].getxOffset();
			 * 
			 * }
			 */
    // System.out.println(String.format("Offsets: %s and %s.", offsetX, offsetZ));
    } else if (structure.isMaster()) // Structure is invalid, break it up.
    {
        resetStructureBlocks(schematas[activeSchemata]);
    }
}
Also used : ITileStructure(forestry.api.core.ITileStructure) EnumStructureState(forestry.core.gadgets.BlockStructure.EnumStructureState)

Aggregations

ITileStructure (forestry.api.core.ITileStructure)12 TileEntity (net.minecraft.tileentity.TileEntity)6 Vect (forestry.core.vect.Vect)4 EnumStructureBlock (forestry.core.utils.Schemata.EnumStructureBlock)3 IFarmComponent (forestry.api.farming.IFarmComponent)2 TileFarmPlain (forestry.farming.gadgets.TileFarmPlain)2 TileHatch (forestry.farming.gadgets.TileHatch)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 IStatementParameter (buildcraft.api.statements.IStatementParameter)1 IAlvearyComponent (forestry.api.apiculture.IAlvearyComponent)1 IFarmHousing (forestry.api.farming.IFarmHousing)1 ForestryBlock (forestry.core.config.ForestryBlock)1 TankManager (forestry.core.fluids.TankManager)1 EnumStructureState (forestry.core.gadgets.BlockStructure.EnumStructureState)1 TileForestry (forestry.core.gadgets.TileForestry)1 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)1