Search in sources :

Example 1 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project minecolonies by Minecolonies.

the class EntityAIWorkBeekeeper method decideWhatToDo.

/**
 * Decides what job the beekeeper should switch to, breeding or harvesting.
 *
 * @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
 */
private IAIState decideWhatToDo() {
    setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
    final Set<BlockPos> hives = getOwnBuilding().getHives();
    if (hives.isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
        setDelay(NO_HIVES_DELAY);
        return DECIDE;
    }
    ItemListModule flowersModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
    if (flowersModule.getList().isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
        setDelay(NO_FLOWERS_DELAY);
        return DECIDE;
    }
    for (BlockPos pos : hives) {
        if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
            getOwnBuilding().removeHive(pos);
        }
    }
    final Optional<BlockPos> hive = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
    if (hive.isPresent()) {
        return BEEKEEPER_HARVEST;
    }
    final List<BeeEntity> bees = new ArrayList<>(searchForAnimals(world, getOwnBuilding()));
    final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
    if (bees.isEmpty()) {
        if (getBeesInHives() <= 0) {
            job.tickNoBees();
            if (job.checkForBeeInteraction()) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
            }
        } else {
            job.resetCounter();
        }
        setDelay(NO_ANIMALS_DELAY);
        return DECIDE;
    } else {
        job.resetCounter();
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
    final int breedableAnimals = (int) bees.stream().filter(animal -> animal.getAge() == 0).count();
    final boolean hasBreedingItem = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> flowersModule.isItemInList(new ItemStorage(stack)));
    if (getOwnBuilding().getSetting(BuildingBeekeeper.BREEDING).getValue() && !hasMaxAnimals(bees) && breedableAnimals >= NUM_OF_ANIMALS_TO_BREED && hasBreedingItem) {
        return HERDER_BREED;
    }
    return START_WORKING;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) 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) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BeehiveBlock(net.minecraft.block.BeehiveBlock) ItemStorage(com.minecolonies.api.crafting.ItemStorage) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) BeeEntity(net.minecraft.entity.passive.BeeEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project Mekanism by mekanism.

the class ModuleShearingUnit method tryShearBlock.

// Slightly modified copy of BeehiveDispenseBehavior#tryShearBeehive modified to not crash if the tag has a block that isn't a
// beehive block instance in it, and also to support shearing pumpkins via the dispenser
private boolean tryShearBlock(IEnergyContainer energyContainer, ServerWorld world, BlockPos pos, Direction sideClicked) {
    if (energyContainer.getEnergy().greaterOrEqual(MekanismConfig.gear.mekaToolEnergyUsageShearBlock.get())) {
        BlockState state = world.getBlockState(pos);
        if (state.is(BlockTags.BEEHIVES) && state.getBlock() instanceof BeehiveBlock && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
            world.playSound(null, pos, SoundEvents.BEEHIVE_SHEAR, SoundCategory.BLOCKS, 1.0F, 1.0F);
            BeehiveBlock.dropHoneycomb(world, pos);
            ((BeehiveBlock) state.getBlock()).releaseBeesAndResetHoneyLevel(world, state, pos, null, BeehiveTileEntity.State.BEE_RELEASED);
            energyContainer.extract(MekanismConfig.gear.mekaToolEnergyUsageShearBlock.get(), Action.EXECUTE, AutomationType.MANUAL);
            return true;
        } else if (state.is(Blocks.PUMPKIN)) {
            // Carve pumpkin - copy from Pumpkin Block's onBlockActivated
            Direction side = sideClicked.getAxis() == Direction.Axis.Y ? Direction.NORTH : sideClicked;
            world.playSound(null, pos, SoundEvents.PUMPKIN_CARVE, SoundCategory.BLOCKS, 1, 1);
            world.setBlock(pos, Blocks.CARVED_PUMPKIN.defaultBlockState().setValue(CarvedPumpkinBlock.FACING, side), BlockFlags.DEFAULT_AND_RERENDER);
            Block.popResource(world, pos, new ItemStack(Items.PUMPKIN_SEEDS, 4));
            energyContainer.extract(MekanismConfig.gear.mekaToolEnergyUsageShearBlock.get(), Action.EXECUTE, AutomationType.MANUAL);
            return true;
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) ItemStack(net.minecraft.item.ItemStack) BeehiveBlock(net.minecraft.block.BeehiveBlock) Direction(net.minecraft.util.Direction)

Example 3 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project minecolonies by ldtteam.

the class EntityAIWorkBeekeeper method decideWhatToDo.

/**
 * Decides what job the beekeeper should switch to, breeding or harvesting.
 *
 * @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
 */
private IAIState decideWhatToDo() {
    setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
    final Set<BlockPos> hives = getOwnBuilding().getHives();
    if (hives.isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
        setDelay(NO_HIVES_DELAY);
        return DECIDE;
    }
    ItemListModule flowersModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
    if (flowersModule.getList().isEmpty()) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
        setDelay(NO_FLOWERS_DELAY);
        return DECIDE;
    }
    for (BlockPos pos : hives) {
        if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
            getOwnBuilding().removeHive(pos);
        }
    }
    final Optional<BlockPos> hive = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
    if (hive.isPresent()) {
        return BEEKEEPER_HARVEST;
    }
    final List<BeeEntity> bees = new ArrayList<>(searchForAnimals(world, getOwnBuilding()));
    final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
    if (bees.isEmpty()) {
        if (getBeesInHives() <= 0) {
            job.tickNoBees();
            if (job.checkForBeeInteraction()) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
            }
        } else {
            job.resetCounter();
        }
        setDelay(NO_ANIMALS_DELAY);
        return DECIDE;
    } else {
        job.resetCounter();
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
    final int breedableAnimals = (int) bees.stream().filter(animal -> animal.getAge() == 0).count();
    final boolean hasBreedingItem = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> flowersModule.isItemInList(new ItemStorage(stack)));
    if (getOwnBuilding().getSetting(BuildingBeekeeper.BREEDING).getValue() && !hasMaxAnimals(bees) && breedableAnimals >= NUM_OF_ANIMALS_TO_BREED && hasBreedingItem) {
        return HERDER_BREED;
    }
    return START_WORKING;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) 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) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BeehiveBlock(net.minecraft.block.BeehiveBlock) ItemStorage(com.minecolonies.api.crafting.ItemStorage) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) BeeEntity(net.minecraft.entity.passive.BeeEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project minecolonies by Minecolonies.

the class ItemScepterBeekeeper method useOn.

@Override
public ActionResultType useOn(final ItemUseContext useContext) {
    // if server world, do nothing
    if (useContext.getLevel().isClientSide) {
        return ActionResultType.FAIL;
    }
    final PlayerEntity player = useContext.getPlayer();
    final ItemStack scepter = useContext.getPlayer().getItemInHand(useContext.getHand());
    final CompoundNBT compound = scepter.getOrCreateTag();
    final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), useContext.getLevel());
    final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
    final IBuilding hut = colony.getBuildingManager().getBuilding(hutPos);
    final BuildingBeekeeper building = (BuildingBeekeeper) hut;
    if (useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock() instanceof BeehiveBlock) {
        final Collection<BlockPos> positions = building.getHives();
        final BlockPos pos = useContext.getClickedPos();
        if (positions.contains(pos)) {
            LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.removehive");
            building.removeHive(pos);
            SoundUtils.playSoundForPlayer((ServerPlayerEntity) player, SoundEvents.NOTE_BLOCK_BELL, (float) SoundUtils.VOLUME * 2, 0.5f);
        } else {
            if (positions.size() < building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.addhive");
                building.addHive(pos);
                SoundUtils.playSuccessSound(player, player.blockPosition());
            }
            if (positions.size() >= building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.maxhives");
                player.inventory.removeItemNoUpdate(player.inventory.selected);
            }
        }
    } else {
        player.inventory.removeItemNoUpdate(player.inventory.selected);
    }
    return super.useOn(useContext);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveBlock(net.minecraft.block.BeehiveBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 5 with BeehiveBlock

use of net.minecraft.block.BeehiveBlock in project Mekanism by mekanism.

the class ModuleShearingUnit method shearBeehive.

private ActionResultType shearBeehive(IEnergyContainer energyContainer, ItemUseContext context, BlockState state) {
    PlayerEntity player = context.getPlayer();
    if (player == null) {
        return ActionResultType.PASS;
    }
    if (state.is(BlockTags.BEEHIVES) && state.getBlock() instanceof BeehiveBlock && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
        // Act as shears on beehives
        World world = context.getLevel();
        BlockPos pos = context.getClickedPos();
        world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundCategory.NEUTRAL, 1, 1);
        BeehiveBlock.dropHoneycomb(world, pos);
        BeehiveBlock beehive = (BeehiveBlock) state.getBlock();
        if (CampfireBlock.isSmokeyPos(world, pos)) {
            beehive.resetHoneyLevel(world, state, pos);
        } else {
            if (beehive.hiveContainsBees(world, pos)) {
                beehive.angerNearbyBees(world, pos);
            }
            beehive.releaseBeesAndResetHoneyLevel(world, state, pos, player, BeehiveTileEntity.State.EMERGENCY);
        }
        if (!world.isClientSide) {
            energyContainer.extract(MekanismConfig.gear.mekaToolEnergyUsageShearBlock.get(), Action.EXECUTE, AutomationType.MANUAL);
        }
        return ActionResultType.sidedSuccess(world.isClientSide);
    }
    return ActionResultType.PASS;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) BeehiveBlock(net.minecraft.block.BeehiveBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

BeehiveBlock (net.minecraft.block.BeehiveBlock)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)5 BuildingBeekeeper (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 World (net.minecraft.world.World)3 TypeToken (com.google.common.reflect.TypeToken)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)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