Search in sources :

Example 1 with GlowPotionEffect

use of net.glowstone.constants.GlowPotionEffect in project Glowstone by GlowstoneMC.

the class GlowLivingEntity method pulse.

// //////////////////////////////////////////////////////////////////////////
// Internals
@Override
public void pulse() {
    super.pulse();
    if (isDead()) {
        deathTicks++;
        if (deathTicks >= 20 && getClass() != GlowPlayer.class) {
            remove();
        }
    }
    // invulnerability
    if (noDamageTicks > 0) {
        --noDamageTicks;
    }
    Material mat = getEyeLocation().getBlock().getType();
    // breathing
    if (mat == Material.WATER) {
        // todo: flowing_water?
        if (canTakeDamage(DamageCause.DROWNING)) {
            --remainingAir;
            if (remainingAir <= -20) {
                remainingAir = 0;
                damage(1, DamageCause.DROWNING);
            }
        }
    } else {
        remainingAir = maximumAir;
    }
    if (isTouchingMaterial(Material.CACTUS)) {
        damage(1, DamageCause.CONTACT);
    }
    if (location.getY() < -64) {
        // no canTakeDamage call - pierces through game modes
        damage(4, DamageCause.VOID);
    }
    if (isWithinSolidBlock()) {
        damage(1, DamageCause.SUFFOCATION);
    }
    // fire and lava damage
    if (getLocation().getBlock().getType() == Material.FIRE) {
        damage(1, DamageCause.FIRE);
        // not applying additional fire ticks after dying in fire
        stoodInFire = !isDead();
    } else if (getLocation().getBlock().getType() == Material.LAVA) {
        damage(4, DamageCause.LAVA);
        if (swamInLava) {
            setFireTicks(getFireTicks() + 2);
        } else {
            setFireTicks(getFireTicks() + 300);
            swamInLava = true;
        }
    } else if (isTouchingMaterial(Material.FIRE) || isTouchingMaterial(Material.LAVA)) {
        damage(1, DamageCause.FIRE);
        // increment the ticks stood adjacent to fire or lava
        adjacentBurnTicks++;
        if (adjacentBurnTicks > 40) {
            stoodInFire = !isDead();
        }
    } else if (stoodInFire) {
        setFireTicks(getFireTicks() + 160);
        stoodInFire = false;
        adjacentBurnTicks = 0;
    } else {
        swamInLava = false;
        if (getLocation().getBlock().getType() == Material.WATER) {
            setFireTicks(0);
        }
    }
    // potion effects
    List<PotionEffect> effects = new ArrayList<>(potionEffects.values());
    for (PotionEffect effect : effects) {
        // pulse effect
        PotionEffectType type = effect.getType();
        GlowPotionEffect glowType = GlowPotionEffect.getEffect(type);
        if (glowType != null) {
            glowType.pulse(this, effect);
        }
        if (effect.getDuration() > 0) {
            // reduce duration on server-side. Don't need to be updated to client
            potionEffects.put(type, effect.withDuration(effect.getDuration() - 1));
        } else {
            // remove
            removePotionEffect(type);
        }
    }
    if (potionEffectsChanged) {
        updatePotionEffectsMetadata();
        potionEffectsChanged = false;
    }
    if (getFireTicks() > 0 && getFireTicks() % 20 == 0) {
        damage(1, DamageCause.FIRE_TICK);
    }
    GlowBlock under = (GlowBlock) getLocation().getBlock().getRelative(BlockFace.DOWN);
    BlockType type = ItemTable.instance().getBlock(under.getType());
    if (type != null) {
        type.onEntityStep(under, this);
    }
    nextAmbientTime--;
    if (!isDead() && getAmbientSound() != null && nextAmbientTime == 0 && !isSilent()) {
        double v = ThreadLocalRandom.current().nextDouble();
        if (v <= 0.2) {
            world.playSound(getLocation(), getAmbientSound(), getSoundVolume(), getSoundPitch());
        }
    }
    if (nextAmbientTime == 0) {
        nextAmbientTime = getAmbientDelay();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowPotionEffect(net.glowstone.constants.GlowPotionEffect) PotionEffect(org.bukkit.potion.PotionEffect) BlockType(net.glowstone.block.blocktype.BlockType) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) GlowPotionEffect(net.glowstone.constants.GlowPotionEffect) Material(org.bukkit.Material)

Aggregations

ArrayList (java.util.ArrayList)1 GlowBlock (net.glowstone.block.GlowBlock)1 BlockType (net.glowstone.block.blocktype.BlockType)1 GlowPotionEffect (net.glowstone.constants.GlowPotionEffect)1 Material (org.bukkit.Material)1 PotionEffect (org.bukkit.potion.PotionEffect)1 PotionEffectType (org.bukkit.potion.PotionEffectType)1