Search in sources :

Example 16 with Bee

use of net.minecraft.world.entity.animal.Bee in project Bumblezone by TelepathicGrunt.

the class WrathOfTheHiveEffect method setAggression.

private static void setAggression(Level world, LivingEntity livingEntity, Class<? extends Mob> entityToFind, TargetingConditions sightMode, int speed, int absorption, int strength) {
    if (livingEntity instanceof Bee) {
        return;
    }
    boolean isHiding = false;
    MobEffectInstance hiddenEffect = livingEntity.getEffect(BzEffects.HIDDEN.get());
    if (hiddenEffect != null && hiddenEffect.getAmplifier() >= 1) {
        isHiding = true;
    }
    sightMode.range(BzBeeAggressionConfigs.aggressionTriggerRadius.get());
    List<? extends Mob> beeList = world.getNearbyEntities(entityToFind, sightMode, livingEntity, livingEntity.getBoundingBox().inflate(BzBeeAggressionConfigs.aggressionTriggerRadius.get()));
    for (Mob bee : beeList) {
        if (bee instanceof NeutralMob) {
            ((NeutralMob) bee).setRemainingPersistentAngerTime(20);
            ((NeutralMob) bee).setPersistentAngerTarget(livingEntity.getUUID());
        }
        if (isHiding) {
            bee.setTarget(null);
        } else {
            bee.setTarget(livingEntity);
            MobEffectInstance effect = livingEntity.getEffect(BzEffects.WRATH_OF_THE_HIVE.get());
            if (effect != null) {
                int leftoverDuration = effect.getDuration();
                bee.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, leftoverDuration, speed, false, false));
                bee.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, leftoverDuration, absorption, false, false));
                bee.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, leftoverDuration, strength, false, true));
            }
        }
    }
}
Also used : NeutralMob(net.minecraft.world.entity.NeutralMob) Mob(net.minecraft.world.entity.Mob) Bee(net.minecraft.world.entity.animal.Bee) NeutralMob(net.minecraft.world.entity.NeutralMob) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance)

Example 17 with Bee

use of net.minecraft.world.entity.animal.Bee in project Bumblezone by TelepathicGrunt.

the class WrathOfTheHiveEffect method applyEffectTick.

/**
 * Makes the bees swarm at the entity
 */
@Override
public void applyEffectTick(LivingEntity entity, int amplifier) {
    Level world = entity.level;
    // Maximum aggression
    if (amplifier >= 2) {
        unBEElievablyHighAggression(world, entity);
        if (GeneralUtils.getEntityCountInBz() < BzGeneralConfigs.broodBlocksBeeSpawnCapacity.get() * 3.0f) {
            // We don't want to spawn millions of bees
            if (!world.isClientSide() && world.random.nextFloat() <= 0.0045f) {
                // Grab a nearby air materialposition a bit away
                BlockPos spawnBlockPos = GeneralUtils.getRandomBlockposWithinRange(world, entity, 30, 10);
                if (world.getBlockState(spawnBlockPos).getMaterial() != Material.AIR) {
                    return;
                }
                Bee bee = EntityType.BEE.create(world);
                if (bee == null)
                    return;
                bee.absMoveTo(spawnBlockPos.getX() + 0.5D, spawnBlockPos.getY() + 0.5D, spawnBlockPos.getZ() + 0.5D, world.random.nextFloat() * 360.0F, 0.0F);
                bee.finalizeSpawn((ServerLevel) world, world.getCurrentDifficultyAt(spawnBlockPos), MobSpawnType.TRIGGERED, null, null);
                world.addFreshEntity(bee);
            }
        }
    } else // Anything lower than 2 is medium aggression
    {
        mediumAggression(world, entity);
    }
    // makes brood blocks grow faster near wrath of the hive entities.
    if (!world.isClientSide()) {
        PoiManager pointofinterestmanager = ((ServerLevel) world).getPoiManager();
        List<PoiRecord> poiInRange = pointofinterestmanager.getInSquare((pointOfInterestType) -> pointOfInterestType == BzPOI.BROOD_BLOCK_POI.get(), entity.blockPosition(), NEARBY_WRATH_EFFECT_RADIUS, PoiManager.Occupancy.ANY).collect(Collectors.toList());
        float chanceofGrowth = 0.001f;
        if (poiInRange.size() != 0) {
            for (int index = poiInRange.size() - 1; index >= 0; index--) {
                PoiRecord poi = poiInRange.remove(index);
                if (world.random.nextFloat() < chanceofGrowth) {
                    BlockState state = world.getBlockState(poi.getPos());
                    if (state.getBlock() instanceof HoneycombBrood) {
                        state.tick((ServerLevel) world, poi.getPos(), world.random);
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) EntityType(net.minecraft.world.entity.EntityType) BzBeeAggressionConfigs(com.telepathicgrunt.the_bumblezone.configs.BzBeeAggressionConfigs) MobSpawnType(net.minecraft.world.entity.MobSpawnType) BlockState(net.minecraft.world.level.block.state.BlockState) BeeAggression(com.telepathicgrunt.the_bumblezone.entities.BeeAggression) NeutralMob(net.minecraft.world.entity.NeutralMob) MobEffects(net.minecraft.world.effect.MobEffects) ServerLevel(net.minecraft.server.level.ServerLevel) PoiRecord(net.minecraft.world.entity.ai.village.poi.PoiRecord) HoneycombBrood(com.telepathicgrunt.the_bumblezone.blocks.HoneycombBrood) TargetingConditions(net.minecraft.world.entity.ai.targeting.TargetingConditions) AttributeMap(net.minecraft.world.entity.ai.attributes.AttributeMap) BzPOI(com.telepathicgrunt.the_bumblezone.modinit.BzPOI) BzEffects(com.telepathicgrunt.the_bumblezone.modinit.BzEffects) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) MobEffectCategory(net.minecraft.world.effect.MobEffectCategory) Collectors(java.util.stream.Collectors) Material(net.minecraft.world.level.material.Material) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) Bee(net.minecraft.world.entity.animal.Bee) BzGeneralConfigs(com.telepathicgrunt.the_bumblezone.configs.BzGeneralConfigs) Mob(net.minecraft.world.entity.Mob) Level(net.minecraft.world.level.Level) GeneralUtils(com.telepathicgrunt.the_bumblezone.utils.GeneralUtils) MobEffect(net.minecraft.world.effect.MobEffect) PoiManager(net.minecraft.world.entity.ai.village.poi.PoiManager) ServerLevel(net.minecraft.server.level.ServerLevel) HoneycombBrood(com.telepathicgrunt.the_bumblezone.blocks.HoneycombBrood) Bee(net.minecraft.world.entity.animal.Bee) BlockState(net.minecraft.world.level.block.state.BlockState) PoiRecord(net.minecraft.world.entity.ai.village.poi.PoiRecord) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) PoiManager(net.minecraft.world.entity.ai.village.poi.PoiManager)

Example 18 with Bee

use of net.minecraft.world.entity.animal.Bee in project AlexsMobs by Alex-the-666.

the class GrizzlyBearAIFleeBees method canUse.

public boolean canUse() {
    if (this.entity.isTame()) {
        return false;
    }
    if (this.entity.isSitting() && !entity.forcedSit) {
        this.entity.setOrderedToSit(false);
    }
    if (this.entity.isSitting()) {
        return false;
    }
    List<Bee> beeEntities = this.entity.level.getEntitiesOfClass(Bee.class, this.entity.getBoundingBox().inflate((double) avoidDistance, 8.0D, (double) avoidDistance), this.avoidTargetSelector);
    if (beeEntities.isEmpty()) {
        return false;
    } else {
        this.closestLivingEntity = beeEntities.get(0);
        Vec3 vec3d = LandRandomPos.getPosAway(this.entity, 16, 7, new Vec3(this.closestLivingEntity.getX(), this.closestLivingEntity.getY(), this.closestLivingEntity.getZ()));
        if (vec3d == null) {
            return false;
        } else if (this.closestLivingEntity.distanceToSqr(vec3d.x, vec3d.y, vec3d.z) < this.closestLivingEntity.distanceToSqr(this.entity)) {
            return false;
        } else {
            this.path = entity.getNavigation().createPath(new BlockPos(vec3d.x, vec3d.y, vec3d.z), 0);
            return this.path != null;
        }
    }
}
Also used : Bee(net.minecraft.world.entity.animal.Bee) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Example 19 with Bee

use of net.minecraft.world.entity.animal.Bee in project BYG by AOCAWOL.

the class BeeHiveFeature method place.

public boolean place(WorldGenLevel world, ChunkGenerator generator, Random rand, BlockPos pos, NoneFeatureConfiguration config) {
    if (world.isEmptyBlock(pos) && world.isEmptyBlock(pos.below())) {
        if (world.getBlockState(pos.above()).is(BlockTags.LEAVES) || world.getBlockState(pos.above()).is(BlockTags.LOGS) || world.getBlockState(pos.above()).is(BYGBlocks.EMBUR_GEL_BLOCK)) {
            Direction direction;
            if (world.isEmptyBlock(pos.north()))
                direction = Direction.NORTH;
            else if (world.isEmptyBlock(pos.south()))
                direction = Direction.SOUTH;
            else if (world.isEmptyBlock(pos.west()))
                direction = Direction.WEST;
            else
                direction = Direction.EAST;
            BlockState beeHiveState = Blocks.BEE_NEST.defaultBlockState().setValue(BeehiveBlock.FACING, direction);
            world.setBlock(pos, beeHiveState, 2);
            BlockEntity tileEntity = world.getBlockEntity(pos);
            if (tileEntity instanceof BeehiveBlockEntity) {
                BeehiveBlockEntity beehiveTileEntity = (BeehiveBlockEntity) tileEntity;
                int beeCount = rand.nextInt(4);
                for (int bee = 0; bee <= beeCount; bee++) {
                    Bee beeEntity = new Bee(EntityType.BEE, world.getLevel());
                    beehiveTileEntity.addOccupantWithPresetTicks(beeEntity, false, rand.nextInt(599));
                }
            }
            return true;
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Bee(net.minecraft.world.entity.animal.Bee) Direction(net.minecraft.core.Direction) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity)

Example 20 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class BeeBox method useOn.

@Override
@NotNull
public InteractionResult useOn(UseOnContext context) {
    Player player = context.getPlayer();
    if (player != null) {
        Level playerWorld = context.getPlayer().getCommandSenderWorld();
        ItemStack stack = context.getItemInHand();
        if (!context.getPlayer().isShiftKeyDown())
            return InteractionResult.FAIL;
        if (playerWorld.isClientSide() || !isFilled(stack))
            return InteractionResult.FAIL;
        Level worldIn = context.getLevel();
        BlockPos pos = context.getClickedPos();
        List<Entity> entities = getEntitiesFromStack(stack, worldIn, true);
        for (Entity entity : entities) {
            if (entity != null) {
                BlockPos blockPos = pos.relative(context.getClickedFace());
                entity.absMoveTo(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, 0, 0);
                worldIn.addFreshEntity(entity);
                if (entity instanceof Bee) {
                    Bee beeEntity = (Bee) entity;
                    BeeJar.resetBee(beeEntity);
                    BeeJar.setBeeAngry(beeEntity, player);
                }
            }
        }
        if (isTemp)
            stack.shrink(1);
        else
            stack.setTag(null);
        return InteractionResult.SUCCESS;
    }
    return InteractionResult.FAIL;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) Bee(net.minecraft.world.entity.animal.Bee) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Bee (net.minecraft.world.entity.animal.Bee)31 BlockPos (net.minecraft.core.BlockPos)12 ItemStack (net.minecraft.world.item.ItemStack)9 Entity (net.minecraft.world.entity.Entity)8 CompoundTag (net.minecraft.nbt.CompoundTag)6 Level (net.minecraft.world.level.Level)6 NotNull (org.jetbrains.annotations.NotNull)6 ICustomBee (com.teamresourceful.resourcefulbees.api.ICustomBee)5 LivingEntity (net.minecraft.world.entity.LivingEntity)5 Player (net.minecraft.world.entity.player.Player)5 AABB (net.minecraft.world.phys.AABB)5 ResourcefulBee (com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee)4 Direction (net.minecraft.core.Direction)4 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 CustomBeeEntity (com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity)3 List (java.util.List)3 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)3 Mob (net.minecraft.world.entity.Mob)3 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)3