@Override public String toString() { return String.format("%1s (%2$dx%3$dx%4$d)", displayName, chunkDistance.getX(), chunkDistance.getY(), chunkDistance.getZ()); } }
/** * Filters based on a random noise * * @param noiseGen the noise generator that produces noise in [0..1] * @param density the threshold in [0..1] * @return true if the noise value is <b>below</b> the threshold */ public static Predicate<Vector3i> probability(final Noise noiseGen, final float density) { return input -> Math.abs(noiseGen.noise(input.getX(), input.getY(), input.getZ())) < density; }
/** * Filters based on the density * * @param density the density facet that contains all tested coords. * @return a predicate that returns true if (density ≥ 0) and (density < 0) for the block at (y - 1) */ public static Predicate<Vector3i> density(final DensityFacet density) { return input -> { // pass if the block on the surface is dense enough float densBelow = density.getWorld(input.getX(), input.getY() - 1, input.getZ()); float densThis = density.getWorld(input); return (densBelow >= 0 && densThis < 0); }; }
private static void generateMockChunkCubeWithSideWidthAround(final Vector3i position, final int sideWidth, final ChunkCache chunkCache) { for (int x = position.getX() - sideWidth; x <= position.getX() + sideWidth; x++) { for (int y = position.getY() - sideWidth; y <= position.getY() + sideWidth; y++) { for (int z = position.getZ() - sideWidth; z <= position.getZ() + sideWidth; z++) { if (x == position.getX() && y == position.getY() && z == position.getZ()) { //dont override the inner chunk continue; } chunkCache.put(new Vector3i(x, y, z), mockChunkAt(x, y, z)); } } } }
private Optional<Vector3f> findSpawnPos(Vector3f targetPos, float entityHeight) { int targetBlockX = TeraMath.floorToInt(targetPos.x); int targetBlockY = TeraMath.floorToInt(targetPos.y); int targetBlockZ = TeraMath.floorToInt(targetPos.z); Vector2i center = new Vector2i(targetBlockX, targetBlockZ); for (BaseVector2i pos : SpiralIterable.clockwise(center).maxRadius(32).scale(2).build()) { Vector3i testPos = new Vector3i(pos.getX(), targetBlockY, pos.getY()); Vector3i spawnPos = findOpenVerticalPosition(testPos, entityHeight); if (spawnPos != null) { return Optional.of(new Vector3f(spawnPos.getX(), spawnPos.getY() + entityHeight, spawnPos.getZ())); } } return Optional.empty(); }
@Override public boolean apply(Vector3i input) { int x = input.getX(); int z = input.getZ(); int level = input.getY() - 1; int min = level - divDown; int max = level + divUp; return inBounds(blockHeightAt(x - 1, z), min, max) && inBounds(blockHeightAt(x + 1, z), min, max) && inBounds(blockHeightAt(x, z - 1), min, max) && inBounds(blockHeightAt(x, z + 1), min, max); }