use of powercrystals.minefactoryreloaded.api.IFactoryFertilizer in project MineFactoryReloaded by powercrystals.
the class TileEntityFertilizer method activateMachine.
@Override
public boolean activateMachine() {
BlockPosition bp = _areaManager.getNextBlock();
int targetId = worldObj.getBlockId(bp.x, bp.y, bp.z);
if (!MFRRegistry.getFertilizables().containsKey(new Integer(targetId))) {
setIdleTicks(getIdleTicksMax());
return false;
}
for (int stackIndex = 0; stackIndex < getSizeInventory(); stackIndex++) {
ItemStack fertStack = getStackInSlot(stackIndex);
if (fertStack == null || !MFRRegistry.getFertilizers().containsKey(new Integer(fertStack.itemID))) {
continue;
}
IFactoryFertilizer fertilizer = MFRRegistry.getFertilizers().get(new Integer(fertStack.itemID));
IFactoryFertilizable fertilizable = MFRRegistry.getFertilizables().get(new Integer(targetId));
if (fertilizer.getFertilizerMeta() != fertStack.getItemDamage()) {
continue;
}
if (!fertilizable.canFertilizeBlock(worldObj, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
continue;
}
if (fertilizable.fertilize(worldObj, _rand, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
fertilizer.consume(fertStack);
if (fertStack.stackSize <= 0) {
setInventorySlotContents(stackIndex, null);
}
return true;
}
}
setIdleTicks(getIdleTicksMax());
return false;
}
Aggregations