本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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));
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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();
}
示例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);
}
}
}
示例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));
}
}
示例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();
}
}
示例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));
}
}
示例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);
}
}
示例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;
}
示例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));
}
}