Search in sources :

Example 1 with BeehiveTileEntity

use of net.minecraft.tileentity.BeehiveTileEntity in project minecolonies by Minecolonies.

the class EntityAIWorkBeekeeper method harvestHoney.

/**
 * Harvest honey/honeycomb from full beehives.
 *
 * @return The next {@link IAIState}.
 */
private IAIState harvestHoney() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_BEEKEEPER_HARVESTING));
    final List<BlockPos> hives = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).collect(Collectors.toList());
    if (hives.isEmpty()) {
        return DECIDE;
    }
    if (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) || (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.BOTH) && lastHarvestedBottle)) {
        if (!equipTool(Hand.MAIN_HAND, ToolType.SHEARS)) {
            return PREPARING;
        }
    } else {
        if (!equipItem(Hand.MAIN_HAND, new ItemStack(Items.GLASS_BOTTLE))) {
            return PREPARING;
        }
    }
    final BlockPos hive = hives.get(0);
    if (!world.getBlockState(hive).is(BlockTags.BEEHIVES)) {
        getOwnBuilding().removeHive(hive);
        return PREPARING;
    }
    if (walkToBlock(hive)) {
        return getState();
    }
    worker.swing(Hand.MAIN_HAND);
    final ItemStack itemStack = worker.getMainHandItem();
    if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEY) && ItemStackUtils.isTool(itemStack, ToolType.SHEARS)) {
        worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        for (ItemStack stackItem : Compatibility.getCombsFromHive(hive, world, getHoneycombsPerHarvest())) {
            InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(stackItem, worker.getItemHandlerCitizen());
        }
        world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
        worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
        lastHarvestedBottle = false;
    } else if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) && itemStack.getItem() == Items.GLASS_BOTTLE) {
        int i;
        for (i = 0; i < getHoneyBottlesPerHarvest() && !itemStack.isEmpty(); i++) {
            itemStack.shrink(1);
        }
        InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(new ItemStack(Items.HONEY_BOTTLE, i), worker.getItemHandlerCitizen());
        world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
        worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
        lastHarvestedBottle = true;
    }
    final int dex = getPrimarySkillLevel();
    if ((50 - (dex / 99. * 50.)) / 100 > worker.getRandom().nextDouble()) {
        final List<Entity> bees = ((BeehiveTileEntity) world.getBlockEntity(hive)).releaseAllOccupants(world.getBlockState(hive), BeehiveTileEntity.State.EMERGENCY);
        bees.stream().filter(entity -> entity instanceof BeeEntity).map(entity -> (BeeEntity) entity).filter(bee -> worker.position().distanceToSqr(bee.position()) <= 16.0D).forEach(bee -> {
            bee.setRemainingPersistentAngerTime(400 + worker.getRandom().nextInt(400));
            bee.setLastHurtByMob(worker);
        });
    }
    incrementActionsDoneAndDecSaturation();
    return START_WORKING;
}
Also used : BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Entity(net.minecraft.entity.Entity) BeeEntity(net.minecraft.entity.passive.BeeEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity)

Example 2 with BeehiveTileEntity

use of net.minecraft.tileentity.BeehiveTileEntity in project minecolonies by ldtteam.

the class EntityAIWorkBeekeeper method harvestHoney.

/**
 * Harvest honey/honeycomb from full beehives.
 *
 * @return The next {@link IAIState}.
 */
private IAIState harvestHoney() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_BEEKEEPER_HARVESTING));
    final List<BlockPos> hives = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).collect(Collectors.toList());
    if (hives.isEmpty()) {
        return DECIDE;
    }
    if (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) || (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.BOTH) && lastHarvestedBottle)) {
        if (!equipTool(Hand.MAIN_HAND, ToolType.SHEARS)) {
            return PREPARING;
        }
    } else {
        if (!equipItem(Hand.MAIN_HAND, new ItemStack(Items.GLASS_BOTTLE))) {
            return PREPARING;
        }
    }
    final BlockPos hive = hives.get(0);
    if (!world.getBlockState(hive).is(BlockTags.BEEHIVES)) {
        getOwnBuilding().removeHive(hive);
        return PREPARING;
    }
    if (walkToBlock(hive)) {
        return getState();
    }
    worker.swing(Hand.MAIN_HAND);
    final ItemStack itemStack = worker.getMainHandItem();
    if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEY) && ItemStackUtils.isTool(itemStack, ToolType.SHEARS)) {
        worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        for (ItemStack stackItem : Compatibility.getCombsFromHive(hive, world, getHoneycombsPerHarvest())) {
            InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(stackItem, worker.getItemHandlerCitizen());
        }
        world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
        worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
        lastHarvestedBottle = false;
    } else if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) && itemStack.getItem() == Items.GLASS_BOTTLE) {
        int i;
        for (i = 0; i < getHoneyBottlesPerHarvest() && !itemStack.isEmpty(); i++) {
            itemStack.shrink(1);
        }
        InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(new ItemStack(Items.HONEY_BOTTLE, i), worker.getItemHandlerCitizen());
        world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
        worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
        lastHarvestedBottle = true;
    }
    final int dex = getPrimarySkillLevel();
    if ((50 - (dex / 99. * 50.)) / 100 > worker.getRandom().nextDouble()) {
        final List<Entity> bees = ((BeehiveTileEntity) world.getBlockEntity(hive)).releaseAllOccupants(world.getBlockState(hive), BeehiveTileEntity.State.EMERGENCY);
        bees.stream().filter(entity -> entity instanceof BeeEntity).map(entity -> (BeeEntity) entity).filter(bee -> worker.position().distanceToSqr(bee.position()) <= 16.0D).forEach(bee -> {
            bee.setRemainingPersistentAngerTime(400 + worker.getRandom().nextInt(400));
            bee.setLastHurtByMob(worker);
        });
    }
    incrementActionsDoneAndDecSaturation();
    return START_WORKING;
}
Also used : BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Entity(net.minecraft.entity.Entity) BeeEntity(net.minecraft.entity.passive.BeeEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)2 Compatibility (com.minecolonies.api.compatibility.Compatibility)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)2 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)2 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 BUILDING_FLOWER_LIST (com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST)2 TICKS_SECOND (com.minecolonies.api.util.constant.Constants.TICKS_SECOND)2 TOOL_LEVEL_WOOD_OR_GOLD (com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD)2 ToolType (com.minecolonies.api.util.constant.ToolType)2 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)2 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)2 BuildingBeekeeper (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper)2 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)2 JobBeekeeper (com.minecolonies.coremod.colony.jobs.JobBeekeeper)2 AbstractEntityAIInteract (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract)2