Search in sources :

Example 1 with BeeEntity

use of net.minecraft.entity.passive.BeeEntity 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 BeeEntity

use of net.minecraft.entity.passive.BeeEntity in project Arclight by IzzelAliz.

the class BeehiveTileEntityMixin method arclight$beeEnterBlock.

@Inject(method = "tryEnterHive(Lnet/minecraft/entity/Entity;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;stopRiding()V"))
private void arclight$beeEnterBlock(Entity entity, boolean p_226962_2_, int p_226962_3_, CallbackInfo ci) {
    if (this.world != null) {
        EntityEnterBlockEvent event = new EntityEnterBlockEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(this.world, this.getPos()));
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            if (entity instanceof BeeEntity) {
                ((BeeEntity) entity).setStayOutOfHiveCountdown(400);
            }
            ci.cancel();
        }
    }
}
Also used : BeeEntity(net.minecraft.entity.passive.BeeEntity) EntityEnterBlockEvent(org.bukkit.event.entity.EntityEnterBlockEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with BeeEntity

use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.

the class BeeEntityMixin method tame.

@Override
protected void tame(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cbir) {
    ItemStack stack = player.getStackInHand(hand);
    boolean friend = beebuddy$getFriend().map(player.getUuid()::equals).orElse(false);
    if (!this.world.isClient) {
        if (stack.getItem() == Items.HONEY_BOTTLE) {
            if (friend && this.getHealth() < this.getMaxHealth()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                }
                this.heal(this.getMaxHealth());
                cbir.setReturnValue(ActionResult.SUCCESS);
            } else if (!friend && !beebuddy$hasFriend()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                    ItemStack g = new ItemStack(Items.GLASS_BOTTLE);
                    if (stack.isEmpty()) {
                        player.setStackInHand(hand, g);
                    } else if (!player.inventory.insertStack(g)) {
                        player.dropItem(g, false);
                    }
                }
                if (this.random.nextInt(4) == 0) {
                    beebuddy$setFriend(Optional.of(player.getUuid()));
                    if (player instanceof ServerPlayerEntity) {
                        ServerPlayerEntity p = (ServerPlayerEntity) player;
                        Criteria.TAME_ANIMAL.trigger(p, (BeeEntity) (Object) this);
                    }
                    beebuddy$friendify();
                    this.world.sendEntityStatus(this, (byte) 7);
                } else {
                    this.world.sendEntityStatus(this, (byte) 6);
                }
                cbir.setReturnValue(ActionResult.SUCCESS);
            }
        } else if (stack.getItem() instanceof NectarItem) {
            NectarItem n = (NectarItem) stack.getItem();
            if (friend || !beebuddy$hasFriend()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                }
                beebuddy$setNectarType(n.getType());
                cbir.setReturnValue(ActionResult.SUCCESS);
            }
        } else {
            beebuddy$setSitting(!beebuddy$isSitting());
            cbir.setReturnValue(ActionResult.SUCCESS);
        }
    } else if (friend || stack.getItem() == Items.HONEY_BOTTLE) {
        cbir.setReturnValue(ActionResult.CONSUME);
    } else if (stack.getItem() instanceof NectarItem) {
        cbir.setReturnValue(ActionResult.CONSUME);
    }
}
Also used : BeeEntity(net.minecraft.entity.passive.BeeEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) NectarItem(nomble.beebuddy.item.NectarItem) ItemStack(net.minecraft.item.ItemStack)

Example 4 with BeeEntity

use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.

the class BeeEntityMixin method doAceReproduction.

@Override
protected void doAceReproduction(PlayerEntity player, CallbackInfo cbi) {
    if (beebuddy$getNectarType().equals("ace")) {
        if (this.world instanceof ServerWorld) {
            BeeEntity us = (BeeEntity) (Object) this;
            us.breed((ServerWorld) this.world, us);
            us.setBaby(true);
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) BeeEntity(net.minecraft.entity.passive.BeeEntity)

Example 5 with BeeEntity

use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.

the class BeeEntityMixin method beebuddy$initTamedGoals.

@Unique
private void beebuddy$initTamedGoals() {
    BeeEntity us = (BeeEntity) (Object) this;
    this.goalSelector.add(0, new BeeSitGoal(us));
    this.goalSelector.add(1, StingGoalInvoker.beebuddy$make(us, us, 1.399999976158142D, true));
    this.goalSelector.add(2, new FollowParentGoal(us, 1.25D));
    this.goalSelector.add(3, new FollowFriendGoal(us));
    this.goalSelector.add(4, new AnimalMateGoal(us, 1.0D));
    if (pollinateGoal == null) {
        // we can be called before initGoals's body
        pollinateGoal = PollinateGoalInvoker.beebuddy$make(us);
    }
    this.goalSelector.add(5, pollinateGoal);
    if (moveToFlowerGoal == null) {
        moveToFlowerGoal = MoveToFlowerGoalInvoker.beebuddy$make(us);
    }
    this.goalSelector.add(6, moveToFlowerGoal);
    this.goalSelector.add(7, new SitOnHeadGoal(us));
    this.goalSelector.add(7, BeeWanderAroundGoalInvoker.beebuddy$make(us));
    this.goalSelector.add(8, new LookAtEntityGoal(us, PlayerEntity.class, 4.0F));
    this.goalSelector.add(8, new SwimGoal(us));
    BeeEntityMixin mix = this;
    this.targetSelector.add(1, (new RevengeGoal(this) {

        @Override
        public boolean canStart() {
            if (!super.canStart()) {
                return false;
            }
            if (us.getAttacker() != null) {
                UUID u = us.getAttacker().getUuid();
                return !u.equals(mix.beebuddy$getFriend());
            } else {
                return true;
            }
        }

        @Override
        public boolean shouldContinue() {
            return us.hasAngerTime() && super.shouldContinue();
        }
    }).setGroupRevenge(new Class[0]));
}
Also used : RevengeGoal(net.minecraft.entity.ai.goal.RevengeGoal) FollowParentGoal(net.minecraft.entity.ai.goal.FollowParentGoal) FollowFriendGoal(nomble.beebuddy.entity.ai.goal.FollowFriendGoal) LookAtEntityGoal(net.minecraft.entity.ai.goal.LookAtEntityGoal) SitOnHeadGoal(nomble.beebuddy.entity.ai.goal.SitOnHeadGoal) SwimGoal(net.minecraft.entity.ai.goal.SwimGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) AnimalMateGoal(net.minecraft.entity.ai.goal.AnimalMateGoal) BeeSitGoal(nomble.beebuddy.entity.ai.goal.BeeSitGoal) BeeEntity(net.minecraft.entity.passive.BeeEntity) UUID(java.util.UUID) Unique(org.spongepowered.asm.mixin.Unique)

Aggregations

BeeEntity (net.minecraft.entity.passive.BeeEntity)12 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 ItemStack (net.minecraft.item.ItemStack)5 TypeToken (com.google.common.reflect.TypeToken)4 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)4 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)4 Compatibility (com.minecolonies.api.compatibility.Compatibility)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 InventoryUtils (com.minecolonies.api.util.InventoryUtils)4 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)4 BUILDING_FLOWER_LIST (com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST)4 TICKS_SECOND (com.minecolonies.api.util.constant.Constants.TICKS_SECOND)4 TOOL_LEVEL_WOOD_OR_GOLD (com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD)4 ToolType (com.minecolonies.api.util.constant.ToolType)4 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)4 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)4