Search in sources :

Example 1 with IFactoryFruit

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

the class TileEntityFruitPicker method activateMachine.

@Override
protected boolean activateMachine() {
    int harvestedBlockId = 0;
    int harvestedBlockMetadata = 0;
    BlockPosition targetCoords = getNextTree();
    if (targetCoords == null) {
        setIdleTicks(getIdleTicksMax());
        return false;
    }
    harvestedBlockId = worldObj.getBlockId(targetCoords.x, targetCoords.y, targetCoords.z);
    harvestedBlockMetadata = worldObj.getBlockMetadata(targetCoords.x, targetCoords.y, targetCoords.z);
    IFactoryFruit harvestable = MFRRegistry.getFruits().get(new Integer(harvestedBlockId));
    List<ItemStack> drops = harvestable.getDrops(worldObj, _rand, targetCoords.x, targetCoords.y, targetCoords.z);
    ItemStack replacement = harvestable.getReplacementBlock(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    harvestable.prePick(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    doDrop(drops);
    if (replacement == null) {
        if (MFRConfig.playSounds.getBoolean(true)) {
            worldObj.playAuxSFXAtEntity(null, 2001, targetCoords.x, targetCoords.y, targetCoords.z, harvestedBlockId + (harvestedBlockMetadata << 12));
        }
        worldObj.setBlockToAir(targetCoords.x, targetCoords.y, targetCoords.z);
    } else {
        worldObj.setBlock(targetCoords.x, targetCoords.y, targetCoords.z, replacement.itemID, replacement.getItemDamage(), 3);
    }
    harvestable.postPick(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    return true;
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition) IFactoryFruit(powercrystals.minefactoryreloaded.api.IFactoryFruit) ItemStack(net.minecraft.item.ItemStack)

Aggregations

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