DFS instantiation in biome generator is now correct.
Performed refactoring Began work on world height shader (untested).
This commit is contained in:
parent
e2c3e46849
commit
6d552820ee
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Launch) - Current File",
|
||||
"request": "launch",
|
||||
"mainClass": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Attach)",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 25566
|
||||
}
|
||||
]
|
||||
}
|
4
pom.xml
4
pom.xml
@ -41,7 +41,7 @@
|
||||
</build>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
@ -4,7 +4,6 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.world.IslandSurvivalCraftChunkGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.IslandWorldGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.BiomePerIslandGenerator;
|
||||
|
||||
public class IslandSurvivalCraft extends JavaPlugin {
|
||||
|
@ -6,6 +6,8 @@ import java.util.Objects;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.apache.commons.lang.NullArgumentException;
|
||||
|
||||
public class DepthFirstSearch {
|
||||
private Queue<Node> queue;
|
||||
private CoordinateValidatable validatable;
|
||||
@ -48,6 +50,9 @@ public class DepthFirstSearch {
|
||||
}
|
||||
|
||||
public boolean buildPathToEndNode() {
|
||||
if (validatable == null) throw new IllegalStateException("Need to set a validator.");
|
||||
if (startNode == null) throw new IllegalStateException("Need to set the starting position.");
|
||||
|
||||
queue = new PriorityQueue<>();
|
||||
checkedNodes.clear();
|
||||
Node begin = startNode;
|
||||
@ -83,6 +88,10 @@ public class DepthFirstSearch {
|
||||
* @return
|
||||
*/
|
||||
public boolean findTarget(CoordinateTargetValidatable targetValidator) {
|
||||
if (validatable == null) throw new IllegalStateException("Need to set a validator.");
|
||||
if (targetValidator == null) throw new NullArgumentException("targetValidator");
|
||||
if (startNode == null) throw new IllegalStateException("Need to set the starting position.");
|
||||
|
||||
queue = new LinkedList<>();
|
||||
checkedNodes.clear();
|
||||
Node begin = startNode;
|
||||
@ -128,6 +137,7 @@ public class DepthFirstSearch {
|
||||
return Math.round(distanceToGoal(endNode) - o.distanceToGoal(endNode));
|
||||
}
|
||||
|
||||
|
||||
public float distanceToGoal(Node goal) {
|
||||
float distanceX = goal.x - this.x;
|
||||
float distanceY = goal.y - this.y;
|
||||
|
@ -4,11 +4,13 @@ import java.util.Random;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.BedrockGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.IslandBiomeGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.shaders.WorldHeightShader;
|
||||
|
||||
/**
|
||||
* A world generator.
|
||||
@ -18,31 +20,45 @@ public class IslandWorldGenerator {
|
||||
private final BedrockGenerator bedrockGenerator;
|
||||
private final BiomeSelector biomeSelector;
|
||||
private final IslandBiomeGenerator biomeGenerator;
|
||||
private final WorldHeightShader heightShader;
|
||||
|
||||
public final World world;
|
||||
public final IslandWorldBaseTerrainMap islandMapGenerator;
|
||||
public final Random random;
|
||||
|
||||
public IslandWorldGenerator(World world, IslandBiomeGenerator generator, Random random) {
|
||||
public IslandWorldGenerator(World world, IslandBiomeGenerator islandBiomeGenerator, Random random) {
|
||||
this.world = world;
|
||||
this.maxHeight = world.getMaxHeight();
|
||||
this.random = random;
|
||||
this.biomeSelector = new BiomeSelector(random);
|
||||
this.bedrockGenerator = new BedrockGenerator(random);
|
||||
this.islandMapGenerator = new IslandWorldBaseTerrainMap(random, world.getSeaLevel(), 4);
|
||||
this.biomeGenerator = generator;
|
||||
this.biomeGenerator = islandBiomeGenerator;
|
||||
this.heightShader = new WorldHeightShader(world.getSeed(), islandMapGenerator);
|
||||
biomeSelector.initialize();
|
||||
islandBiomeGenerator.initialize(world, islandMapGenerator, biomeSelector);
|
||||
}
|
||||
|
||||
public void GenerateChunk(int chunkX, int chunkZ, int localX, int localZ, ChunkData chunk, BiomeGrid biomeGrid) {
|
||||
int worldX = 16 * chunkX + localX;
|
||||
int worldZ = 16 * chunkZ + localZ;
|
||||
//gets the bedrock.
|
||||
int bedrockHeight = bedrockGenerator.getBedrockHeight(worldX, worldZ);
|
||||
|
||||
//Sets the biome.
|
||||
biomeGenerator.GenerateBiome(chunkX, chunkZ, localX, localZ, biomeGrid);
|
||||
Biome currentBiome = biomeGenerator.GenerateBiome(chunkX, chunkZ, localX, localZ);
|
||||
for (int y = 0; y < maxHeight; y++) {
|
||||
biomeGrid.setBiome(localX, y, localZ, currentBiome);
|
||||
}
|
||||
|
||||
//Sets the bedrock.
|
||||
int bedrockHeight = bedrockGenerator.getBedrockHeight(worldX, worldZ);
|
||||
//get height shader.
|
||||
int height = heightShader.getAltitude(worldX, worldZ, currentBiome);
|
||||
|
||||
|
||||
//set general shape
|
||||
chunk.setRegion(localX, 0, localZ, localX, height, localZ, Material.BEDROCK);
|
||||
|
||||
//set bedrock last
|
||||
chunk.setRegion(localX, 0, localZ, localX, bedrockHeight, localZ, Material.BEDROCK);
|
||||
}
|
||||
}
|
@ -5,13 +5,11 @@ import java.util.Random;
|
||||
import org.bukkit.util.noise.SimplexOctaveGenerator;
|
||||
|
||||
public class BedrockGenerator {
|
||||
private Random random;
|
||||
private SimplexOctaveGenerator noiseGenerator;
|
||||
private final int maxBedrockHeight = 5;
|
||||
private final int minBedrockHeight = 1;
|
||||
|
||||
public BedrockGenerator(Random random) {
|
||||
this.random = random;
|
||||
noiseGenerator = new SimplexOctaveGenerator(random, 8);
|
||||
noiseGenerator.setScale(0.1D);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package ca.recrown.islandsurvivalcraft.world.generation;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateTargetValidatable;
|
||||
import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
|
||||
@ -14,19 +13,14 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
|
||||
private IslandWorldBaseTerrainMap islandLocator;
|
||||
private BiomeSelector biomeSelector;
|
||||
private TemperatureMapGenerator temperatureMapGenerator;
|
||||
private int buildHeight;
|
||||
private World world;
|
||||
private DepthFirstSearch dfs;
|
||||
private Biome mainBiome;
|
||||
private Biome shoreBiome;
|
||||
private float temperature;
|
||||
|
||||
private BiomeGrid currentBiomeGrid;
|
||||
private int currentChunkX, currentChunkZ;
|
||||
|
||||
public BiomePerIslandGenerator() {
|
||||
this.temperatureMapGenerator = new TemperatureMapGenerator();
|
||||
dfs = new DepthFirstSearch(islandLocator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,7 +31,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
|
||||
this.biomeSelector = biomeSelector;
|
||||
this.world = world;
|
||||
this.temperatureMapGenerator.setSeed(world.getSeed());
|
||||
this.buildHeight = world.getMaxHeight();
|
||||
dfs = new DepthFirstSearch(islandLocator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,32 +46,18 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
|
||||
if (mainBiome != null && shoreBiome != null) {
|
||||
return true;
|
||||
}
|
||||
} else if (x/16 == currentChunkX && y/16 == currentChunkZ) {
|
||||
int localX = x - (currentChunkX * 16);
|
||||
int localZ = y - (currentChunkZ * 16);
|
||||
Biome foundBiome = currentBiomeGrid.getBiome(localX, 0, localZ);
|
||||
if (islandLocator.isShore(x, y)) {
|
||||
shoreBiome = foundBiome;
|
||||
} else {
|
||||
mainBiome = foundBiome;
|
||||
}
|
||||
if (mainBiome != null && shoreBiome != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biomeGrid) {
|
||||
public Biome GenerateBiome(int chunkX, int chunkZ, int localX, int localZ) {
|
||||
int worldX = chunkX * 16 + localX;
|
||||
int worldZ = chunkZ * 16 + localZ;
|
||||
|
||||
if (islandLocator.isIsland(worldX, worldZ)) {
|
||||
if (mainBiome == null && shoreBiome == null) {
|
||||
this.currentBiomeGrid = biomeGrid;
|
||||
this.currentChunkX = chunkX;
|
||||
this.currentChunkZ = chunkZ;
|
||||
dfs.setStartPosition(worldX, worldZ);
|
||||
if (!dfs.findTarget(this)) {
|
||||
temperature = temperatureMapGenerator.getTemperature(worldX, worldZ);
|
||||
mainBiome = biomeSelector.getLandBiome(temperature);
|
||||
@ -96,10 +76,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
|
||||
} else if (islandLocator.isShore(worldX, worldZ)) {
|
||||
designatedBiome = shoreBiome;
|
||||
}
|
||||
|
||||
for (int y = 0; y < buildHeight; y++) {
|
||||
biomeGrid.setBiome(localX, y, localZ, designatedBiome);
|
||||
}
|
||||
return designatedBiome;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,13 +2,12 @@ package ca.recrown.islandsurvivalcraft.world.generation;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.world.BiomeSelector;
|
||||
import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap;
|
||||
|
||||
public interface IslandBiomeGenerator {
|
||||
public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biome);
|
||||
public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biomeGrid);
|
||||
public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biomeSelector);
|
||||
public Biome GenerateBiome(int chunkX, int chunkZ, int localX, int localZ);
|
||||
public IslandBiomeGenerator getInstance();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ca.recrown.islandsurvivalcraft.world.shapers;
|
||||
package ca.recrown.islandsurvivalcraft.world.shaders;
|
||||
|
||||
import java.util.Random;
|
||||
|
@ -139,9 +139,9 @@ public class DepthFirstSearchTest {
|
||||
@Test
|
||||
public void testDFSFindEndNodeMapDValid() {
|
||||
Validator validator = new Validator(mapD);
|
||||
dfs = new DepthFirstSearch(validator);
|
||||
dfs.setValidatable(validator);
|
||||
dfs.setStartPosition(0, 0);
|
||||
|
||||
assertTrue(dfs.findTarget(validator));
|
||||
assertEquals(0, dfs.getEndX());
|
||||
assertEquals(3, dfs.getEndY());
|
||||
@ -150,6 +150,7 @@ public class DepthFirstSearchTest {
|
||||
@Test
|
||||
public void testDFSFindEndNodeMapEInvalid() {
|
||||
Validator validator = new Validator(mapE);
|
||||
dfs = new DepthFirstSearch();
|
||||
dfs.setValidatable(validator);
|
||||
dfs.setStartPosition(0, 0);
|
||||
|
||||
|
127
test-server/crash-reports/crash-2020-04-21_20.26.41-server.txt
Normal file
127
test-server/crash-reports/crash-2020-04-21_20.26.41-server.txt
Normal file
File diff suppressed because one or more lines are too long
127
test-server/crash-reports/crash-2020-04-21_20.30.37-server.txt
Normal file
127
test-server/crash-reports/crash-2020-04-21_20.30.37-server.txt
Normal file
File diff suppressed because one or more lines are too long
110
test-server/crash-reports/crash-2020-04-21_20.36.24-server.txt
Normal file
110
test-server/crash-reports/crash-2020-04-21_20.36.24-server.txt
Normal file
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
#Minecraft server properties
|
||||
#Sun Apr 19 03:21:17 CDT 2020
|
||||
#Tue Apr 21 20:37:39 CDT 2020
|
||||
spawn-protection=16
|
||||
max-tick-time=60000
|
||||
query.port=25565
|
||||
|
@ -4,5 +4,5 @@ del /s /f /q world >nul 2>&1
|
||||
ECHO "Attempting to copy plugin jar to plugins folder"
|
||||
COPY "..\target\IslandSurvivalCraft-1.0.0.jar" "plugins\IslandSurvivalCraft-1.0.0.jar" >nul
|
||||
ECHO "Starting server..."
|
||||
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4711 -Xms512M -Xmx1G -jar paper-195.jar nogui
|
||||
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=25566 -Xms512M -Xmx1G -jar paper-195.jar nogui
|
||||
pause
|
@ -3,5 +3,5 @@ rm -rf world
|
||||
echo "Attempting to copy plugin jar to plugins folder"
|
||||
cp "..\target\IslandSurvivalCraft-1.0.0.jar" "plugins\IslandSurvivalCraft-1.0.0.jar"
|
||||
echo "Starting server..."
|
||||
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4711 -Xms512M -Xmx1G -jar paper-195.jar nogui
|
||||
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=25566 -Xms512M -Xmx1G -jar paper-195.jar nogui
|
||||
pause
|
Loading…
Reference in New Issue
Block a user