Search in sources :

Example 1 with IHarvestingTarget

use of crazypants.enderio.base.farming.harvesters.IHarvestingTarget in project EnderIO by SleepyTrousers.

the class ItemDarkSteelAxe method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(@Nonnull ItemStack itemstack, @Nonnull BlockPos pos, @Nonnull EntityPlayer player) {
    if (!player.world.isRemote && !player.isSneaking() && EnergyUpgradeManager.itemHasAnyPowerUpgrade(itemstack)) {
        IBlockState bs = player.world.getBlockState(pos);
        Block block = bs.getBlock();
        if (FarmersRegistry.isLog(block)) {
            int powerStored = EnergyUpgradeManager.getEnergyStored(itemstack);
            HarvestResult res = new HarvestResult();
            final IHarvestingTarget target = new AxeHarvestingTarget(bs, pos);
            TreeHarvester.harvest(player.world, pos, res, target);
            NNList<BlockPos> sortedTargets = new NNList<BlockPos>(res.getHarvestedBlocks());
            harvestComparator.refPoint = pos;
            Collections.sort(sortedTargets, harvestComparator);
            int maxBlocks = powerStored / Config.darkSteelAxePowerUsePerDamagePointMultiHarvest;
            int numUsedPower = 0;
            for (int i = 0; numUsedPower < maxBlocks && i < sortedTargets.size(); i++) {
                if (doMultiHarvest(player, player.world, sortedTargets.get(i), block)) {
                    numUsedPower++;
                }
            }
            return numUsedPower != 0;
        }
    }
    return false;
}
Also used : HarvestResult(crazypants.enderio.base.farming.farmers.HarvestResult) IBlockState(net.minecraft.block.state.IBlockState) AxeHarvestingTarget(crazypants.enderio.base.farming.harvesters.AxeHarvestingTarget) IHarvestingTarget(crazypants.enderio.base.farming.harvesters.IHarvestingTarget) NNList(com.enderio.core.common.util.NNList) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with IHarvestingTarget

use of crazypants.enderio.base.farming.harvesters.IHarvestingTarget in project EnderIO by SleepyTrousers.

the class TreeFarmer method harvestBlock.

@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull BlockPos bc, @Nonnull Block block, @Nonnull IBlockState meta) {
    setupHarvesting(farm, bc);
    if (!hasAxe) {
        farm.setNotification(FarmNotification.NO_AXE);
        return null;
    }
    final World world = farm.getWorld();
    final HarvestResult res = new HarvestResult();
    final IHarvestingTarget target = new FarmHarvestingTarget(this, farm);
    TreeHarvester.harvest(world, bc, res, target);
    Collections.sort(res.getHarvestedBlocks(), comp);
    List<BlockPos> actualHarvests = new ArrayList<BlockPos>();
    for (int i = 0; i < res.getHarvestedBlocks().size() && hasAxe; i++) {
        final BlockPos coord = res.getHarvestedBlocks().get(i);
        harvestSingleBlock(farm, world, res, coord);
        actualHarvests.add(coord);
    }
    res.getHarvestedBlocks().clear();
    res.getHarvestedBlocks().addAll(actualHarvests);
    tryReplanting(farm, world, bc, res);
    return res;
}
Also used : IHarvestResult(crazypants.enderio.api.farm.IHarvestResult) IHarvestingTarget(crazypants.enderio.base.farming.harvesters.IHarvestingTarget) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) FarmHarvestingTarget(crazypants.enderio.base.farming.harvesters.FarmHarvestingTarget)

Aggregations

IHarvestingTarget (crazypants.enderio.base.farming.harvesters.IHarvestingTarget)2 BlockPos (net.minecraft.util.math.BlockPos)2 NNList (com.enderio.core.common.util.NNList)1 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)1 HarvestResult (crazypants.enderio.base.farming.farmers.HarvestResult)1 AxeHarvestingTarget (crazypants.enderio.base.farming.harvesters.AxeHarvestingTarget)1 FarmHarvestingTarget (crazypants.enderio.base.farming.harvesters.FarmHarvestingTarget)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 World (net.minecraft.world.World)1