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++;
}
}
}
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;
}
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();
}
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();
}
}
}
}
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]);
}
}
Aggregations