Skip to content

Commit

Permalink
Made biomes default and added nether and end biomes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 6, 2021
1 parent c7d79a6 commit be18724
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/skygrid/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public class Settings implements WorldSettings {
private Map<Material, Integer> endBlocks = new HashMap<>();

/* SkyGrid */
@ConfigComment("Overworld has biomes - this will affect some block types and tree types.")
@ConfigComment("Biomes - this will affect some block types and tree types.")
@ConfigEntry(path = "world.create-biomes")
private boolean createBiomes = false;
private boolean createBiomes = true;

@ConfigComment("The probability of a frame being created in a chunk. Frames are always at y=0.")
@ConfigEntry(path = "world.end-frame-probability")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@
import java.util.Objects;

import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.util.noise.PerlinOctaveGenerator;

public class BiomeGenerator {

private final PerlinOctaveGenerator temperatureGen, rainfallGen;
private final PerlinOctaveGenerator temperatureGen;
private final PerlinOctaveGenerator rainfallGen;
private final Environment env;

public BiomeGenerator(World world) {
temperatureGen = new PerlinOctaveGenerator(world.getSeed(), 16);
temperatureGen.setScale(1.0/100.0);

rainfallGen = new PerlinOctaveGenerator(world.getSeed() + 1, 15);
rainfallGen.setScale(1.0/100.0);

env = world.getEnvironment();
}

/**
* Get the biome for this coordinate
* @param realX - x
* @param realZ - z
* @return Biome
*/
public Biome getDominantBiome(int realX, int realZ) {
//We get the 3 closest biome's to the temperature and rainfall at this block
HashMap<Biomes, Double> biomes = Biomes.getBiomes(Math.abs(temperatureGen.noise(realX, realZ, 0.5, 0.5)*100.0), Math.abs(rainfallGen.noise(realX, realZ, 0.5, 0.5)*100.0));
HashMap<Biomes, Double> biomes = Biomes.getBiomes(env, Math.abs(temperatureGen.noise(realX, realZ, 0.5, 0.5)*100.0),
Math.abs(rainfallGen.noise(realX, realZ, 0.5, 0.5)*100.0));
//And tell bukkit (who tells the client) what the biggest biome here is
double maxNoiz = 0.0;
Biomes maxBiome = null;
Expand Down
60 changes: 40 additions & 20 deletions src/main/java/world/bentobox/skygrid/generators/Biomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;

import org.bukkit.World.Environment;
import org.bukkit.block.Biome;

/**
Expand All @@ -18,25 +19,40 @@
public enum Biomes {

//We store the biome, the temperature and rainfall for each biome.
SNOWY_TUNDRA(Biome.SNOWY_TUNDRA, 0, 100),
SNOWY_TAIGA(Biome.SNOWY_TAIGA, 0, 100),
FROZEN_RIVER(Biome.FROZEN_RIVER, 0, 10),
SNOWY_BEACH(Biome.SNOWY_BEACH, 0, 100),
MOUNTAINS(Biome.MOUNTAINS, 20, 60),
WOODED_MOUNTAINS(Biome.WOODED_MOUNTAINS, 20, 60),
DESERT(Biome.DESERT, 60, 4),
FOREST(Biome.FOREST, 50, 60),
PLAINS(Biome.PLAINS, 40, 30),
SWAMP(Biome.SWAMP, 40, 70),
JUNGLE(Biome.JUNGLE, 60, 50),
SAVANNA(Biome.SAVANNA, 40, 10),
DESERT_HILLS(Biome.DESERT_HILLS, 60, 5),
TAIGA(Biome.TAIGA, 30, 5);

SNOWY_TUNDRA(Environment.NORMAL, Biome.SNOWY_TUNDRA, 0, 100),
SNOWY_TAIGA(Environment.NORMAL, Biome.SNOWY_TAIGA, 0, 100),
FROZEN_RIVER(Environment.NORMAL, Biome.FROZEN_RIVER, 0, 10),
SNOWY_BEACH(Environment.NORMAL, Biome.SNOWY_BEACH, 0, 100),
MOUNTAINS(Environment.NORMAL, Biome.MOUNTAINS, 20, 60),
WOODED_MOUNTAINS(Environment.NORMAL, Biome.WOODED_MOUNTAINS, 20, 60),
DESERT(Environment.NORMAL, Biome.DESERT, 60, 4),
FOREST(Environment.NORMAL, Biome.FOREST, 50, 60),
PLAINS(Environment.NORMAL, Biome.PLAINS, 40, 30),
SWAMP(Environment.NORMAL, Biome.SWAMP, 40, 70),
JUNGLE(Environment.NORMAL, Biome.JUNGLE, 60, 50),
SAVANNA(Environment.NORMAL, Biome.SAVANNA, 40, 10),
DESERT_HILLS(Environment.NORMAL, Biome.DESERT_HILLS, 60, 5),
TAIGA(Environment.NORMAL, Biome.TAIGA, 30, 5),
// Nether
NETHER_WASTES(Environment.NETHER, Biome.NETHER_WASTES, 40, 30),
SOUL_SAND_VALLEY(Environment.NETHER, Biome.SOUL_SAND_VALLEY, 40, 70),
CRIMSON_FOREST(Environment.NETHER, Biome.CRIMSON_FOREST, 50, 60),
WARPED_FOREST(Environment.NETHER, Biome.WARPED_FOREST, 20, 60),
BASALT_DELTAS(Environment.NETHER, Biome.BASALT_DELTAS, 20, 50),
// The End
THE_END(Environment.THE_END, Biome.THE_END, 40, 30),
SMALL_END_ISLANDS(Environment.THE_END, Biome.SMALL_END_ISLANDS, 0, 100),
END_MIDLANDS(Environment.THE_END, Biome.END_MIDLANDS, 50, 60),
END_HIGHLANDS(Environment.THE_END, Biome.END_HIGHLANDS, 20, 60),
END_BARRENS(Environment.THE_END, Biome.END_BARRENS, 60, 4);

public final Environment env;
public final Biome biome;
public final double optimumTemperature, optimumRainfall;
public final double optimumTemperature;
public final double optimumRainfall;

Biomes(Biome biome, double temp, double rain) {
Biomes(Environment env, Biome biome, double temp, double rain) {
this.env = env;
this.biome = biome;
this.optimumTemperature = temp;
this.optimumRainfall = rain;
Expand All @@ -45,16 +61,20 @@ public enum Biomes {
/**
* Returns the mapping between the 3 closest biomes and "amount of the biome" in this location.
* This is just so that we can limit the amount of calculations we have to do.
* This could probably be cleaned up a bit
* @param env - environment
* @param temp - temperature
* @param rain - rain
* @return Map of 3 biomes
*/
public static HashMap<Biomes, Double> getBiomes(double temp, double rain) {
//We tell it the capacity we need to avoid expensive dynamic lengthening
public static HashMap<Biomes, Double> getBiomes(Environment env, double temp, double rain) {
// We tell it the capacity we need to avoid expensive dynamic lengthening
HashMap<Biomes, Double> biomes = new HashMap<>(3);

Biomes closestBiome = null, secondClosestBiome = null, thirdClosestBiome = null;
double closestDist = 10000000, secondClosestDist = 10000000, thirdClosestDist = 10000000;

for (Biomes biome : Biomes.values()) {
if (!env.equals(biome.env)) continue;
// To avoid having to do an expensive square root per biome per block,
// we just compare the square distances, and take the square root at the
// end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

Expand All @@ -20,12 +21,11 @@
public class SkyGridChunks {

// Blocks that need to be placed on dirt
private static final List<Material> NEEDS_DIRT = Arrays.asList(
private static final List<Material> NEEDS_DIRT = Collections.unmodifiableList(Arrays.asList(
Material.ACACIA_SAPLING,
Material.ALLIUM,
Material.AZURE_BLUET,
Material.BEETROOTS,
Material.BEETROOTS,
Material.BIRCH_SAPLING,
Material.BLUE_ORCHID,
Material.BROWN_MUSHROOM,
Expand All @@ -49,12 +49,11 @@ public class SkyGridChunks {
Material.SPRUCE_SAPLING,
Material.SUGAR_CANE,
Material.SUNFLOWER,
Material.SUNFLOWER,
Material.TALL_GRASS,
Material.WHEAT,
Material.WHITE_TULIP
// TODO add all the other plants that need to go on dirt
);
));

private static final int PRE_MADE_CHUNKS_NUMBER = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public ChunkData generateChunkData(World world, Random random, int chunkX, int c

@Override
public List<BlockPopulator> getDefaultPopulators(World world) {
//return Collections.emptyList();
return Collections.singletonList(populator);
}

Expand Down
22 changes: 20 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ world:
end:
- BLACK_SHULKER_BOX
- BLUE_SHULKER_BOX
- BREWING_STAND
- BROWN_SHULKER_BOX
- CHORUS_FLOWER
- CHORUS_FRUIT
Expand Down Expand Up @@ -675,6 +676,21 @@ world:
COBWEB: 7
GLOWSTONE: 1
RED_NETHER_BRICKS: 12
NETHER_BRICKS: 12
CHISELED_POLISHED_BLACKSTONE: 12
POLISHED_BLACKSTONE_BRICKS: 12
POLISHED_BLACKSTONE_BRICK_STAIRS: 12
CRACKED_POLISHED_BLACKSTONE_BRICKS: 12
NETHERITE_BLOCK: 10
ANCIENT_DEBRIS: 10
BONE_BLOCK: 10
CRYING_OBSIDIAN: 10
OBSIDIAN: 10
BLACKSTONE: 10
GILDED_BLACKSTONE: 10
SOUL_SOIL: 80
NETHER_GOLD_ORE: 12

end:
# Generate SkyGrid End - if this is false, the end world will not be made
generate: true
Expand All @@ -688,8 +704,10 @@ world:
SPAWNER: 5
GRAVEL: 10
PURPUR_BLOCK: 10
# Overworld has biomes - this will affect some block types and tree types.
create-biomes: false
PURPLE_STAINED_GLASS: 10

# Biomes - this will affect some block types and tree types.
create-biomes: true
# The probability of a frame being created in a chunk. Frames are always at y=0.
end-frame-probability: 0.1
# Friendly name for this world. Used in admin commands. Must be a single word
Expand Down

0 comments on commit be18724

Please sign in to comment.