Example #1
0
  private void playOutExplosion(GlowPlayer player, Iterable<BlockVector> blocks) {
    Collection<ExplosionMessage.Record> records = new ArrayList<>();

    Location clientLoc = location.clone();
    clientLoc.setX((int) clientLoc.getX());
    clientLoc.setY((int) clientLoc.getY());
    clientLoc.setZ((int) clientLoc.getZ());

    for (BlockVector block : blocks) {
      byte x = (byte) (block.getBlockX() - clientLoc.getBlockX());
      byte y = (byte) (block.getBlockY() - clientLoc.getBlockY());
      byte z = (byte) (block.getBlockZ() - clientLoc.getBlockZ());
      records.add(new ExplosionMessage.Record(x, y, z));
    }

    Vector velocity = player.getVelocity();
    ExplosionMessage message =
        new ExplosionMessage(
            (float) location.getX(),
            (float) location.getY(),
            (float) location.getZ(),
            5,
            (float) velocity.getX(),
            (float) velocity.getY(),
            (float) velocity.getZ(),
            records);

    player.getSession().send(message);
  }
Example #2
0
 private Vector distanceToHead(LivingEntity entity) {
   return entity
       .getLocation()
       .clone()
       .subtract(location.clone().subtract(0, entity.getEyeHeight(), 0))
       .toVector();
 }
Example #3
0
  private void calculateRay(int ox, int oy, int oz, Collection<BlockVector> result) {
    double x = ox / 7.5 - 1;
    double y = oy / 7.5 - 1;
    double z = oz / 7.5 - 1;
    Vector direction = new Vector(x, y, z);
    direction.normalize();
    direction.multiply(0.3f); // 0.3 blocks away with each step

    Location current = location.clone();

    float currentPower = calculateStartPower();

    while (currentPower > 0) {
      GlowBlock block = world.getBlockAt(current);

      if (block.getType() != Material.AIR) {
        double blastDurability = getBlastDurability(block) / 5d;
        blastDurability += 0.3F;
        blastDurability *= 0.3F;
        currentPower -= blastDurability;

        if (currentPower > 0) {
          result.add(new BlockVector(block.getX(), block.getY(), block.getZ()));
        }
      }

      current.add(direction);
      currentPower -= 0.225f;
    }
  }
Example #4
0
  /**
   * Creates a new explosion
   *
   * @param source The entity causing this explosion
   * @param location The location this explosion is occuring at. Must contain a GlowWorld
   * @param power The power of the explosion
   * @param incendiary Whether or not blocks should be set on fire
   * @param breakBlocks Whether blocks should break through this explosion
   */
  public Explosion(
      Entity source, Location location, float power, boolean incendiary, boolean breakBlocks) {
    if (!(location.getWorld() instanceof GlowWorld)) {
      throw new IllegalArgumentException("Supplied location does not have a valid GlowWorld");
    }

    this.source = source;
    this.location = location.clone();
    this.power = power;
    this.incendiary = incendiary;
    this.breakBlocks = breakBlocks;
    this.world = (GlowWorld) location.getWorld();
  }
Example #5
0
 private double distanceTo(LivingEntity entity) {
   return location.clone().subtract(entity.getLocation()).length();
 }