当前位置: 首页>>代码示例>>Java>>正文


Java Effect类代码示例

本文整理汇总了Java中cn.nukkit.potion.Effect的典型用法代码示例。如果您正苦于以下问题:Java Effect类的具体用法?Java Effect怎么用?Java Effect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Effect类属于cn.nukkit.potion包,在下文中一共展示了Effect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initEntity

import cn.nukkit.potion.Effect; //导入依赖的package包/类
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();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:25,代码来源:Entity.java

示例2: attack

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public boolean attack(EntityDamageEvent source) {
    if (hasEffect(Effect.FIRE_RESISTANCE)
            && (source.getCause() == DamageCause.FIRE
            || source.getCause() == DamageCause.FIRE_TICK
            || source.getCause() == DamageCause.LAVA)) {
        return false;
    }

    getServer().getPluginManager().callEvent(source);
    if (source.isCancelled()) {
        return false;
    }
    if (this.absorption > 0) {  //Damage Absorption
        float absorptionHealth = this.absorption - source.getFinalDamage() > 0 ? source.getFinalDamage() : this.absorption;
        this.setAbsorption(this.absorption - absorptionHealth);
        source.setDamage(-absorptionHealth, EntityDamageEvent.DamageModifier.ABSORPTION);
    }
    setLastDamageCause(source);
    setHealth(getHealth() - source.getFinalDamage());
    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:Entity.java

示例3: getBreakTime

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public double getBreakTime(Item item, Player player) {
    Objects.requireNonNull(item, "getBreakTime: Item can not be null");
    Objects.requireNonNull(player, "getBreakTime: Player can not be null");
    double blockHardness = getHardness();
    boolean correctTool = correctTool0(getToolType(), item);
    boolean canHarvestWithHand = canHarvestWithHand();
    int blockId = getId();
    int itemToolType = toolType0(item);
    int itemTier = item.getTier();
    int efficiencyLoreLevel = Optional.ofNullable(item.getEnchantment(Enchantment.ID_EFFICIENCY))
            .map(Enchantment::getLevel).orElse(0);
    int hasteEffectLevel = Optional.ofNullable(player.getEffect(Effect.HASTE))
            .map(Effect::getAmplifier).orElse(0);
    boolean insideOfWaterWithoutAquaAffinity = player.isInsideOfWater() &&
            Optional.ofNullable(player.getInventory().getHelmet().getEnchantment(Enchantment.ID_WATER_WORKER))
                    .map(Enchantment::getLevel).map(l -> l >= 1).orElse(false);
    boolean outOfWaterButNotOnGround = (!player.isInsideOfWater()) && (!player.isOnGround());
    return breakTime0(blockHardness, correctTool, canHarvestWithHand, blockId, itemToolType, itemTier,
            efficiencyLoreLevel, hasteEffectLevel, insideOfWaterWithoutAquaAffinity, outOfWaterButNotOnGround);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:21,代码来源:Block.java

示例4: addEffect

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void addEffect(Effect effect) {
    if (effect == null) {
        return; //here add null means add nothing
    }

    Effect oldEffect = this.effects.getOrDefault(effect.getId(), null);
    if (oldEffect != null) {
        if (Math.abs(effect.getAmplifier()) < Math.abs(oldEffect.getAmplifier())) return;
        if (Math.abs(effect.getAmplifier()) == Math.abs(oldEffect.getAmplifier())
                && effect.getDuration() < oldEffect.getDuration()) return;
        effect.add(this, true);
    } else {
        effect.add(this, false);
    }

    this.effects.put(effect.getId(), effect);

    this.recalculateEffectColor();

    if (effect.getId() == Effect.HEALTH_BOOST) {
        this.setHealth(this.getHealth() + 4 * (effect.getAmplifier() + 1));
    }

}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:25,代码来源:Entity.java

示例5: fall

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void fall(float fallDistance) {
    float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));
    if (damage > 0) {
        this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage));
    }

    if (fallDistance > 0.75) {
        BlockVector3 v = new BlockVector3(getFloorX(), getFloorY() - 1, getFloorZ());
        int down = this.level.getBlockIdAt(v.x, v.y, v.z);

        if (down == Item.FARMLAND) {
            if (this instanceof Player) {
                Player p = (Player) this;
                PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), this.temporalVector.setComponents(v.x, v.y, v.z), null, Action.PHYSICAL);
                this.server.getPluginManager().callEvent(ev);
                if (ev.isCancelled()) {
                    return;
                }
            }
            this.level.setBlock(this.temporalVector.setComponents(v.x, v.y, v.z), new BlockDirt(), true, true);
        }
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:24,代码来源:Entity.java

示例6: attack

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public boolean attack(EntityDamageEvent source) {
    if (hasEffect(Effect.FIRE_RESISTANCE)
            && (source.getCause() == DamageCause.FIRE
            || source.getCause() == DamageCause.FIRE_TICK
            || source.getCause() == DamageCause.LAVA)) {
        return false;
    }

    getServer().getPluginManager().callEvent(source);
    if (source.isCancelled()) {
        return false;
    }
    setLastDamageCause(source);
    setHealth(getHealth() - source.getFinalDamage());
    return true;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:17,代码来源:Entity.java

示例7: fall

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void fall(float fallDistance) {
    float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));
    if (damage > 0) {
        this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage));
    }

    if (fallDistance > 0.75) {
        BlockVector3 v = new BlockVector3(getFloorX(), getFloorY() - 1, getFloorZ());
        int down = this.level.getBlockIdAt(v.x, v.y, v.z);

        if (down == Item.FARMLAND) {
            if (this instanceof Player) {
                Player p = (Player) this;
                PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), this.temporalVector.setComponents(v.x, v.y, v.z), null, PlayerInteractEvent.PHYSICAL);
                this.server.getPluginManager().callEvent(ev);
                if (ev.isCancelled()) {
                    return;
                }
            }
            this.level.setBlock(this.temporalVector.setComponents(v.x, v.y, v.z), new BlockDirt(), true, true);
        }
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:24,代码来源:Entity.java

示例8: initEntity

import cn.nukkit.potion.Effect; //导入依赖的package包/类
protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            int amplifier = e.getByte("Amplifier") & 0xff; // 0-255 only
            
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }

            effect.setAmplifier(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();
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:27,代码来源:Entity.java

示例9: fall

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void fall(float fallDistance) {
    float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));
    if (damage > 0) {
        this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage));
    }

    if (fallDistance > 0.75) {
        Block down = this.level.getBlock(this.floor().down());

        if (down.getId() == Item.FARMLAND) {
            if (this instanceof Player) {
                Player p = (Player) this;
                PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), down, null, Action.PHYSICAL);
                this.server.getPluginManager().callEvent(ev);
                if (ev.isCancelled()) {
                    return;
                }
            }
            this.level.setBlock(down, new BlockDirt(), true, true);
        }
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:23,代码来源:Entity.java

示例10: addEffect

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void addEffect(Effect effect) {
    if (effect == null) {
        return; //here add null means add nothing
    }

    Effect oldEffect = this.effects.getOrDefault(effect.getId(), null);
    if (oldEffect != null) {
        if (Math.abs(effect.getAmplifier()) < Math.abs(oldEffect.getAmplifier())) {
            return;
        }
        if (Math.abs(effect.getAmplifier()) == Math.abs(oldEffect.getAmplifier())
                && effect.getDuration() < oldEffect.getDuration()) {
            return;
        }
        effect.add(this, true);
    } else {
        effect.add(this, false);
    }

    this.effects.put(effect.getId(), effect);

    this.recalculateEffectColor();

    if (effect.getId() == Effect.HEALTH_BOOST) {
        this.setHealth(this.getHealth() + 4 * (effect.getAmplifier() + 1));
    }

}
 
开发者ID:Nukkit,项目名称:Nukkit,代码行数:29,代码来源:Entity.java

示例11: removeEffect

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void removeEffect(int effectId) {
    if (this.effects.containsKey(effectId)) {
        Effect effect = this.effects.get(effectId);
        this.effects.remove(effectId);
        effect.remove(this);

        this.recalculateEffectColor();
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:10,代码来源:Entity.java

示例12: recalculateEffectColor

import cn.nukkit.potion.Effect; //导入依赖的package包/类
protected void recalculateEffectColor() {
    int[] color = new int[3];
    int count = 0;
    boolean ambient = true;
    for (Effect effect : this.effects.values()) {
        if (effect.isVisible()) {
            int[] c = effect.getColor();
            color[0] += c[0] * (effect.getAmplifier() + 1);
            color[1] += c[1] * (effect.getAmplifier() + 1);
            color[2] += c[2] * (effect.getAmplifier() + 1);
            count += effect.getAmplifier() + 1;
            if (!effect.isAmbient()) {
                ambient = false;
            }
        }
    }

    if (count > 0) {
        int r = (color[0] / count) & 0xff;
        int g = (color[1] / count) & 0xff;
        int b = (color[2] / count) & 0xff;

        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, (r << 16) + (g << 8) + b));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, ambient ? 1 : 0));
    } else {
        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, 0));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, 0));
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:30,代码来源:Entity.java

示例13: sendPotionEffects

import cn.nukkit.potion.Effect; //导入依赖的package包/类
public void sendPotionEffects(Player player) {
    for (Effect effect : this.effects.values()) {
        MobEffectPacket pk = new MobEffectPacket();
        pk.eid = this.getId();
        pk.effectId = effect.getId();
        pk.amplifier = effect.getAmplifier();
        pk.particles = effect.isVisible();
        pk.duration = effect.getDuration();
        pk.eventId = MobEffectPacket.EVENT_ADD;

        player.dataPacket(pk);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:14,代码来源:Entity.java

示例14: onEatenBy

import cn.nukkit.potion.Effect; //导入依赖的package包/类
@Override
protected boolean onEatenBy(Player player) {
    super.onEatenBy(player);
    List<Effect> toApply = new LinkedList<>();
    effects.forEach((effect, chance) -> {
        if (chance >= Math.random()) toApply.add(effect.clone());
    });
    toApply.forEach(player::addEffect);
    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:11,代码来源:FoodEffective.java

示例15: doPostAttack

import cn.nukkit.potion.Effect; //导入依赖的package包/类
@Override
public void doPostAttack(Entity attacker, Entity entity) {
    if (entity instanceof EntityArthropod) {
        int duration = 20 + ThreadLocalRandom.current().nextInt(10 * this.level);
        entity.addEffect(Effect.getEffect(Effect.SLOWNESS).setDuration(duration).setAmplifier(3));
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:8,代码来源:EnchantmentDamageArthropods.java


注:本文中的cn.nukkit.potion.Effect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。