Exemple #1
0
  protected static boolean damagePlayers(World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    for (Player player : etc.getServer().getPlayerList()) {
      Location pLoc = player.getLocation();
      Vector pVec = new Vector(pLoc.x, pLoc.y, pLoc.z);

      if (player.getWorld() == world
          && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
          && pVec.getBlockY() == y
          && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
        if (!id.isEmpty()) {
          if ((id.charAt(0) == 'g' && player.isInGroup(id.substring(2)))
              || (id.charAt(0) == 'p' && player.getName().equalsIgnoreCase(id.substring(2)))) {
            player.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        } else {
          player.getEntity().a(ODamageSource.j, damage);
          damaged = true;
        }
      }
    }

    return damaged;
  }
Exemple #2
0
 /**
  * Get the distance between a point and this cuboid.
  *
  * @param pos
  * @return
  */
 public double distance(Vector pos) {
   Vector max = origin.add(new Vector(width, height, length));
   int closestX = Math.max(origin.getBlockX(), Math.min(max.getBlockX(), pos.getBlockX()));
   int closestY = Math.max(origin.getBlockY(), Math.min(max.getBlockY(), pos.getBlockY()));
   int closestZ = Math.max(origin.getBlockZ(), Math.min(max.getBlockZ(), pos.getBlockZ()));
   return pos.distance(new Vector(closestX, closestY, closestZ));
 }
  /**
   * Adds a position to be used a source.
   *
   * @param pos
   * @return
   */
  public void addSingleSourcePosition(Vector pos) {
    int x = pos.getBlockX();
    int y = pos.getBlockY();
    int z = pos.getBlockZ();

    if (CraftBook.getBlockID(pos) == BlockType.CHEST) {
      ComplexBlock complexBlock = etc.getServer().getComplexBlock(x, y, z);

      if (complexBlock instanceof Chest) {
        Chest chest = (Chest) complexBlock;
        Item[] itemArray = chest.getContents();
        boolean occupied = false;

        // Got to make sure that at least one slot is occupied
        for (int i = 0; itemArray.length > i; i++) {
          if (itemArray[i] != null) {
            // Found an item
            if (itemArray[i].getAmount() > 0) {
              occupied = true;
              break;
            }
          }
        }

        if (occupied) {
          chests.add(new ComparableComplexBlock<Chest>(pos.toBlockVector(), chest));
        }
      }
    }
  }
Exemple #4
0
  /**
   * Do cauldron.
   *
   * @param pt
   * @param player
   */
  public void preCauldron(Vector pt, Player player) {
    int x = pt.getBlockX();
    int y = pt.getBlockY();
    int z = pt.getBlockZ();

    World world = player.getWorld();

    int rootY = y;
    int below = CraftBook.getBlockID(world, x, y - 1, z);
    int below2 = CraftBook.getBlockID(world, x, y - 2, z);
    int s1 = CraftBook.getBlockID(world, x + 1, y, z);
    int s3 = CraftBook.getBlockID(world, x - 1, y, z);
    int s2 = CraftBook.getBlockID(world, x, y, z + 1);
    int s4 = CraftBook.getBlockID(world, x, y, z - 1);

    // Preliminary check so we don't waste CPU cycles
    if ((BlockType.isLava(below) || BlockType.isLava(below2))
        && (s1 == BlockType.STONE
            || s2 == BlockType.STONE
            || s3 == BlockType.STONE
            || s4 == BlockType.STONE)) {
      // Cauldron is 2 units deep
      if (BlockType.isLava(below)) {
        rootY++;
      }

      performCauldron(new BlockVector(x, rootY, z), player);
    }
  }
Exemple #5
0
 /**
  * Construct the object. This is to create a new copy at a certain location.
  *
  * @param origin
  * @param size
  */
 public CuboidCopy(Vector origin, Vector size) {
   this.origin = origin;
   width = size.getBlockX();
   height = size.getBlockY();
   length = size.getBlockZ();
   blocks = new byte[width * height * length];
   data = new byte[width * height * length];
 }
Exemple #6
0
    @Override
    public void run() {
      @SuppressWarnings("rawtypes")
      List entities = null;

      try {
        switch (TYPE) {
          case 0:
            entities = etc.getServer().getPlayerList();
            break;
          case 1:
            entities = this.WORLD.getMobList();
            break;
          case 2:
            entities = this.WORLD.getAnimalList();
            break;
          case 3:
            entities = this.WORLD.getLivingEntityList();
            break;
          case 4:
            entities = entitiesExceptPlayers(this.WORLD.getWorld());
            break;
          case 5:
            entities = entitiesExceptPlayersItems(this.WORLD.getWorld());
            break;
        }
      } catch (ConcurrentModificationException e) {
        e.printStackTrace();
        return;
      }

      if (entities == null) return;

      boolean found = false;

      for (Object obj : entities) {
        BaseEntity entity = (BaseEntity) obj;
        if (entity.getWorld().getType().getId() != WORLD.getType().getId()) continue;

        double diffX = BLOCK.getBlockX() - entity.getX();
        double diffY = BLOCK.getBlockY() - entity.getY();
        double diffZ = BLOCK.getBlockZ() - entity.getZ();

        if (diffX * diffX + diffY * diffY + diffZ * diffZ < DISTANCE) {
          boolean result = entityInRange(entity);
          if (result) {
            found = true;
            if (DESTROY) {
              entity.destroy();
            } else {
              break;
            }
          }
        }
      }

      Redstone.setOutput(CraftBook.getCBWorld(WORLD), LEVER, found);
    }
Exemple #7
0
  @SuppressWarnings("rawtypes")
  protected static boolean damageEntities(
      List list, World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    boolean isNamed =
        !id.isEmpty()
            && !id.equalsIgnoreCase("animal")
            && !id.equalsIgnoreCase("animals")
            && !id.equalsIgnoreCase("mob")
            && !id.equalsIgnoreCase("mobs");

    for (Object obj : list) {
      BaseEntity entity = (BaseEntity) obj;
      if (entity != null
          && entity
              .getWorld()
              .isChunkLoaded((int) entity.getX(), (int) entity.getY(), (int) entity.getZ())
          && (entity.isMob() || entity.isAnimal())) {
        Vector pVec = new Vector(entity.getX(), entity.getY(), entity.getZ());

        if (entity.getWorld() == world
            && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
            && pVec.getBlockY() == y
            && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
          if (isNamed) {
            // Mob mob = (Mob)entity;
            if (entity.getName().equalsIgnoreCase(id)) {
              entity.getEntity().a(ODamageSource.j, damage);
              damaged = true;
            }
          } else {
            entity.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        }
      }
    }

    return damaged;
  }
Exemple #8
0
 /**
  * Save the copy to file.
  *
  * @param dest
  * @throws IOException
  */
 public void save(File dest) throws IOException {
   FileOutputStream out = new FileOutputStream(dest);
   DataOutputStream writer = new DataOutputStream(out);
   writer.writeByte(1);
   writer.writeInt(origin.getBlockX());
   writer.writeInt(origin.getBlockY());
   writer.writeInt(origin.getBlockZ());
   writer.writeInt(width);
   writer.writeInt(height);
   writer.writeInt(length);
   writer.write(blocks, 0, blocks.length);
   writer.write(data, 0, data.length);
   writer.close();
   out.close();
 }
Exemple #9
0
  static void setTrackTrigger(World world, Vector pos) {
    if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) {
      int data = CraftBook.getBlockData(world, pos);
      int newData = 0;
      boolean state = (data & 0x8) == 0x8;

      if (state) {
        newData = data & 0x7;
      } else {
        newData = data | 0x8;
      }

      CraftBook.setBlockData(world, pos, newData);
      world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData);
    }
  }
Exemple #10
0
  static void setOutput(World world, Vector pos, boolean state) {
    if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) {
      int data = CraftBook.getBlockData(world, pos);
      int newData = data & 0x7;

      if (!state) {
        newData = data & 0x7;
      } else {
        newData = data | 0x8;
      }

      if (newData != data) {
        CraftBook.setBlockData(world, pos, newData);
        world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData);
      }
    }
  }
Exemple #11
0
  static Boolean testAnyInput(
      World world, Vector pt, boolean checkWiresAbove, boolean checkOnlyHorizontal) {
    Boolean result = null;
    Boolean temp = null;

    int x = pt.getBlockX();
    int y = pt.getBlockY();
    int z = pt.getBlockZ();

    if (checkWiresAbove) {
      temp = testAnyInput(world, new Vector(x, y + 1, z), false, true);
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    if (!checkOnlyHorizontal) {
      // Check block above
      int above = CraftBook.getBlockID(world, x, y + 1, z);
      temp = Redstone.isHigh(world, new Vector(x, y + 1, z), above, true);
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    if (!checkOnlyHorizontal) {
      // Check block below
      int below = CraftBook.getBlockID(world, x, y - 1, z);
      temp = Redstone.isHigh(world, new Vector(x, y - 1, z), below, true);
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    int north = CraftBook.getBlockID(world, x - 1, y, z);
    int south = CraftBook.getBlockID(world, x + 1, y, z);
    int west = CraftBook.getBlockID(world, x, y, z + 1);
    int east = CraftBook.getBlockID(world, x, y, z - 1);

    // For wires that lead up to only this block
    if (north == BlockType.REDSTONE_WIRE) {
      temp =
          Redstone.isWireHigh(
              world,
              new Vector(x - 1, y, z),
              new Vector(x - 1, y, z - 1),
              new Vector(x - 1, y, z + 1));
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    if (south == BlockType.REDSTONE_WIRE) {
      temp =
          Redstone.isWireHigh(
              world,
              new Vector(x + 1, y, z),
              new Vector(x + 1, y, z - 1),
              new Vector(x + 1, y, z + 1));
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    if (west == BlockType.REDSTONE_WIRE) {
      temp =
          Redstone.isWireHigh(
              world,
              new Vector(x, y, z + 1),
              new Vector(x + 1, y, z + 1),
              new Vector(x - 1, y, z + 1));
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    if (east == BlockType.REDSTONE_WIRE) {
      temp =
          Redstone.isWireHigh(
              world,
              new Vector(x, y, z - 1),
              new Vector(x + 1, y, z - 1),
              new Vector(x - 1, y, z - 1));
      if (temp != null) {
        if (temp == true) {
          return true;
        } else {
          result = false;
        }
      }
    }

    // The sides of the block
    temp = Redstone.isHigh(world, new Vector(x - 1, y, z), north, false);
    if (temp != null) {
      if (temp == true) {
        return true;
      } else {
        result = false;
      }
    }

    temp = Redstone.isHigh(world, new Vector(x + 1, y, z), south, false);
    if (temp != null) {
      if (temp == true) {
        return true;
      } else {
        result = false;
      }
    }

    temp = Redstone.isHigh(world, new Vector(x, y, z + 1), west, false);
    if (temp != null) {
      if (temp == true) {
        return true;
      } else {
        result = false;
      }
    }

    temp = Redstone.isHigh(world, new Vector(x, y, z - 1), east, false);
    if (temp != null) {
      if (temp == true) {
        return true;
      } else {
        result = false;
      }
    }

    return result;
  }