Search in sources :

Example 1 with BatEntity

use of net.minecraft.entity.passive.BatEntity in project AstralSorcery by HellFirePvP.

the class EntityFlare method tick.

@Override
public void tick() {
    super.tick();
    this.entityAge++;
    if (this.getEntityWorld().isRemote()) {
        this.tickClient();
    } else {
        if (this.isAmbient() && this.entityAge > 600 && rand.nextInt(600) == 0) {
            DamageUtil.attackEntityFrom(this, CommonProxy.DAMAGE_SOURCE_STELLAR, 1F);
        }
        if (this.isAlive()) {
            if (EntityConfig.CONFIG.flareAttackBats.get() && rand.nextInt(30) == 0) {
                BatEntity closest = EntityUtils.getClosestEntity(this.getEntityWorld(), BatEntity.class, this.getBoundingBox().grow(10), Vector3.atEntityCenter(this));
                if (closest != null) {
                    this.doLightningAttack(closest, 100F);
                }
            }
            if (EntityConfig.CONFIG.flareAttackPhantoms.get() && rand.nextInt(30) == 0) {
                PhantomEntity closest = EntityUtils.getClosestEntity(this.getEntityWorld(), PhantomEntity.class, this.getBoundingBox().grow(10), Vector3.atEntityCenter(this));
                if (closest != null) {
                    this.doLightningAttack(closest, 100F);
                }
            }
            if (this.isAmbient()) {
                boolean atTarget = this.currentMoveTarget == null || this.currentMoveTarget.distance(this) < 5.0;
                if (atTarget) {
                    this.currentMoveTarget = null;
                }
                if (this.currentMoveTarget == null && rand.nextInt(150) == 0) {
                    BlockPos newTarget = this.getPosition().add(rand.nextInt(RANDOM_WANDER_RANGE) * (rand.nextBoolean() ? 1 : -1), rand.nextInt(RANDOM_WANDER_RANGE) * (rand.nextBoolean() ? 1 : -1), rand.nextInt(RANDOM_WANDER_RANGE) * (rand.nextBoolean() ? 1 : -1));
                    if (newTarget.getY() > 1 && newTarget.getY() < 254 && new Vector3(newTarget).distance(this) >= 5.0) {
                        MiscUtils.executeWithChunk(this.getEntityWorld(), newTarget, () -> {
                            this.currentMoveTarget = new Vector3(newTarget);
                        });
                    }
                }
            } else if (this.getAttackTarget() != null) {
                if (!this.getAttackTarget().isAlive() || (this.getFollowingTarget() != null && this.getFollowingTarget().getDistance(this) > 30.0F)) {
                    this.setAttackTarget(null);
                } else {
                    Vector3 newTarget = Vector3.atEntityCenter(this.getAttackTarget()).addY(1.5F);
                    if (newTarget.getY() > 1 && newTarget.getY() < 254 && newTarget.distance(this) >= 3.0) {
                        this.currentMoveTarget = newTarget;
                    } else {
                        this.currentMoveTarget = null;
                    }
                }
            } else if (this.followingEntityId != -1) {
                LivingEntity following = this.getFollowingTarget();
                if (following == null) {
                    DamageUtil.attackEntityFrom(this, CommonProxy.DAMAGE_SOURCE_STELLAR, 1F);
                } else {
                    MantleEffectBootes effect = ItemMantle.getEffect(following, ConstellationsAS.bootes);
                    if (effect == null) {
                        DamageUtil.attackEntityFrom(this, CommonProxy.DAMAGE_SOURCE_STELLAR, 1F);
                        return;
                    }
                    if (this.getAttackTarget() != null && !this.getAttackTarget().isAlive()) {
                        this.setAttackTarget(null);
                    }
                    if (this.getAttackTarget() == null) {
                        Vector3 newTarget = Vector3.atEntityCenter(following).addY(2.5F);
                        if (newTarget.distance(this) >= 2.0) {
                            this.currentMoveTarget = newTarget;
                        } else {
                            this.currentMoveTarget = null;
                        }
                    }
                }
            } else {
                DamageUtil.attackEntityFrom(this, CommonProxy.DAMAGE_SOURCE_STELLAR, 1F);
                return;
            }
            LivingEntity target = this.getAttackTarget();
            if (target != null && target.isAlive() && target.getDistance(this) < 10 && rand.nextInt(40) == 0) {
                DamageUtil.shotgunAttack(target, e -> this.doLightningAttack(e, 2F + rand.nextFloat() * 2F));
            }
            this.doMovement();
        }
    }
}
Also used : MantleEffectBootes(hellfirepvp.astralsorcery.common.constellation.mantle.effect.MantleEffectBootes) PhantomEntity(net.minecraft.entity.monster.PhantomEntity) BatEntity(net.minecraft.entity.passive.BatEntity) BlockPos(net.minecraft.util.math.BlockPos) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3)

Example 2 with BatEntity

use of net.minecraft.entity.passive.BatEntity in project Wings by pau101.

the class ServerEventHandler method onPlayerEntityInteract.

@SubscribeEvent
public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event) {
    PlayerEntity player = event.getPlayer();
    Hand hand = event.getHand();
    ItemStack stack = player.getItemInHand(hand);
    if (event.getTarget() instanceof BatEntity && stack.getItem() == Items.GLASS_BOTTLE) {
        player.level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
        ItemStack destroyed = stack.copy();
        if (!player.abilities.instabuild) {
            stack.shrink(1);
        }
        player.awardStat(Stats.ITEM_USED.get(Items.GLASS_BOTTLE));
        ItemStack batBlood = new ItemStack(WingsItems.BAT_BLOOD_BOTTLE.get());
        if (stack.isEmpty()) {
            ForgeEventFactory.onPlayerDestroyItem(player, destroyed, hand);
            player.setItemInHand(hand, batBlood);
        } else if (!player.inventory.add(batBlood)) {
            player.drop(batBlood, false);
        }
        event.setCancellationResult(ActionResultType.SUCCESS);
    }
}
Also used : BatEntity(net.minecraft.entity.passive.BatEntity) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

BatEntity (net.minecraft.entity.passive.BatEntity)2 MantleEffectBootes (hellfirepvp.astralsorcery.common.constellation.mantle.effect.MantleEffectBootes)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 PhantomEntity (net.minecraft.entity.monster.PhantomEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 Hand (net.minecraft.util.Hand)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1