Search in sources :

Example 1 with IFactoryFertilizable

use of powercrystals.minefactoryreloaded.api.IFactoryFertilizable 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;
}
Also used : IFactoryFertilizable(powercrystals.minefactoryreloaded.api.IFactoryFertilizable) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack) IFactoryFertilizer(powercrystals.minefactoryreloaded.api.IFactoryFertilizer)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 BlockPosition (powercrystals.core.position.BlockPosition)1 IFactoryFertilizable (powercrystals.minefactoryreloaded.api.IFactoryFertilizable)1 IFactoryFertilizer (powercrystals.minefactoryreloaded.api.IFactoryFertilizer)1