Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Comparable to the CubicPopulators in order to make an orderable generation && caching Heightmaps in order to use on another generators #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
gradle/.DS_Store
.DS_Store

/logs/

# eclipse
bin
*.launch
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/io/github/terra121/EarthTerrainProcessor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package io.github.terra121;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.*;

import io.github.opencubicchunks.cubicchunks.api.util.Coords;
import io.github.opencubicchunks.cubicchunks.api.util.CubePos;
Expand All @@ -23,6 +17,7 @@
import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.IBiomeBlockReplacerProvider;
import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings;
import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.structure.CubicCaveGenerator;
import io.github.terra121.dataset.HeightmapModel;
import io.github.terra121.dataset.Heights;
import io.github.terra121.dataset.OpenStreetMaps;
import io.github.terra121.populator.CliffReplacer;
Expand Down Expand Up @@ -60,6 +55,8 @@ public class EarthTerrainProcessor extends BasicCubeGenerator {
private boolean doRoads;
private boolean doBuildings;

public static final int spawnSize = 5;

public EarthTerrainProcessor(World world) {
super(world);

Expand All @@ -81,7 +78,7 @@ public EarthTerrainProcessor(World world) {
unnaturals.add(Blocks.CONCRETE);
unnaturals.add(Blocks.BRICK_BLOCK);

surfacePopulators = new HashSet<ICubicPopulator>();
surfacePopulators = new TreeSet<>();
if(doRoads || cfg.settings.osmwater)surfacePopulators.add(new RoadGenerator(osm, heights, projection));
surfacePopulators.add(new EarthTreePopulator(projection));
snow = new SnowPopulator(); //this will go after the rest
Expand Down Expand Up @@ -124,7 +121,7 @@ public CubePrimer generateCube(int cubeX, int cubeY, int cubeZ) {
boolean surface = false;

//null island
if(-5 < cubeX && cubeX < 5 && -5 < cubeZ && cubeZ < 5) {
if(-spawnSize < cubeX && cubeX < spawnSize && -spawnSize < cubeZ && cubeZ < spawnSize) {
for(int x=0; x<16; x++)
for(int z=0; z<16; z++)
heightarr[x][z] = 1;
Expand All @@ -145,6 +142,11 @@ public CubePrimer generateCube(int cubeX, int cubeY, int cubeZ) {
}
}

CubePos pos = new CubePos(cubeX, cubeY, cubeZ);
HeightmapModel model = new HeightmapModel(surface, heightarr);

HeightmapModel.add(pos, model);

//fill in the world
for(int x=0; x<16; x++) {
for(int z=0; z<16; z++) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/github/terra121/dataset/HeightmapModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.terra121.dataset;

import io.github.opencubicchunks.cubicchunks.api.util.CubePos;

import java.util.HashMap;
import java.util.Map;

public class HeightmapModel {
public boolean surface;
public double[][] heightmap;

private HeightmapModel() {}

public HeightmapModel(boolean surface, double[][] heightmap) {
this.heightmap = heightmap;
this.surface = surface;
}

private static Map<CubePos, HeightmapModel> cachedHeightmaps = new HashMap<>();

public static HeightmapModel getModel(int chunkX, int chunkY, int chunkZ) {
return getModel(new CubePos(chunkX, chunkY, chunkZ));
}

public static HeightmapModel getModel(CubePos pos) {
if(!cachedHeightmaps.containsKey(pos))
return null;

return cachedHeightmaps.get(pos);
}

public static void add(CubePos pos, HeightmapModel model) {
cachedHeightmaps.put(pos, model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

public class EarthTreePopulator implements ICubicPopulator {
public class EarthTreePopulator implements ICubicPopulator, Comparable<Object> {

Trees trees;

Expand Down Expand Up @@ -106,5 +106,10 @@ private int quickElev(World world, int x, int z, int low, int high) {

return low;
}

@Override
public int compareTo(Object o) {
return 1;
}

}
19 changes: 18 additions & 1 deletion src/main/java/io/github/terra121/populator/RoadGenerator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.terra121.populator;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.function.BiFunction;
Expand All @@ -20,7 +21,9 @@
import net.minecraft.world.biome.Biome;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;

public class RoadGenerator implements ICubicPopulator {
public class RoadGenerator implements ICubicPopulator, Comparable<Object> {

private static Set<CubePos> roadChunks = new HashSet<>();

private static final IBlockState ASPHALT = Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, EnumDyeColor.GRAY);
private static final IBlockState WATER_SOURCE = Blocks.WATER.getDefaultState();
Expand Down Expand Up @@ -93,6 +96,8 @@ public void generate(World world, Random rand, CubePos pos, Biome biome) {
}
}
}

roadChunks.add(new CubePos(cubeX, cubeY, cubeZ));
}
}

Expand Down Expand Up @@ -214,4 +219,16 @@ private static double bound(double x, double slope, double j, double k, double r
}
return slope*x + sign*b;
}

public static boolean isRoad(int cubeX, int cubeY, int cubeZ) {
CubePos pos = new CubePos(cubeX, cubeY, cubeZ);
boolean isRoad = roadChunks.contains(pos);
// roadChunks.remove(pos);
return isRoad;
}

@Override
public int compareTo(Object o) {
return 0;
}
}