Example #1
0
 public void placeObject(int xx, int yy, int zz, WorldGeneratorObject object) {
   final Vector3 transformed = transform(xx, yy, zz);
   if (object.canPlaceObject(
       position.getWorld(),
       transformed.getFloorX(),
       transformed.getFloorY(),
       transformed.getFloorZ())) {
     object.placeObject(
         position.getWorld(),
         transformed.getFloorX(),
         transformed.getFloorY(),
         transformed.getFloorZ());
   }
 }
Example #2
0
 public void setBlockMaterial(int xx, int yy, int zz, BlockMaterial material, short data) {
   final Vector3 transformed = transform(xx, yy, zz);
   position
       .getWorld()
       .setBlockMaterial(
           transformed.getFloorX(),
           transformed.getFloorY(),
           transformed.getFloorZ(),
           material,
           data,
           null);
   if (material instanceof Directional) {
     final Directional directional = (Directional) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = directional.getFacing(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       directional.setFacing(
           block, BlockFace.fromYaw(face.getDirection().getYaw() + rotation.getYaw()));
     }
   } else if (material instanceof Attachable) {
     final Attachable attachable = (Attachable) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = attachable.getAttachedFace(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       attachable.setAttachedFace(
           block, BlockFace.fromYaw(face.getDirection().getYaw() + rotation.getYaw()), null);
     }
   }
 }
Example #3
0
 public BlockMaterial getBlockMaterial(int xx, int yy, int zz) {
   final Vector3 transformed = transform(xx, yy, zz);
   return position
       .getWorld()
       .getBlockMaterial(
           transformed.getFloorX(), transformed.getFloorY(), transformed.getFloorZ());
 }
Example #4
0
  @Override
  public boolean commitCuboid(CuboidBlockMaterialBuffer buffer, Cause<?> cause) {
    Vector3 base = buffer.getBase();
    int x = base.getFloorX();
    int y = base.getFloorY();
    int z = base.getFloorZ();
    SpoutChunk[][][] chunks = getChunks(x, y, z, buffer);

    return commitCuboid(chunks, buffer, cause);
  }
Example #5
0
 private static byte getOffsetHash(Vector3 offset) {
   offset = offset.normalize();
   offset = offset.round();
   int x = offset.getFloorX();
   int y = offset.getFloorY();
   int z = offset.getFloorZ();
   x += 1;
   y += 1;
   z += 1;
   return (byte) (x | y << 2 | z << 4);
 }
Example #6
0
 @Override
 public void queueChunkForGeneration(final Vector3 chunk) {
   final int rx = (chunk.getFloorX() >> Region.CHUNKS.BITS);
   final int ry = (chunk.getFloorY() >> Region.CHUNKS.BITS);
   final int rz = (chunk.getFloorZ() >> Region.CHUNKS.BITS);
   SpoutRegion region = getRegion(rx, ry, rz, LoadOption.NO_LOAD);
   if (region != null) {
     region.queueChunkForGeneration(chunk);
   } else {
     Spout.getScheduler()
         .scheduleSyncDelayedTask(
             this,
             new Runnable() {
               @Override
               public void run() {
                 SpoutRegion region = getRegion(rx, ry, rz, LoadOption.LOAD_GEN);
                 region.queueChunkForGeneration(chunk);
               }
             });
   }
 }
Example #7
0
  private SpoutChunk[][][] getChunks(int x, int y, int z, CuboidBlockMaterialBuffer buffer) {
    Vector3 size = buffer.getSize();

    int startX = x;
    int startY = y;
    int startZ = z;

    int endX = x + size.getFloorX();
    int endY = y + size.getFloorY();
    int endZ = z + size.getFloorZ();

    Chunk start = getChunkFromBlock(startX, startY, startZ);
    Chunk end = getChunkFromBlock(endX - 1, endY - 1, endZ - 1);

    int chunkStartX = start.getX();
    int chunkStartY = start.getY();
    int chunkStartZ = start.getZ();

    int chunkEndX = end.getX();
    int chunkEndY = end.getY();
    int chunkEndZ = end.getZ();

    int chunkSizeX = chunkEndX - chunkStartX + 1;
    int chunkSizeY = chunkEndY - chunkStartY + 1;
    int chunkSizeZ = chunkEndZ - chunkStartZ + 1;

    SpoutChunk[][][] chunks = new SpoutChunk[chunkSizeX][chunkSizeY][chunkSizeZ];
    for (int dx = chunkStartX; dx <= chunkEndX; dx++) {
      for (int dy = chunkStartY; dy <= chunkEndY; dy++) {
        for (int dz = chunkStartZ; dz <= chunkEndZ; dz++) {
          SpoutChunk chunk = getChunk(dx, dy, dz, LoadOption.LOAD_GEN);
          if (chunk == null) {
            throw new IllegalStateException("Null chunk loaded with LoadOption.LOAD_GEN");
          }
          chunks[dx - chunkStartX][dy - chunkStartY][dz - chunkStartZ] = chunk;
        }
      }
    }
    return chunks;
  }
Example #8
0
  protected boolean commitCuboid(
      SpoutChunk[][][] chunks, CuboidBlockMaterialBuffer buffer, Cause<?> cause) {

    Vector3 base = buffer.getBase();
    int x = base.getFloorX();
    int y = base.getFloorY();
    int z = base.getFloorZ();

    lockChunks(chunks);

    try {
      for (int dx = 0; dx < chunks.length; dx++) {
        SpoutChunk[][] subArray1 = chunks[dx];
        for (int dy = 0; dy < subArray1.length; dy++) {
          SpoutChunk[] subArray2 = subArray1[dy];
          for (int dz = 0; dz < subArray2.length; dz++) {
            if (!subArray2[dz].testCuboid(x, y, z, buffer)) {
              return false;
            }
          }
        }
      }

      // set
      for (int dx = 0; dx < chunks.length; dx++) {
        SpoutChunk[][] subArray1 = chunks[dx];
        for (int dy = 0; dy < subArray1.length; dy++) {
          SpoutChunk[] subArray2 = subArray1[dy];
          for (int dz = 0; dz < subArray2.length; dz++) {
            subArray2[dz].setCuboid(x, y, z, buffer, cause);
          }
        }
      }

      return true;
    } finally {
      unlockChunks(chunks);
    }
  }
Example #9
0
  /**
   * Updates the list of chunks around the player.
   *
   * @param force Forces the update
   * @return True if the list was changed
   */
  public boolean updateNearbyChunkMeshes(boolean force) {
    if (world == null) {
      world = client.getDefaultWorld();
      if (world != null)
        System.out.println("World updated to " + world.getName() + "-" + world.getUID());
    }

    if (world == null) {
      try {
        Thread.sleep(5);
      } catch (InterruptedException e) {
      }
      return false;
    }

    int chunkViewDistance = client.getActivePlayer().getViewDistance() / 16;

    Point currentPos = client.getActivePlayer().getTransform().getPosition();

    int currentChunkX = currentPos.getChunkX();
    int currentChunkY = currentPos.getChunkY();
    int currentChunkZ = currentPos.getChunkZ();

    if (currentChunkX == lastChunkX
        && currentChunkY == lastChunkY
        && currentChunkZ == lastChunkZ
        && !force
        && !firstUpdate) {
      return false;
    }
    // just add all visible chunks

    if (chunkRenderers.size() == 0 || force) {
      chunkRenderers.clear();

      int cubeMinX = currentChunkX - chunkViewDistance;
      int cubeMinY = currentChunkY - chunkViewDistance;
      int cubeMinZ = currentChunkZ - chunkViewDistance;

      int cubeMaxX = currentChunkX + chunkViewDistance;
      int cubeMaxY = currentChunkY + chunkViewDistance;
      int cubeMaxZ = currentChunkZ + chunkViewDistance;

      Vector3 batchMin =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMinX, cubeMinY, cubeMinZ));
      Vector3 batchMax =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMaxX, cubeMaxY, cubeMaxZ));

      for (int x = batchMin.getFloorX(); x <= batchMax.getFloorX(); x++) {
        for (int y = batchMin.getFloorY(); y <= batchMax.getFloorY(); y++) {
          for (int z = batchMin.getFloorZ(); z <= batchMax.getFloorZ(); z++) {
            Vector3 chunkCoords = ChunkMeshBatch.getChunkCoordinates(new Vector3(x, y, z));
            ChunkMeshBatch batch =
                new ChunkMeshBatch(
                    material,
                    world,
                    chunkCoords.getFloorX(),
                    chunkCoords.getFloorY(),
                    chunkCoords.getFloorZ());
            addChunkMeshBatch(batch);
            batch.update();

            System.out.println(batch);
          }
        }
      }
    } else {
      Cube oldView =
          new Cube(
              new Point(
                  world,
                  lastChunkX - chunkViewDistance,
                  lastChunkY - chunkViewDistance,
                  lastChunkZ - chunkViewDistance),
              chunkViewDistance * 2);
      Cube newView =
          new Cube(
              new Point(
                  world,
                  currentChunkX - chunkViewDistance,
                  currentChunkY - chunkViewDistance,
                  currentChunkZ - chunkViewDistance),
              chunkViewDistance * 2);

      Vector3 min = oldView.getBase().min(newView.getBase());
      Vector3 max =
          oldView.getBase().add(oldView.getSize()).max(newView.getBase().add(newView.getSize()));

      // Shared area
      Vector3 ignoreMin = oldView.getBase().max(newView.getBase());
      Vector3 ignoreMax =
          oldView.getBase().add(oldView.getSize()).min(newView.getBase().add(newView.getSize()));
      Cuboid ignore = new Cuboid(new Point(ignoreMin, world), ignoreMax.subtract(ignoreMin));

      for (int x = min.getFloorX(); x < max.getFloorX(); x++) {
        for (int y = min.getFloorY(); y < max.getFloorY(); y++) {
          for (int z = min.getFloorZ(); z < max.getFloorZ(); z++) {
            Vector3 vec = new Vector3(x, y, z);
            if (ignore.contains(vec)) {
              continue;
            }

            Vector3 pos = ChunkMeshBatch.getChunkCoordinates(vec);

            if (oldView.contains(vec)) {
              ChunkMeshBatch c =
                  chunkRenderersByPosition.get(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              removeChunkMeshBatch(c);
              continue;
            }

            if (newView.contains(vec)) {
              ChunkMeshBatch c =
                  new ChunkMeshBatch(
                      material, world, pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              addChunkMeshBatch(c);
              c.update();
            }
          }
        }
      }
    }

    firstUpdate = false;
    lastChunkX = currentChunkX;
    lastChunkY = currentChunkY;
    lastChunkZ = currentChunkZ;

    return true;
  }
Example #10
0
 @Override
 public SpoutChunk getChunkFromBlock(Vector3 position, LoadOption loadopt) {
   return this.getChunkFromBlock(
       position.getFloorX(), position.getFloorY(), position.getFloorZ(), loadopt);
 }
Example #11
0
 @Override
 public void getCuboid(CuboidBlockMaterialBuffer buffer) {
   Vector3 base = buffer.getBase();
   getCuboid(base.getFloorX(), base.getFloorY(), base.getFloorZ(), buffer);
 }
Example #12
0
 @Override
 public void setCuboid(CuboidBlockMaterialBuffer buffer, Cause<?> cause) {
   Vector3 base = buffer.getBase();
   setCuboid(base.getFloorX(), base.getFloorY(), base.getFloorZ(), buffer, cause);
 }
Example #13
0
 public void offsetPosition(Vector3 offset) {
   offsetPosition(offset.getFloorX(), offset.getFloorY(), offset.getFloorZ());
 }
Example #14
0
 @Override
 protected void generateTerrain(
     CuboidShortBuffer blockData, int x, int y, int z, BiomeManager biomes, long seed) {
   if (y >= HEIGHT) {
     return;
   }
   final Vector3 size = blockData.getSize();
   final int sizeX = size.getFloorX();
   final int sizeY = MathHelper.clamp(size.getFloorY(), 0, HEIGHT);
   final int sizeZ = size.getFloorZ();
   ELEVATION.setSeed((int) seed * 23);
   ROUGHNESS.setSeed((int) seed * 29);
   DETAIL.setSeed((int) seed * 17);
   TURBULENCE.setSeed((int) seed * 53);
   final Random random = WorldGeneratorUtils.getRandom(seed, x, y, z, 6516);
   final double[][][] noise =
       WorldGeneratorUtils.fastNoise(FINAL, sizeX, sizeY, sizeZ, 4, x, y, z);
   final BiomeSelector selector = getSelector();
   final TIntPairObjectHashMap<NormalBiome> biomeCache = new TIntPairObjectHashMap<NormalBiome>();
   for (int xx = 0; xx < sizeX; xx++) {
     for (int zz = 0; zz < sizeZ; zz++) {
       float maxSum = 0;
       float minSum = 0;
       byte count = 0;
       for (int sx = -SMOOTH_SIZE; sx <= SMOOTH_SIZE; sx++) {
         for (int sz = -SMOOTH_SIZE; sz <= SMOOTH_SIZE; sz++) {
           final NormalBiome adjacent;
           if (xx + sx < 0 || zz + sz < 0 || xx + sx >= sizeX || zz + sz >= sizeZ) {
             if (biomeCache.containsKey(x + xx + sx, z + zz + sz)) {
               adjacent = biomeCache.get(x + xx + sx, z + zz + sz);
             } else {
               adjacent = (NormalBiome) selector.pickBiome(x + xx + sx, y, z + zz + sz, seed);
               biomeCache.put(x + xx + sx, z + zz + sz, adjacent);
             }
           } else {
             adjacent = (NormalBiome) biomes.getBiome(xx + sx, y, zz + sz);
           }
           minSum += adjacent.getMin();
           maxSum += adjacent.getMax();
           count++;
         }
       }
       final double minElevation = minSum / count;
       final double smoothHeight = (maxSum / count - minElevation) / 2d;
       for (int yy = 0; yy < sizeY; yy++) {
         double noiseValue =
             noise[xx][yy][zz] - 1 / smoothHeight * (y + yy - smoothHeight - minElevation);
         if (noiseValue >= 0) {
           blockData.set(x + xx, y + yy, z + zz, VanillaMaterials.STONE.getId());
         } else {
           if (y + yy <= SEA_LEVEL) {
             if (y + yy == SEA_LEVEL
                 && ((NormalBiome) biomes.getBiome(xx, 0, zz)).getClimate() == Climate.COLD) {
               blockData.set(x + xx, y + yy, z + zz, VanillaMaterials.ICE.getId());
             } else {
               blockData.set(x + xx, y + yy, z + zz, VanillaMaterials.WATER.getId());
             }
           } else {
             blockData.set(x + xx, y + yy, z + zz, VanillaMaterials.AIR.getId());
           }
         }
       }
       if (y == 0) {
         final byte bedrockDepth = (byte) (random.nextInt(BEDROCK_DEPTH) + 1);
         for (byte yy = 0; yy < bedrockDepth; yy++) {
           blockData.set(x + xx, yy, z + zz, VanillaMaterials.BEDROCK.getId());
         }
       }
     }
   }
 }