use of crazypants.enderio.api.farm.IHarvestResult in project EnderIO by SleepyTrousers.
the class CustomSeedFarmer method harvestBlock.
@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull final BlockPos pos, @Nonnull Block block, @Nonnull IBlockState state) {
if (!canHarvest(farm, pos, block, state)) {
return null;
}
if (!farm.hasTool(FarmingTool.HOE)) {
farm.setNotification(FarmNotification.NO_HOE);
return null;
}
final World world = farm.getWorld();
final EntityPlayerMP joe = farm.startUsingItem(FarmingTool.HOE);
final int fortune = farm.getLootingValue(FarmingTool.HOE);
final NNList<EntityItem> result = new NNList<EntityItem>();
NNList<ItemStack> drops = new NNList<>();
block.getDrops(drops, world, pos, state, fortune);
float chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, pos, state, fortune, 1.0F, false, joe);
farm.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, state, pos);
boolean removed = false;
for (ItemStack stack : drops) {
if (world.rand.nextFloat() <= chance) {
if (!removed && stack.isItemEqual(getSeeds())) {
stack.shrink(1);
removed = true;
if (Prep.isValid(stack)) {
result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy()));
}
} else {
result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy()));
}
}
}
NNList.wrap(farm.endUsingItem(FarmingTool.HOE)).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
}
});
if (removed) {
if (!plant(farm, world, pos)) {
result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, getSeeds().copy()));
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 1 | 2);
}
} else {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 1 | 2);
}
return new HarvestResult(result, pos);
}
use of crazypants.enderio.api.farm.IHarvestResult in project EnderIO by SleepyTrousers.
the class PickableFarmer method harvestBlock.
@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull final BlockPos bc, @Nonnull Block block, @Nonnull IBlockState meta) {
if (!canHarvest(farm, bc, block, meta)) {
return null;
}
if (!farm.hasTool(FarmingTool.HOE)) {
farm.setNotification(FarmNotification.NO_HOE);
return null;
}
final HarvestResult result = new HarvestResult();
final World world = farm.getWorld();
EntityPlayerMP joe = farm.startUsingItem(FarmingTool.HOE);
joe.interactionManager.processRightClickBlock(joe, joe.world, joe.getHeldItemMainhand(), EnumHand.MAIN_HAND, bc, EnumFacing.DOWN, 0, 0, 0);
NNList.wrap(farm.endUsingItem(FarmingTool.HOE)).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
result.getDrops().add(new EntityItem(world, bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5, drop.copy()));
}
});
farm.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, meta, bc);
result.getHarvestedBlocks().add(bc);
return result;
}
use of crazypants.enderio.api.farm.IHarvestResult 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;
}
use of crazypants.enderio.api.farm.IHarvestResult in project EnderIO by SleepyTrousers.
the class NaturaBerryFarmer method harvestBlock.
@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull BlockPos bc, @Nonnull Block block, @Nonnull IBlockState meta) {
if (block != getPlantedBlock()) {
return null;
}
if (!farm.hasTool(FarmingTool.HOE)) {
farm.setNotification(FarmNotification.NO_HOE);
return null;
}
IHarvestResult res = new HarvestResult();
BlockPos checkBlock = bc;
while (checkBlock != null && checkBlock.getY() <= 255 && farm.hasTool(FarmingTool.HOE)) {
meta = farm.getBlockState(checkBlock);
block = meta.getBlock();
if (block != getPlantedBlock()) {
checkBlock = null;
} else {
if (getFullyGrownBlockMeta() == block.getMetaFromState(meta)) {
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
if (blockRes != null) {
res.getHarvestedBlocks().add(checkBlock);
res.getDrops().addAll(blockRes.getDrops());
}
}
checkBlock = checkBlock.up();
}
}
if (res.getHarvestedBlocks().isEmpty()) {
return null;
}
return res;
}
use of crazypants.enderio.api.farm.IHarvestResult in project EnderIO by SleepyTrousers.
the class TileFarmStation method executeHarvest.
private boolean executeHarvest(@Nonnull IFarmer farmer, @Nonnull BlockPos farmingPos, @Nonnull IBlockState bs, @Nonnull Block block) {
IHarvestResult harvest = Commune.instance.harvestBlock(farmer, farmingPos, block, bs);
if (harvest != null && (!harvest.getHarvestedBlocks().isEmpty() || !harvest.getDrops().isEmpty())) {
if (!harvest.getHarvestedBlocks().isEmpty()) {
PacketFarmAction pkt = new PacketFarmAction(harvest.getHarvestedBlocks());
PacketHandler.sendToAllAround(pkt, this);
}
NNList.wrap(harvest.getDrops()).apply(new Callback<EntityItem>() {
@Override
public void apply(@Nonnull EntityItem ei) {
if (!ei.isDead) {
ItemStack stack = ei.getItem();
if (Prep.isValid(stack)) {
getFarmer().handleExtraItem(stack, farmingPos);
}
ei.setDead();
}
}
});
return true;
}
return false;
}
Aggregations