Пример #1
0
 @Override
 public ChunkViewCore getSubviewAroundChunk(Vector3i chunkPos) {
   Region3i region =
       Region3i.createFromCenterExtents(chunkPos, ChunkConstants.LOCAL_REGION_EXTENTS);
   if (getChunk(chunkPos) != null) {
     return createWorldView(
         region, new Vector3i(-region.min().x, -region.min().y, -region.min().z));
   }
   return null;
 }
Пример #2
0
/** @author Immortius */
@API
public final class ChunkConstants {
  public static final int SIZE_X = 32;
  public static final int SIZE_Y = 64;
  public static final int SIZE_Z = 32;

  public static final int INNER_CHUNK_POS_FILTER_X = TeraMath.ceilPowerOfTwo(SIZE_X) - 1;
  public static final int INNER_CHUNK_POS_FILTER_Y = TeraMath.ceilPowerOfTwo(SIZE_Y) - 1;
  public static final int INNER_CHUNK_POS_FILTER_Z = TeraMath.ceilPowerOfTwo(SIZE_Z) - 1;

  public static final int POWER_X = TeraMath.sizeOfPower(SIZE_X);
  public static final int POWER_Y = TeraMath.sizeOfPower(SIZE_Y);
  public static final int POWER_Z = TeraMath.sizeOfPower(SIZE_Z);

  public static final byte MAX_LIGHT = 0x0f;
  public static final byte MAX_SUNLIGHT = 0x0f;
  public static final byte MAX_SUNLIGHT_REGEN = 63;
  public static final byte SUNLIGHT_REGEN_THRESHOLD = 48;

  public static final Vector3i CHUNK_POWER = new Vector3i(POWER_X, POWER_Y, POWER_Z);
  public static final Vector3i CHUNK_SIZE = new Vector3i(SIZE_X, SIZE_Y, SIZE_Z);
  public static final Vector3i INNER_CHUNK_POS_FILTER =
      new Vector3i(INNER_CHUNK_POS_FILTER_X, INNER_CHUNK_POS_FILTER_Y, INNER_CHUNK_POS_FILTER_Z);
  public static final Region3i CHUNK_REGION =
      Region3i.createFromMinAndSize(Vector3i.zero(), CHUNK_SIZE);

  public static final Vector3i LOCAL_REGION_EXTENTS = new Vector3i(1, 1, 1);

  private ChunkConstants() {}
}
Пример #3
0
  @Test
  public void borderCalculation() {
    WorldBuilder worldBuilder = new WorldBuilder(12L);
    worldBuilder.addProvider(new Facet1Provider());
    worldBuilder.addProvider(new Facet2Provider());

    World world = worldBuilder.build();
    Region3i regionToGenerate = Region3i.createFromCenterExtents(new Vector3i(), 1);
    Region regionData = world.getWorldData(regionToGenerate);

    Facet1 facet1 = regionData.getFacet(Facet1.class);
    assertEquals(regionToGenerate, facet1.getWorldRegion());

    Facet2 facet2 = regionData.getFacet(Facet2.class);
    assertEquals(
        Region3i.createFromMinAndSize(new Vector3i(-3, -1, -3), new Vector3i(7, 3, 7)),
        facet2.getWorldRegion());
  }
Пример #4
0
 @Override
 public ChunkViewCore getLocalView(Vector3i centerChunkPos) {
   Region3i region =
       Region3i.createFromCenterExtents(centerChunkPos, ChunkConstants.LOCAL_REGION_EXTENTS);
   if (getChunk(centerChunkPos) != null) {
     return createWorldView(region, Vector3i.one());
   }
   return null;
 }
Пример #5
0
 private boolean makeChunkAvailable(final ReadyChunkInfo readyChunkInfo) {
   final Chunk chunk = nearCache.get(readyChunkInfo.getPos());
   if (chunk == null) {
     return false;
   }
   for (Vector3i pos : Region3i.createFromCenterExtents(readyChunkInfo.getPos(), 1)) {
     if (nearCache.get(pos) == null) {
       return false;
     }
   }
   lightMerger.beginMerge(chunk, readyChunkInfo);
   return true;
 }
Пример #6
0
 private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
   Chunk[] chunks = new Chunk[region.sizeX() * region.sizeY() * region.sizeZ()];
   for (Vector3i chunkPos : region) {
     Chunk chunk = nearCache.get(chunkPos);
     if (chunk == null || !chunk.isReady()) {
       return null;
     }
     chunkPos.sub(region.minX(), region.minY(), region.minZ());
     int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
     chunks[index] = chunk;
   }
   return new ChunkViewCoreImpl(
       chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
 }
Пример #7
0
 @Override
 public ChunkViewCore getSubviewAroundBlock(Vector3i blockPos, int extent) {
   Region3i region = ChunkMath.getChunkRegionAroundWorldPos(blockPos, extent);
   return createWorldView(region, new Vector3i(-region.min().x, -region.min().y, -region.min().z));
 }