Java Code Examples for cn.nukkit.potion.Effect#getEffect()

The following examples show how to use cn.nukkit.potion.Effect#getEffect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
    }

    this.scheduleUpdate();
}
 
Example 2
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
    }

    this.scheduleUpdate();
}
 
Example 3
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));

            this.addEffect(effect);
        }
    }

    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
        if(this.namedTag.contains("CustomNameAlwaysVisible")){
            this.setNameTagAlwaysVisible(this.namedTag.getBoolean("CustomNameAlwaysVisible"));
        }
    }

    this.setDataFlag(DATA_FLAGS, DATA_FLAG_HAS_COLLISION, true);
    this.dataProperties.putFloat(DATA_BOUNDING_BOX_HEIGHT, this.getHeight());
    this.dataProperties.putFloat(DATA_BOUNDING_BOX_WIDTH, this.getWidth());
    this.dataProperties.putInt(DATA_HEALTH, (int) this.getHealth());

    this.scheduleUpdate();
}
 
Example 4
Source File: BlockEntityBeacon.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate() {
    //Only apply effects every 4 secs
    if (currentTick++ % 80 != 0) {
        return true;
    }

    int oldPowerLevel = this.getPowerLevel();
    //Get the power level based on the pyramid
    setPowerLevel(calculatePowerLevel());
    int newPowerLevel = this.getPowerLevel();

    //Skip beacons that do not have a pyramid or sky access
    if (newPowerLevel < 1 || !hasSkyAccess()) {
        if (oldPowerLevel > 0) {
            this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_DEACTIVATE);
        }
        return true;
    } else if (oldPowerLevel < 1) {
        this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_ACTIVATE);
    } else {
        this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_AMBIENT);
    }

    //Get all players in game
    Map<Long, Player> players = this.level.getPlayers();

    //Calculate vars for beacon power
    int range = 10 + getPowerLevel() * 10;
    int duration = 9 + getPowerLevel() * 2;

    for(Map.Entry<Long, Player> entry : players.entrySet()) {
        Player p = entry.getValue();

        //If the player is in range
        if (p.distance(this) < range) {
            Effect e;

            if (getPrimaryPower() != 0) {
                //Apply the primary power
                e = Effect.getEffect(getPrimaryPower());

                //Set duration
                e.setDuration(duration * 20);

                //If secondary is selected as the primary too, apply 2 amplification
                if (getSecondaryPower() == getPrimaryPower()) {
                    e.setAmplifier(2);
                } else {
                    e.setAmplifier(1);
                }

                //Hide particles
                e.setVisible(false);

                //Add the effect
                p.addEffect(e);
            }

            //If we have a secondary power as regen, apply it
            if (getSecondaryPower() == Effect.REGENERATION) {
                //Get the regen effect
                e = Effect.getEffect(Effect.REGENERATION);

                //Set duration
                e.setDuration(duration * 20);

                //Regen I
                e.setAmplifier(1);

                //Hide particles
                e.setVisible(false);

                //Add effect
                p.addEffect(e);
            }
        }
    }

    return true;
}