-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19 Makes chests a bit more generous. Version up.
- Loading branch information
1 parent
106ee59
commit 0958d79
Showing
6 changed files
with
139 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 28 additions & 16 deletions
44
src/main/java/world/bentobox/skygrid/generators/BiomeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
package world.bentobox.skygrid.generators; | ||
|
||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
import org.bukkit.World; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.util.noise.PerlinOctaveGenerator; | ||
|
||
public class BiomeGenerator { | ||
|
||
private final PerlinOctaveGenerator temperatureGen, rainfallGen; | ||
|
||
public BiomeGenerator(World world) { | ||
// I used a scale of 1/300 instead of something like 1/600 or 1/1000 | ||
// to make the biome edges easier to see | ||
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); | ||
} | ||
|
||
public HashMap<Biomes, Double> getBiomes(int realX, int realZ) { | ||
return 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)); | ||
} | ||
|
||
private final PerlinOctaveGenerator temperatureGen, rainfallGen; | ||
|
||
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); | ||
} | ||
|
||
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)); | ||
//And tell bukkit (who tells the client) what the biggest biome here is | ||
double maxNoiz = 0.0; | ||
Biomes maxBiome = null; | ||
|
||
for (Biomes biome : biomes.keySet()) { | ||
if (biomes.get(biome) >= maxNoiz) { | ||
maxNoiz = biomes.get(biome); | ||
maxBiome = biome; | ||
} | ||
} | ||
return Objects.requireNonNull(maxBiome).biome; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.