Exemple #1
0
  public List<CollisionVolume> getCollidingObject(CollisionModel model) {
    // TODO Make this more general
    final int minX = MathHelper.floor(model.getPosition().getX());
    final int minY = MathHelper.floor(model.getPosition().getY());
    final int minZ = MathHelper.floor(model.getPosition().getZ());
    final int maxX = minX + 1;
    final int maxY = minY + 1;
    final int maxZ = minZ + 1;

    final LinkedList<CollisionVolume> colliding = new LinkedList<CollisionVolume>();

    final BoundingBox mutable = new BoundingBox(0, 0, 0, 0, 0, 0);
    final BoundingBox position = new BoundingBox((BoundingBox) model.getVolume());
    position.offset(minX, minY, minZ);

    for (int dx = minX; dx < maxX; dx++) {
      for (int dy = minY - 1; dy < maxY; dy++) {
        for (int dz = minZ; dz < maxZ; dz++) {
          BlockMaterial material = this.getBlockMaterial(dx, dy, dz);
          mutable.set((BoundingBox) material.getBoundingArea());
          mutable.offset(dx, dy, dz);
          if (mutable.intersects(position)) {
            colliding.add(mutable.clone());
          }
        }
      }
    }

    // TODO: colliding entities
    return colliding;
  }
Exemple #2
0
 @Override
 public Region getRegion(Point point, boolean load) {
   int x = MathHelper.floor(point.getX());
   int y = MathHelper.floor(point.getY());
   int z = MathHelper.floor(point.getZ());
   return regions.getRegionFromBlock(x, y, z, load);
 }
Exemple #3
0
 @Override
 public Block getBlock(Point point) {
   int x = MathHelper.floor(point.getX());
   int y = MathHelper.floor(point.getY());
   int z = MathHelper.floor(point.getZ());
   return getBlock(x, y, z);
 }
Exemple #4
0
 @Override
 public Chunk getChunk(Point point, boolean load) {
   int x = MathHelper.floor(point.getX());
   int y = MathHelper.floor(point.getY());
   int z = MathHelper.floor(point.getZ());
   return getChunk(
       x >> Chunk.CHUNK_SIZE_BITS, y >> Chunk.CHUNK_SIZE_BITS, z >> Chunk.CHUNK_SIZE_BITS, load);
 }
 @Override
 public Region getRegion() {
   // Check here to avoid the lookup
   if (entityManager != null && entityManager.getRegion() != null) {
     return entityManager.getRegion();
   }
   // Lookup
   World world = getWorld();
   if (world == null) {
     return null;
   } else {
     return world.getRegionFromBlock(
         MathHelper.floor(getPosition().getX()),
         MathHelper.floor(getPosition().getY()),
         MathHelper.floor(getPosition().getZ()));
   }
 }