Polished TrafficLightRace

This commit is contained in:
2023-10-03 16:50:59 +02:00
parent 16cf29a590
commit b9b683dcde
11 changed files with 216 additions and 50 deletions

View File

@@ -11,6 +11,7 @@ public enum BlockPallet {
WOOD(new Block[] {Block.ACACIA_WOOD, Block.BIRCH_WOOD, Block.JUNGLE_WOOD, Block.OAK_WOOD, Block.DARK_OAK_WOOD, Block.SPRUCE_WOOD}),
STONE(new Block[] {Block.CHISELED_STONE_BRICKS, Block.STONE_BRICKS, Block.POLISHED_ANDESITE, Block.POLISHED_BLACKSTONE, Block.POLISHED_DIORITE}),
WINTER(new Block[] {Block.SNOW_BLOCK, Block.ICE, Block.PACKED_ICE, Block.BLUE_CONCRETE, Block.SEA_LANTERN}),
STREET(new Block[] {Block.BLACK_CONCRETE_POWDER, Block.GRAY_CONCRETE_POWDER, Block.GRAVEL, Block.BLACK_CONCRETE, Block.GRAY_CONCRETE}),
PRESSURE_PLATES(new Block[] {Block.ACACIA_PRESSURE_PLATE, Block.BIRCH_PRESSURE_PLATE, Block.CRIMSON_PRESSURE_PLATE, Block.JUNGLE_PRESSURE_PLATE, Block.OAK_PRESSURE_PLATE, Block.DARK_OAK_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.POLISHED_BLACKSTONE_PRESSURE_PLATE, Block.SPRUCE_PRESSURE_PLATE, Block.STONE_PRESSURE_PLATE, Block.WARPED_PRESSURE_PLATE});

View File

@@ -9,6 +9,7 @@ import net.minestom.server.coordinate.Pos;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.generator.GenerationUnit;
import net.minestom.server.instance.generator.Generator;
import net.minestom.server.world.DimensionType;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@@ -19,14 +20,25 @@ public class SquareTerrainGenerator implements Generator {
private final int width;
private final int length;
private int plateHeight = 0;
private boolean withBorder = false;
private final boolean generatePlate;
public SquareTerrainGenerator(int width, int length, boolean generatePlate) {
public SquareTerrainGenerator(int width, int length) {
this.width = width;
this.length = length;
this.generatePlate = generatePlate;
}
public SquareTerrainGenerator withPlate(int plateHeight) {
this.plateHeight = plateHeight;
return this;
}
public SquareTerrainGenerator withBorders() {
this.withBorder = true;
return this;
}
private final JNoise base = JNoise.newBuilder()
.fastSimplex()
.setSeed(rnd.nextLong())
@@ -59,22 +71,35 @@ public class SquareTerrainGenerator implements Generator {
for (int z = 0; z < unit.size().z(); z++) {
Point bottom = start.add(x, 0, z);
if(generatePlate) {
if(plateHeight > 0) {
if(bottom.x() <= width && bottom.x() >= 0 && bottom.z() <= length && bottom.z() >= 0) {
unit.modifier().fill(bottom, bottom.add(1, 50, 1), BlockPallet.GROUND.rnd());
unit.modifier().fill(bottom, bottom.add(1, plateHeight, 1), BlockPallet.GROUND.rnd());
continue;
}
}
if(withBorder) {
Runnable generateBorder = () -> unit.modifier().fill(bottom, bottom.add(1, DimensionType.OVERWORLD.getMaxY(), 1), Block.BARRIER);
if(bottom.z() <= length+1 && bottom.z() >= -1 && bottom.x() >= -1 && bottom.x() <= width+1) {
if(bottom.x() == -1 || bottom.x() == width+1) {
generateBorder.run();
}
if(bottom.z() == -1 || bottom.z() == length + 1) {
generateBorder.run();
}
}
}
unit.modifier().setBlock(bottom, Block.GRASS_BLOCK);
synchronized (base) {
double baseNoise = base.getNoise(bottom.x(), bottom.z());
double possibleHeights[] = {
minTwo(RangeMap.map(bottom.distance(new Pos(0, 0, 0)), 0, 400, -(this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(width, 0, 0)), 0, 400, -(this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(0, 0, length)), 0, 400, -(this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(width, 0, length)), 0, 400, -(this.width / 5), 200)) + baseNoise * 8
double[] possibleHeights = {
minTwo(RangeMap.map(bottom.distance(new Pos(0, 0, 0)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(width, 0, 0)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(0, 0, length)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
minTwo(RangeMap.map(bottom.distance(new Pos(width, 0, length)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8
};
double currentHeight = Arrays.stream(possibleHeights).min().getAsDouble();