Search in sources :

Example 1 with CompostParticleMessage

use of com.minecolonies.coremod.network.messages.client.CompostParticleMessage in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method shouldHarvest.

/**
 * Checks if the crop should be harvested.
 *
 * @param position the position to check.
 * @return true if should be harvested.
 */
private boolean shouldHarvest(@NotNull final BlockPos position) {
    BlockState state = world.getBlockState(position.above());
    Block block = state.getBlock();
    if (block == Blocks.PUMPKIN || block == Blocks.MELON) {
        return true;
    }
    if (isCrop(block)) {
        @NotNull CropsBlock crop = (CropsBlock) block;
        if (crop.isMaxAge(state)) {
            return true;
        }
        final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
        if (amountOfCompostInInv == 0) {
            return false;
        }
        if (InventoryUtils.shrinkItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost)) {
            Network.getNetwork().sendToPosition(new CompostParticleMessage(position.above()), new PacketDistributor.TargetPoint(position.getX(), position.getY(), position.getZ(), BLOCK_BREAK_SOUND_RANGE, world.dimension()));
            crop.growCrops(world, position.above(), state);
            state = world.getBlockState(position.above());
            block = state.getBlock();
            if (isCrop(block)) {
                crop = (CropsBlock) block;
            } else {
                return false;
            }
        }
        return crop.isMaxAge(state);
    }
    return false;
}
Also used : PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) NotNull(org.jetbrains.annotations.NotNull) CompostParticleMessage(com.minecolonies.coremod.network.messages.client.CompostParticleMessage)

Example 2 with CompostParticleMessage

use of com.minecolonies.coremod.network.messages.client.CompostParticleMessage in project minecolonies by ldtteam.

the class EntityAIWorkFarmer method shouldHarvest.

/**
 * Checks if the crop should be harvested.
 *
 * @param position the position to check.
 * @return true if should be harvested.
 */
private boolean shouldHarvest(@NotNull final BlockPos position) {
    BlockState state = world.getBlockState(position.above());
    Block block = state.getBlock();
    if (block == Blocks.PUMPKIN || block == Blocks.MELON) {
        return true;
    }
    if (isCrop(block)) {
        @NotNull CropsBlock crop = (CropsBlock) block;
        if (crop.isMaxAge(state)) {
            return true;
        }
        final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
        if (amountOfCompostInInv == 0) {
            return false;
        }
        if (InventoryUtils.shrinkItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost)) {
            Network.getNetwork().sendToPosition(new CompostParticleMessage(position.above()), new PacketDistributor.TargetPoint(position.getX(), position.getY(), position.getZ(), BLOCK_BREAK_SOUND_RANGE, world.dimension()));
            crop.growCrops(world, position.above(), state);
            state = world.getBlockState(position.above());
            block = state.getBlock();
            if (isCrop(block)) {
                crop = (CropsBlock) block;
            } else {
                return false;
            }
        }
        return crop.isMaxAge(state);
    }
    return false;
}
Also used : PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) NotNull(org.jetbrains.annotations.NotNull) CompostParticleMessage(com.minecolonies.coremod.network.messages.client.CompostParticleMessage)

Aggregations

CompostParticleMessage (com.minecolonies.coremod.network.messages.client.CompostParticleMessage)2 PacketDistributor (net.minecraftforge.fml.network.PacketDistributor)2 NotNull (org.jetbrains.annotations.NotNull)2