Refactored Generation and class structure
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator;
|
||||
package eu.mhsl.minenet.minigames.world;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator;
|
||||
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import net.minestom.server.instance.generator.Generator;
|
||||
|
||||
public abstract class PlateTerrainGenerator implements Generator {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.featureEnriched;
|
||||
|
||||
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
||||
import eu.mhsl.minenet.minigames.util.SingleExecution;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.HeightTerrainGenerator;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.generator.GenerationUnit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CircularPlateGenerator extends HeightTerrainGenerator {
|
||||
private final SingleExecution execution = SingleExecution.make();
|
||||
private final int radius;
|
||||
private final int height;
|
||||
private BlockPallet blockPallet = BlockPallet.GROUND;
|
||||
|
||||
private int centerX = 0;
|
||||
private int centerZ = 0;
|
||||
|
||||
private boolean generated = false;
|
||||
|
||||
public CircularPlateGenerator(int radius, int height) {
|
||||
setCalculateHeight(point -> (int) ((point.distance(new Pos(0, point.y(), 0)) / 2) - radius));
|
||||
this.radius = radius;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public CircularPlateGenerator setBlockPallet(BlockPallet pallet) {
|
||||
this.blockPallet = pallet;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CircularPlateGenerator setCenter(int x, int z) {
|
||||
this.centerX = x;
|
||||
this.centerZ = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
execution.singleRun(() -> unit.fork(setter -> {
|
||||
System.out.println(new Pos(-(radius + centerX), unit.absoluteStart().y(), -(radius + centerZ)));
|
||||
System.out.println(new Pos(radius + centerX, height, radius + centerZ));
|
||||
GeneratorUtils.foreachXZ(
|
||||
new Pos(-(radius + centerX), unit.absoluteStart().y(), -(radius + centerZ)),
|
||||
new Pos(radius + centerX, height, radius + centerZ),
|
||||
point -> {
|
||||
double distance = point.distance(new Pos(centerX, point.y(), centerZ));
|
||||
|
||||
if(distance <= this.radius) {
|
||||
setter.setBlock(point.add(1, height, 1), Block.GOLD_BLOCK);
|
||||
}
|
||||
}
|
||||
);
|
||||
}));
|
||||
|
||||
super.generate(unit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.featureEnriched;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.HeightTerrainGenerator;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ValeGenerator extends HeightTerrainGenerator {
|
||||
private final JNoise curves = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.01)
|
||||
.build();
|
||||
|
||||
private final JNoise largeCurves = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.001)
|
||||
.build();
|
||||
|
||||
private Function<Integer, Double> xShiftMultiplier = multiplier -> 1d;
|
||||
|
||||
public ValeGenerator() {
|
||||
setCalculateHeight(this::calculateY);
|
||||
setHeightNoiseMultiplier(point -> (int) NumberUtil.map(calculateY(point), -64, 100, 0, 16));
|
||||
}
|
||||
|
||||
private int calculateY(Point point) {
|
||||
return (int) (Math.abs(point.blockX() - getXShiftAtZ(point.blockZ())) / 1.5);
|
||||
}
|
||||
|
||||
public int getXShiftAtZ(int z) {
|
||||
return (int) ((curves.getNoise(z) * 32 + largeCurves.getNoise(z) * 64) * xShiftMultiplier.apply(z));
|
||||
}
|
||||
|
||||
public void setXShiftMultiplier(Function<Integer, Double> xShiftMultiplier) {
|
||||
this.xShiftMultiplier = xShiftMultiplier;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.structures.generatable;
|
||||
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.Structure;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
@@ -13,6 +13,27 @@ public class Tree extends Structure {
|
||||
|
||||
@Override
|
||||
public void generateStructure(Block.Setter setter) {
|
||||
int trunkX = position.blockX();
|
||||
int trunkBottomY = position.blockY();
|
||||
int trunkZ = position.blockZ();
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
setter.setBlock(trunkX + 1, trunkBottomY + 3 + i, trunkZ, Block.OAK_LEAVES);
|
||||
setter.setBlock(trunkX - 1, trunkBottomY + 3 + i, trunkZ, Block.OAK_LEAVES);
|
||||
setter.setBlock(trunkX, trunkBottomY + 3 + i, trunkZ + 1, Block.OAK_LEAVES);
|
||||
setter.setBlock(trunkX, trunkBottomY + 3 + i, trunkZ - 1, Block.OAK_LEAVES);
|
||||
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
setter.setBlock(trunkX + x, trunkBottomY + 2 + i, trunkZ - z, Block.OAK_LEAVES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setter.setBlock(trunkX, trunkBottomY, trunkZ, Block.OAK_LOG);
|
||||
setter.setBlock(trunkX, trunkBottomY + 1, trunkZ, Block.OAK_LOG);
|
||||
setter.setBlock(trunkX, trunkBottomY + 2, trunkZ, Block.OAK_LOG);
|
||||
setter.setBlock(trunkX, trunkBottomY + 3, trunkZ, Block.OAK_LOG);
|
||||
setter.setBlock(trunkX, trunkBottomY + 4, trunkZ, Block.OAK_LEAVES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.Structure;
|
||||
import net.minestom.server.instance.generator.GenerationUnit;
|
||||
import net.minestom.server.instance.generator.Generator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseGenerator implements Generator {
|
||||
private final List<Structure> structures = new ArrayList<>();
|
||||
private final List<Generator> mixIns = new ArrayList<>();
|
||||
|
||||
public void addStructure(Structure structure) {
|
||||
this.structures.add(structure);
|
||||
}
|
||||
|
||||
public void addMixIn(Generator mixIn) {
|
||||
this.mixIns.add(mixIn);
|
||||
}
|
||||
|
||||
protected void applyStructures(GenerationUnit unit) {
|
||||
structures.forEach(structure -> unit.fork(structure::generateStructure));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
mixIns.forEach(generator -> generator.generate(unit));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
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.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.PlateTerrainGenerator;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.generatable.PeakRock;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
@@ -61,7 +61,7 @@ public class CircularPlateTerrainGenerator extends PlateTerrainGenerator {
|
||||
|
||||
synchronized (base) {
|
||||
double baseNoise = base.getNoise(bottom.x(), bottom.z());
|
||||
double currentHeight = minTwo(RangeMap.map(distance, 0, 400, -((double) this.size / 5), 200)) + baseNoise * 8;
|
||||
double currentHeight = minTwo(NumberUtil.map(distance, 0, 400, -((double) this.size / 5), 200)) + baseNoise * 8;
|
||||
|
||||
synchronized (batches) {
|
||||
double elementNoise = batches.getNoise(bottom.x(), bottom.z());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
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 FlatTerrainGenerator implements Generator {
|
||||
private final int height;
|
||||
private final Block block;
|
||||
|
||||
public FlatTerrainGenerator(int height, Block block) {
|
||||
this.height = height;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
FlatTerrainGenerator() {
|
||||
this.height = 5;
|
||||
this.block = Block.GRASS_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
unit.modifier().fillHeight(0, height, block);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
||||
import eu.mhsl.minenet.minigames.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class HeightTerrainGenerator extends BaseGenerator {
|
||||
protected final Random rnd = new Random();
|
||||
private Function<Point, Integer> calculateHeight = (Point) -> 0;
|
||||
protected Function<Point, Integer> heightNoiseMultiplier = (Point) -> 16;
|
||||
protected Function<Point, Integer> calculateSeaLevel = null;
|
||||
|
||||
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();
|
||||
|
||||
private final BlockPallet blockPallet = BlockPallet.STONE;
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
super.generate(unit);
|
||||
GeneratorUtils.foreachXZ(unit, bottomPoint -> {
|
||||
unit.modifier().setBlock(bottomPoint, blockPallet.rnd());
|
||||
|
||||
synchronized (base) {
|
||||
double heightNoise = base.getNoise(bottomPoint.x(), bottomPoint.z());
|
||||
double noiseModifier = heightNoise * heightNoiseMultiplier.apply(bottomPoint);
|
||||
double heightModifier = NumberUtil.clamp(calculateHeight.apply(bottomPoint) + noiseModifier, 1d, unit.size().y());
|
||||
if(heightModifier < 1) System.out.println("HEIGHT MODIFIER ILLEGAL");
|
||||
|
||||
synchronized (batches) {
|
||||
double batchNoise = batches.getNoise(bottomPoint.x(), bottomPoint.z());
|
||||
|
||||
unit.modifier().fill(bottomPoint, bottomPoint.add(1, heightModifier, 1), batchNoise < 0.9 ? batchNoise > 0 ? Block.GRASS_BLOCK : Block.SOUL_SAND : Block.STONE);
|
||||
|
||||
if(calculateSeaLevel != null) {
|
||||
Point absoluteHeight = bottomPoint.add(0, heightModifier, 0);
|
||||
int seaLevel = calculateSeaLevel.apply(bottomPoint);
|
||||
if(absoluteHeight.y() < seaLevel) {
|
||||
// System.out.println("HM:" + absoluteHeight.y() + " SL:" + seaLevel);
|
||||
// System.out.println("Filling from " + bottomPoint.y() + " to " + absoluteHeight.withY(seaLevel).y());
|
||||
unit.modifier().fill(bottomPoint.withY(v -> v+heightModifier), absoluteHeight.add(1, 0, 1).withY(seaLevel), Block.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (peaks) {
|
||||
double peakNoise = peaks.getNoise(bottomPoint.x(), bottomPoint.z());
|
||||
|
||||
if(peakNoise > 0.97 && bottomPoint.distance(new Pos(0, 0, 0)) > (50 + 20)) {
|
||||
|
||||
Point center = bottomPoint.add(1, heightModifier, 1);
|
||||
// unit.fork(setter -> new PeakRock(center, BlockPallet.STONE).generateStructure(setter));
|
||||
|
||||
// unit.fork(setter -> new Tree(center).generateStructure(setter));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setCalculateHeight(Function<Point, Integer> calculateHeight) {
|
||||
this.calculateHeight = calculateHeight;
|
||||
}
|
||||
|
||||
public void setHeightNoiseMultiplier(Function<Point, Integer> heightNoiseMultiplier) {
|
||||
this.heightNoiseMultiplier = heightNoiseMultiplier;
|
||||
}
|
||||
|
||||
public void setCalculateSeaLevel(@Nullable Function<Point, Integer> calculateSeaLevel) {
|
||||
this.calculateSeaLevel = calculateSeaLevel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.mhsl.minenet.minigames.world.generator.terrain;
|
||||
|
||||
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 PlaneTerrainGenerator implements Generator {
|
||||
private final int height;
|
||||
private final Block block;
|
||||
|
||||
public PlaneTerrainGenerator(int height, Block block) {
|
||||
this.height = height;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
PlaneTerrainGenerator() {
|
||||
this.height = 5;
|
||||
this.block = Block.GRASS_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
unit.modifier().fillHeight(height-1, height, block);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
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.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.PlateTerrainGenerator;
|
||||
import eu.mhsl.minenet.minigames.world.generator.structures.generatable.PeakRock;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
@@ -84,10 +84,10 @@ public class SquarePlateTerrainGenerator extends PlateTerrainGenerator {
|
||||
synchronized (base) {
|
||||
double baseNoise = base.getNoise(bottom.x(), bottom.z());
|
||||
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
|
||||
minTwo(NumberUtil.map(bottom.distance(new Pos(0, 0, 0)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
|
||||
minTwo(NumberUtil.map(bottom.distance(new Pos(width, 0, 0)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
|
||||
minTwo(NumberUtil.map(bottom.distance(new Pos(0, 0, length)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8,
|
||||
minTwo(NumberUtil.map(bottom.distance(new Pos(width, 0, length)), 0, 400, -((double) this.width / 5), 200)) + baseNoise * 8
|
||||
};
|
||||
|
||||
double currentHeight = Arrays.stream(possibleHeights).min().getAsDouble();
|
||||
|
||||
Reference in New Issue
Block a user