Search in sources :

Example 1 with IFactoryPlantable

use of powercrystals.minefactoryreloaded.api.IFactoryPlantable in project MineFactoryReloaded by powercrystals.

the class TileEntityPlanter method activateMachine.

@Override
public boolean activateMachine() {
    BlockPosition bp = _areaManager.getNextBlock();
    ItemStack match = _inventory[getPlanterSlotIdFromBp(bp)];
    for (int stackIndex = 10; stackIndex <= 25; stackIndex++) {
        ItemStack availableStack = getStackInSlot(stackIndex);
        //skip planting attempt if there's no stack in that slot, or if there's a template item that's not matched
        if (availableStack == null || (match != null && !stacksEqual(match, availableStack))) {
            continue;
        }
        if (!MFRRegistry.getPlantables().containsKey(new Integer(availableStack.itemID))) {
            continue;
        }
        IFactoryPlantable plantable = MFRRegistry.getPlantables().get(new Integer(availableStack.itemID));
        if (!plantable.canBePlantedHere(worldObj, bp.x, bp.y, bp.z, availableStack)) {
            continue;
        }
        plantable.prePlant(worldObj, bp.x, bp.y, bp.z, availableStack);
        worldObj.setBlock(bp.x, bp.y, bp.z, plantable.getPlantedBlockId(worldObj, bp.x, bp.y, bp.z, availableStack), plantable.getPlantedBlockMetadata(worldObj, bp.x, bp.y, bp.z, availableStack), 3);
        plantable.postPlant(worldObj, bp.x, bp.y, bp.z, availableStack);
        decrStackSize(stackIndex, 1);
        return true;
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : IFactoryPlantable(powercrystals.minefactoryreloaded.api.IFactoryPlantable) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack)

Aggregations

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