Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public enum BlockPallet {
|
||||
GROUND(new Block[] {Block.GRAVEL, Block.STONE, Block.DIRT, Block.GRASS_BLOCK, Block.COARSE_DIRT, Block.ROOTED_DIRT}),
|
||||
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}),
|
||||
|
||||
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});
|
||||
|
||||
final List<Block> list;
|
||||
final Random rnd = new Random();
|
||||
|
||||
BlockPallet(Block[] blocks) {
|
||||
this.list = new ArrayList<>(List.of(blocks));
|
||||
}
|
||||
|
||||
public Block rnd() {
|
||||
return list.get(rnd.nextInt(list.size()));
|
||||
}
|
||||
|
||||
public boolean contains(Block b) {
|
||||
return list.contains(b);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.generator.GenerationUnit;
|
||||
import net.minestom.server.instance.generator.Generator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlaneGenerator implements Generator {
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
unit.modifier()
|
||||
.fillHeight(0, 5, Block.STONE);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.structures;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Structure {
|
||||
protected final Random rnd = new Random();
|
||||
|
||||
public abstract void generateGame(Block.Setter setter);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.structures.generatable;
|
||||
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.Structure;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
public class PeakRock extends Structure {
|
||||
private final Point position;
|
||||
public PeakRock(Point position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGame(Block.Setter setter) {
|
||||
for (int stoneX = -4; stoneX < 4; stoneX++) {
|
||||
for (int stoneZ = -4; stoneZ < 4; stoneZ++) {
|
||||
|
||||
double distanceToCenter = position.add(stoneX, 0, stoneZ).distance(position);
|
||||
if(distanceToCenter > 3) continue;
|
||||
|
||||
for (int stoneY = 0; stoneY < 10-(int) distanceToCenter * rnd.nextDouble(2, 5); stoneY++) {
|
||||
Point blockPos = position.add(stoneX, stoneY, stoneZ);
|
||||
setter.setBlock(blockPos, BlockPallet.STONE.rnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.util.RangeMap;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.generatable.PeakRock;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CircularTerrainGenerator implements Generator {
|
||||
protected final Random rnd = new Random();
|
||||
private final int size;
|
||||
|
||||
protected final Pos mapCenter = new Pos(0, 50, 0);
|
||||
|
||||
private boolean generatePlate;
|
||||
|
||||
public CircularTerrainGenerator(int size, boolean generatePlate) {
|
||||
this.size = size;
|
||||
this.generatePlate = generatePlate;
|
||||
}
|
||||
private final JNoise base = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.01)
|
||||
.build();
|
||||
|
||||
private final JNoise batches = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.05)
|
||||
.build();
|
||||
|
||||
private final JNoise peaks = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.1)
|
||||
.build();
|
||||
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
Point start = unit.absoluteStart().withY(0);
|
||||
|
||||
if(unit.absoluteStart().distance(new Pos(0, 0, 0)) > 500 + this.size) return;
|
||||
|
||||
for (int x = 0; x < unit.size().x(); x++) {
|
||||
for (int z = 0; z < unit.size().z(); z++) {
|
||||
Point bottom = start.add(x, 0, z);
|
||||
|
||||
double distance = bottom.distance(new Pos(0, 0, 0));
|
||||
|
||||
if(distance <= this.size && generatePlate) {
|
||||
unit.modifier().fill(bottom, bottom.add(1, 50, 1), BlockPallet.GROUND.rnd());
|
||||
continue;
|
||||
}
|
||||
|
||||
unit.modifier().setBlock(bottom, Block.GRASS_BLOCK);
|
||||
|
||||
synchronized (base) {
|
||||
double baseNoise = base.getNoise(bottom.x(), bottom.z());
|
||||
double currentHeight = minTwo(RangeMap.map(distance, 0, 400, -(this.size / 5), 200)) + baseNoise * 8;
|
||||
|
||||
synchronized (batches) {
|
||||
double elementNoise = batches.getNoise(bottom.x(), bottom.z());
|
||||
|
||||
unit.modifier().fill(
|
||||
bottom,
|
||||
bottom.add(1, 1, 1)
|
||||
.withY(currentHeight),
|
||||
elementNoise < 0.9 ? elementNoise > 0 ? Block.GRASS_BLOCK : Block.SOUL_SAND : Block.STONE
|
||||
);
|
||||
}
|
||||
|
||||
synchronized (peaks) {
|
||||
double peakNoise = peaks.getNoise(bottom.x(), bottom.z());
|
||||
|
||||
if(peakNoise > 0.97 && bottom.distance(new Pos(0, 0, 0)) > (this.size + 20)) {
|
||||
|
||||
Point center = bottom.add(1, currentHeight-3, 1);
|
||||
unit.fork(setter -> new PeakRock(center).generateGame(setter));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static double minTwo(double input) {
|
||||
if(input < 2) return 2;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.util.RangeMap;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.generatable.PeakRock;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SquareTerrainGenerator implements Generator {
|
||||
protected final Random rnd = new Random();
|
||||
|
||||
private int width;
|
||||
private int length;
|
||||
|
||||
private boolean generatePlate;
|
||||
|
||||
protected final Pos mapStart = new Pos(0, 50, 0);
|
||||
|
||||
public SquareTerrainGenerator(int width, int length, boolean generatePlate) {
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
this.generatePlate = generatePlate;
|
||||
}
|
||||
private final JNoise base = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.01)
|
||||
.build();
|
||||
|
||||
private final JNoise batches = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.05)
|
||||
.build();
|
||||
|
||||
private final JNoise peaks = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.1)
|
||||
.build();
|
||||
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
Point start = unit.absoluteStart().withY(0);
|
||||
|
||||
// don't generate more than 500 blocks outwards
|
||||
Point chunkStart = unit.absoluteStart();
|
||||
if(chunkStart.z() > length + 500 || chunkStart.z() < -500) return;
|
||||
if(chunkStart.x() < -500 || chunkStart.x() > width + 500) return;
|
||||
|
||||
for (int x = 0; x < unit.size().x(); x++) {
|
||||
for (int z = 0; z < unit.size().z(); z++) {
|
||||
Point bottom = start.add(x, 0, z);
|
||||
|
||||
double distance = bottom.distance(new Pos(0, 0, 0));
|
||||
|
||||
if(generatePlate) {
|
||||
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());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unit.modifier().setBlock(bottom, Block.GRASS_BLOCK);
|
||||
|
||||
synchronized (base) {
|
||||
double baseNoise = base.getNoise(bottom.x(), bottom.z());
|
||||
double currentHeight = minTwo(RangeMap.map(distance, 0, 400, -(this.width / 5), 200)) + baseNoise * 8;
|
||||
|
||||
synchronized (batches) {
|
||||
double elementNoise = batches.getNoise(bottom.x(), bottom.z());
|
||||
|
||||
unit.modifier().fill(
|
||||
bottom,
|
||||
bottom.add(1, 1, 1)
|
||||
.withY(currentHeight),
|
||||
elementNoise < 0.9 ? elementNoise > 0 ? Block.GRASS_BLOCK : Block.SOUL_SAND : Block.STONE
|
||||
);
|
||||
}
|
||||
|
||||
synchronized (peaks) {
|
||||
double peakNoise = peaks.getNoise(bottom.x(), bottom.z());
|
||||
|
||||
if(peakNoise > 0.97 && bottom.distance(new Pos(0, 0, 0)) > (this.width + 20)) {
|
||||
|
||||
Point center = bottom.add(1, currentHeight-3, 1);
|
||||
unit.fork(setter -> new PeakRock(center).generateGame(setter));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static double minTwo(double input) {
|
||||
if(input < 2) return 2;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user