Search in sources :

Example 91 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class EntityKoaBase method doHurtTarget.

/**
 * Copied from EntityMob
 */
@Override
public boolean doHurtTarget(Entity entityIn) {
    float damage = (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
    float knockback = (float) this.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
    if (entityIn instanceof LivingEntity) {
        damage += EnchantmentHelper.getDamageBonus(this.getMainHandItem(), ((LivingEntity) entityIn).getMobType());
        knockback += EnchantmentHelper.getKnockbackBonus(this);
    }
    boolean flag = entityIn.hurt(DamageSource.mobAttack(this), damage);
    if (flag) {
        if (knockback > 0 && entityIn instanceof LivingEntity) {
            ((LivingEntity) entityIn).knockback(knockback * 0.5F, Mth.sin(this.getYRot() * 0.017453292F), -Mth.cos(this.getYRot() * 0.017453292F));
            this.setDeltaMovement(this.getDeltaMovement().x * 0.6D, this.getDeltaMovement().y, this.getDeltaMovement().z * 0.6D);
        /*this.motionX *= 0.6D;
                this.motionZ *= 0.6D;*/
        }
        int j = EnchantmentHelper.getFireAspect(this);
        if (j > 0) {
            entityIn.setSecondsOnFire(j * 4);
        }
        if (entityIn instanceof Player) {
            Player entityplayer = (Player) entityIn;
            ItemStack itemstack = this.getMainHandItem();
            ItemStack itemstack1 = entityplayer.isUsingItem() ? entityplayer.getUseItem() : ItemStack.EMPTY;
            if (!itemstack.isEmpty() && !itemstack1.isEmpty() && itemstack.getItem() instanceof AxeItem && itemstack1.getItem() == Items.SHIELD) {
                float f1 = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;
                if (this.random.nextFloat() < f1) {
                    entityplayer.getCooldowns().addCooldown(Items.SHIELD, 100);
                    this.level.broadcastEntityEvent(entityplayer, (byte) 30);
                }
            }
        }
        this.doEnchantDamageEffects(this, entityIn);
    }
    return flag;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Player(net.minecraft.world.entity.player.Player) ItemStack(net.minecraft.world.item.ItemStack) AxeItem(net.minecraft.world.item.AxeItem)

Example 92 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class IguanaEntity method customServerAiStep.

@Override
protected void customServerAiStep() {
    AttributeInstance attribute = this.getAttribute(Attributes.MOVEMENT_SPEED);
    if (this.isAngry()) {
        if (!this.isBaby() && !attribute.hasModifier(ATTACK_SPEED_BOOST_MODIFIER)) {
            attribute.addTransientModifier(ATTACK_SPEED_BOOST_MODIFIER);
        }
        --this.angerLevel;
    } else if (attribute.hasModifier(ATTACK_SPEED_BOOST_MODIFIER)) {
        attribute.removeModifier(ATTACK_SPEED_BOOST_MODIFIER);
    }
    if (this.angerLevel > 0 && this.angerTargetUUID != null && this.getLastHurtByMob() == null) {
        Player entityplayer = this.level.getPlayerByUUID(this.angerTargetUUID);
        this.setLastHurtByMob(entityplayer);
        this.lastHurtByPlayer = entityplayer;
        this.lastHurtByPlayerTime = this.getLastHurtByMobTimestamp();
    }
    super.customServerAiStep();
}
Also used : Player(net.minecraft.world.entity.player.Player) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 93 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class IguanaEntity method readAdditionalSaveData.

@Override
public void readAdditionalSaveData(final CompoundTag compound) {
    super.readAdditionalSaveData(compound);
    angerLevel = compound.getShort("Anger");
    String hurtBy = compound.getString("HurtBy");
    if (!hurtBy.isEmpty()) {
        angerTargetUUID = UUID.fromString(hurtBy);
        final Player entityplayer = level.getPlayerByUUID(angerTargetUUID);
        setLastHurtByMob(entityplayer);
        if (entityplayer != null) {
            lastHurtByPlayer = entityplayer;
            lastHurtByPlayerTime = getLastHurtByMobTimestamp();
        }
    }
}
Also used : Player(net.minecraft.world.entity.player.Player)

Example 94 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class SharkEntity method tick.

@Override
public void tick() {
    super.tick();
    if (isBoss()) {
        // Set state to boss
        if (!hasSetBoss) {
            setBossTraits();
        }
        if (!level.isClientSide) {
            // Search for suitable target
            Player nearest = level.getNearestPlayer(this, 64D);
            if (nearest != null) {
                if (hasLineOfSight(nearest) && nearest.isInWater() && !nearest.isCreative() && nearest.isAlive()) {
                    aggressTarget = nearest;
                    setTargetHeading(aggressTarget.getX(), aggressTarget.getY() + 1, aggressTarget.getZ(), true);
                    // Show health bar to target player
                    if (nearest instanceof ServerPlayer) {
                        if (!bossInfo.getPlayers().contains(nearest)) {
                            bossTargets.add((ServerPlayer) nearest);
                            bossInfo.addPlayer((ServerPlayer) nearest);
                        }
                    }
                } else {
                    clearBossTargets();
                }
            } else {
                clearBossTargets();
            }
            // Heal if no target
            if (this.getHealth() < this.getMaxHealth() && this.tickCount % 80 == 0 && this.aggressTarget == null) {
                this.heal(1f);
                this.spawnAnim();
            }
            // Update health bar
            this.bossInfo.setProgress(this.rangeMap(this.getHealth(), 0, this.getMaxHealth(), 0, 1));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 95 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class BlowGunItem method getAmmo.

private static ItemStack getAmmo(LivingEntity entityIn, ItemStack stack) {
    final boolean isCreativeMode = entityIn instanceof Player && ((Player) entityIn).getAbilities().instabuild;
    final ItemStack ammo = entityIn.getProjectile(stack);
    if (isCreativeMode) {
        return getProjectile();
    }
    if (!ammo.isEmpty()) {
        return ammo;
    }
    return ItemStack.EMPTY;
}
Also used : Player(net.minecraft.world.entity.player.Player) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

Player (net.minecraft.world.entity.player.Player)97 ItemStack (net.minecraft.world.item.ItemStack)65 Level (net.minecraft.world.level.Level)56 InteractionHand (net.minecraft.world.InteractionHand)55 InteractionResult (net.minecraft.world.InteractionResult)52 ItemEntity (net.minecraft.world.entity.item.ItemEntity)51 Items (net.minecraft.world.item.Items)51 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)50 MyPet (de.Keyle.MyPet.api.entity.MyPet)50 InvocationTargetException (java.lang.reflect.InvocationTargetException)50 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)42 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)42 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)42 ServerLevel (net.minecraft.server.level.ServerLevel)40 Bukkit (org.bukkit.Bukkit)39 MyPetApi (de.Keyle.MyPet.MyPetApi)38 Util (de.Keyle.MyPet.api.Util)38 Pair (com.mojang.datafixers.util.Pair)36 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)36 Arrays (java.util.Arrays)36