Beispiel #1
0
 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) {
     EntityDamageEvent ev = new EntityDamageEvent(this, EntityDamageEvent.CAUSE_FALL, damage);
     this.attack(ev);
   }
 }
Beispiel #2
0
  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));
    }
  }
Beispiel #3
0
 public Vector2 getDirectionPlane() {
   return (new Vector2(
           (float) (-Math.cos(Math.toRadians(this.yaw) - Math.PI / 2)),
           (float) (-Math.sin(Math.toRadians(this.yaw) - Math.PI / 2))))
       .normalize();
 }
Beispiel #4
0
 public static byte[] subBytes(byte[] bytes, int start, int length) {
   int len = Math.min(bytes.length, start + length);
   return Arrays.copyOfRange(bytes, start, len);
 }