Selecting best spawn location if it wasn't defined
This commit is contained in:
@@ -9,9 +9,10 @@ public final class WorldConstants {
|
||||
public static final String WORLD_INFO_FILE_NAME_TEMPLATE = "world.dat";
|
||||
public static final String REGION_FILE_NAME_TEMPLATE = "r.{0}.{1}";
|
||||
|
||||
public static final int WORLD_MIN_HEIGHT = 36;
|
||||
public static final int WORLD_MAX_HEIGHT = 256;
|
||||
public static final int WORLD_SEA_LEVEL = 64;
|
||||
public static final int WORLD_MAX_HEIGHT = 128;
|
||||
public static final int WORLD_MIN_GENERATION_HEIGHT = 36;
|
||||
public static final int WORLD_MAX_GENERATION_HEIGHT = 128;
|
||||
public static final int WORLD_REGION_SIZE = 256;
|
||||
public static final int WORLD_CHUNK_SIZE = 16;
|
||||
public static final int WORLD_MAX_TEMPERATURE = 100;
|
||||
|
||||
@@ -179,8 +179,8 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
int tz = convert(z + region.getZ() * WORLD_REGION_SIZE);
|
||||
double p = sigmoid(noiseGenerator.noise(tx / WORLD_LAND_SIZE, tz / WORLD_LAND_SIZE));
|
||||
double r = Math.sqrt(noiseGenerator.noise(tx / WORLD_LAKE_SIZE, tz / WORLD_LAKE_SIZE));
|
||||
double h = (WORLD_MAX_HEIGHT - WORLD_MIN_HEIGHT) * Math.min(p * r, 1);
|
||||
h = Math.min(WORLD_MAX_HEIGHT, h + WORLD_MIN_HEIGHT);
|
||||
double h = (WORLD_MAX_GENERATION_HEIGHT - WORLD_MIN_GENERATION_HEIGHT) * Math.min(p * r, 1);
|
||||
h = Math.min(WORLD_MAX_GENERATION_HEIGHT, h + WORLD_MIN_GENERATION_HEIGHT);
|
||||
heightMap[x][z] = (int)(h);
|
||||
grassMap[x][z] = (int) (1 + SeedRandomGenerator.random(tx, tz, world.getSeed()) * (LANDFILL_GRASS_SURFACE_THIN - 1));
|
||||
double k = Math.sqrt(noiseGenerator.noise(tx * WORLD_TEMPERATURE_ZONE_SIZE, tz * WORLD_TEMPERATURE_ZONE_SIZE));
|
||||
@@ -191,8 +191,8 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
wetMap[x][z] = (int) (WORLD_MAX_WETNESS * WORLD_WET_SEA_PERCENT *noiseGenerator.noise(tx, tz));
|
||||
} else {
|
||||
int th = heightMap[x][z] - WORLD_SEA_LEVEL;
|
||||
th = (int) (th * (1 + 1.25 * th / (WORLD_MAX_HEIGHT - WORLD_SEA_LEVEL)));
|
||||
heightMap[x][z] = Math.min(WORLD_SEA_LEVEL + th, WORLD_MAX_HEIGHT);
|
||||
th = (int) (th * (1 + 1.25 * th / (WORLD_MAX_GENERATION_HEIGHT - WORLD_SEA_LEVEL)));
|
||||
heightMap[x][z] = Math.min(WORLD_SEA_LEVEL + th, WORLD_MAX_GENERATION_HEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
} else {
|
||||
if (height < WORLD_SEA_LEVEL) {
|
||||
if (height < WORLD_MIN_HEIGHT + (WORLD_SEA_LEVEL - WORLD_MIN_HEIGHT) / 2) {
|
||||
if (height < WORLD_MIN_GENERATION_HEIGHT + (WORLD_SEA_LEVEL - WORLD_MIN_GENERATION_HEIGHT) / 2) {
|
||||
return Biome.DEEP_OCEAN;
|
||||
} else {
|
||||
return Biome.OCEAN;
|
||||
@@ -376,7 +376,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
final int HILLS_HEIGHT = WORLD_SEA_LEVEL + (WORLD_MAX_HEIGHT - WORLD_SEA_LEVEL) / 3;
|
||||
final int HILLS_HEIGHT = WORLD_SEA_LEVEL + (WORLD_MAX_GENERATION_HEIGHT - WORLD_SEA_LEVEL) / 3;
|
||||
|
||||
if (temperature == Temperature.FROST) {
|
||||
if (wetness == Wetness.DRIEST || wetness == Wetness.DRY) {
|
||||
|
||||
@@ -3,8 +3,10 @@ package mc.world.generated_world.world;
|
||||
import com.flowpowered.nbt.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.Location;
|
||||
import mc.core.WarpPosition;
|
||||
import mc.core.block.BlockType;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.world.Chunk;
|
||||
import mc.core.world.IWorldType;
|
||||
@@ -17,6 +19,10 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static mc.world.generated_world.WorldConstants.WORLD_CHUNK_SIZE;
|
||||
import static mc.world.generated_world.WorldConstants.WORLD_MAX_HEIGHT;
|
||||
|
||||
@Slf4j
|
||||
public class CubicWorld implements World {
|
||||
@Getter
|
||||
private final UUID worldId;
|
||||
@@ -59,6 +65,15 @@ public class CubicWorld implements World {
|
||||
if (warpPosition == null) {
|
||||
synchronized (spawnLocationLock) {
|
||||
if (warpPosition == null) {
|
||||
log.warn("Spawn location is not defined. Trying to select best location");
|
||||
warpPosition = new WarpPosition(Location.startPointLocation(), new Look(0, 0));
|
||||
for (int y = WORLD_MAX_HEIGHT; y > 0; y --) {
|
||||
Chunk chunk = getChunk(0,y / WORLD_CHUNK_SIZE, 0);
|
||||
if (chunk.getBlock(0, y, 0).getBlockType() != BlockType.AIR) {
|
||||
warpPosition = new WarpPosition(new Location(0, y + 1, 0), new Look(0, 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
warpPosition = new WarpPosition(Location.startPointLocation(), new Look(0,0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user