Skip to content

Commit

Permalink
Include better vanilla gen + fix placeDecoration
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Dec 18, 2024
1 parent ee714d1 commit 34346db
Show file tree
Hide file tree
Showing 49 changed files with 5,195 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Based on plugins made by [wode490390](https://github.com/wode490390)
- https://github.com/wode490390/MultiTemplateStructurePopulator
- https://github.com/wode490390/SingleTemplateStructurePopulator
- https://github.com/wode490390/ScatteredBuildingPopulator
- https://github.com/wode490390/TheEnd
- https://github.com/wode490390/BetterVanillaGenerator
- https://github.com/wode490390/TheEnd
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>worldgeneratorextension</groupId>
<artifactId>WorldGeneratorExtension</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<plugins>
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/worldgeneratorextension/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.nukkit.item.RuntimeItemMapping;
import cn.nukkit.item.RuntimeItems;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.Generator;
import cn.nukkit.level.generator.Normal;
import cn.nukkit.level.generator.Void;
import cn.nukkit.level.generator.populator.type.Populator;
Expand Down Expand Up @@ -36,6 +37,7 @@
import worldgeneratorextension.theend.noise.SimplexNoise;
import worldgeneratorextension.theend.object.theend.ObsidianPillar;
import worldgeneratorextension.theend.populator.theend.*;
import worldgeneratorextension.vanillagenerator.NormalGenerator;
import worldgeneratorextension.vipop.populator.PopulatorVillage;
import worldgeneratorextension.vipop.structure.VillagePieces;

Expand All @@ -58,10 +60,21 @@ public void onLoad() {

@Override
public void onEnable() {
Plugin betterVanillaGenerator = getServer().getPluginManager().getPlugin("BetterVanillaGenerator");
if (betterVanillaGenerator != null && "cn.wode490390.nukkit.vanillagenerator.BetterGenerator".equals(betterVanillaGenerator.getDescription().getMain())) {
getLogger().warning("Already loaded plugin cn.wode490390.nukkit.vanillagenerator.BetterGenerator found. Using WorldGeneratorExtension instead is recommended.");
}

Plugin theEnd = getServer().getPluginManager().getPlugin("TheEnd");
if (theEnd != null && "cn.wode490390.nukkit.theend.TheEnd".equals(theEnd.getDescription().getMain())) {
getLogger().info("Disabling already loaded cn.wode490390.nukkit.theend.TheEnd");
getServer().getPluginManager().disablePlugin(theEnd);
getLogger().warning("Already loaded plugin cn.wode490390.nukkit.theend.TheEnd found. Using WorldGeneratorExtension instead is recommended.");
}

boolean vanillaOverworld = getServer().getPropertyBoolean("wgenext.vanilla-overworld");
if (vanillaOverworld) {
getLogger().info("Using better vanilla overworld generator");
Generator.addGenerator(NormalGenerator.class, "default", NormalGenerator.TYPE_INFINITE);
Generator.addGenerator(NormalGenerator.class, "normal", NormalGenerator.TYPE_INFINITE);
}

PopulatorFossil.init();
Expand All @@ -87,7 +100,7 @@ public void onEnable() {
populatorsOverworld.add(new PopulatorPillagerOutpost());
populatorsOverworld.add(new PopulatorOceanRuin());
populatorsOverworld.add(new PopulatorRuinedPortal());
populatorsOverworld.add(new PopulatorVillage(Normal.seaHeight > 62));
populatorsOverworld.add(new PopulatorVillage(!vanillaOverworld && Normal.seaHeight > 62));
populatorsOverworld.add(new PopulatorStronghold());
populatorsOverworld.add(new PopulatorOceanMonument());
populatorsOverworld.add(new PopulatorMineshaft());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package worldgeneratorextension.pm1e.populator;

import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockID;
import cn.nukkit.block.BlockLayer;
import cn.nukkit.level.ChunkManager;
Expand Down Expand Up @@ -98,7 +99,7 @@ private static void placeDecoration(NukkitRandom random, FullChunk chunk, int am
int z = random.nextBoundedInt(16);
int y = getHighestWorkableBlock(chunk, x, z);

if (y >= 40 && y < Normal.seaHeight) {
if (y >= 40 && y < Normal.seaHeight && Block.isWater(chunk.getBlockId(x, y, z))) {
chunk.setBlock(x, y, z, id, random.nextBoundedInt(type));
chunk.setBlockAtLayer(x, y, z, BlockLayer.WATERLOGGED, BlockID.WATER);
}
Expand Down
387 changes: 387 additions & 0 deletions src/main/java/worldgeneratorextension/vanillagenerator/LICENSE

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package worldgeneratorextension.vanillagenerator.biome;

import cn.nukkit.level.biome.Biome;
import cn.nukkit.level.biome.EnumBiome;
import cn.nukkit.math.NukkitRandom;
import worldgeneratorextension.vanillagenerator.noise.bukkit.SimplexOctaveGenerator;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

public class BiomeClimate {

private static final Int2ObjectMap<Climate> CLIMATE_MAP = new Int2ObjectOpenHashMap<>();
private static final SimplexOctaveGenerator noiseGen;

static {
int[] biomes = new int[Biome.unorderedBiomes.size()];
for (int i = 0; i < biomes.length; i++) {
biomes[i] = Biome.unorderedBiomes.get(i).getId();
}
setBiomeClimate(Climate.DEFAULT, biomes);
setBiomeClimate(Climate.PLAINS, EnumBiome.PLAINS.id, EnumBiome.SUNFLOWER_PLAINS.id, EnumBiome.BEACH.id);
setBiomeClimate(Climate.DESERT, EnumBiome.DESERT.id, EnumBiome.DESERT_HILLS.id, EnumBiome.DESERT_M.id, EnumBiome.MESA.id, EnumBiome.MESA_BRYCE.id, EnumBiome.MESA_PLATEAU.id, EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_M.id, EnumBiome.MESA_PLATEAU_F_M.id, EnumBiome.HELL.id);
setBiomeClimate(Climate.EXTREME_HILLS, EnumBiome.EXTREME_HILLS.id, EnumBiome.EXTREME_HILLS_PLUS.id, EnumBiome.EXTREME_HILLS_M.id, EnumBiome.EXTREME_HILLS_PLUS_M.id, EnumBiome.STONE_BEACH.id, EnumBiome.EXTREME_HILLS_EDGE.id);
setBiomeClimate(Climate.FOREST, EnumBiome.FOREST.id, EnumBiome.FOREST_HILLS.id, EnumBiome.FLOWER_FOREST.id, EnumBiome.ROOFED_FOREST.id, EnumBiome.ROOFED_FOREST_M.id);
setBiomeClimate(Climate.BIRCH_FOREST, EnumBiome.BIRCH_FOREST.id, EnumBiome.BIRCH_FOREST_HILLS.id, EnumBiome.BIRCH_FOREST_M.id, EnumBiome.BIRCH_FOREST_HILLS_M.id);
setBiomeClimate(Climate.TAIGA, EnumBiome.TAIGA.id, EnumBiome.TAIGA_HILLS.id, EnumBiome.TAIGA_M.id, EnumBiome.MEGA_SPRUCE_TAIGA.id, EnumBiome.MEGA_SPRUCE_TAIGA_HILLS.id);
setBiomeClimate(Climate.SWAMPLAND, EnumBiome.SWAMP.id, EnumBiome.SWAMPLAND_M.id);
setBiomeClimate(Climate.ICE_PLAINS, EnumBiome.ICE_PLAINS.id, EnumBiome.ICE_PLAINS_SPIKES.id, EnumBiome.FROZEN_RIVER.id, EnumBiome.FROZEN_OCEAN.id, EnumBiome.ICE_MOUNTAINS.id);
setBiomeClimate(Climate.MUSHROOM, EnumBiome.MUSHROOM_ISLAND.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id);
setBiomeClimate(Climate.COLD_BEACH, EnumBiome.COLD_BEACH.id);
setBiomeClimate(Climate.JUNGLE, EnumBiome.JUNGLE.id, EnumBiome.JUNGLE_HILLS.id, EnumBiome.JUNGLE_M.id, EnumBiome.BAMBOO_JUNGLE.id, EnumBiome.BAMBOO_JUNGLE_HILLS.id);
setBiomeClimate(Climate.JUNGLE_EDGE, EnumBiome.JUNGLE_EDGE.id, EnumBiome.JUNGLE_EDGE_M.id);
setBiomeClimate(Climate.COLD_TAIGA, EnumBiome.COLD_TAIGA.id, EnumBiome.COLD_TAIGA_HILLS.id, EnumBiome.COLD_TAIGA_M.id);
setBiomeClimate(Climate.MEGA_TAIGA, EnumBiome.MEGA_TAIGA.id, EnumBiome.MEGA_TAIGA_HILLS.id);
setBiomeClimate(Climate.SAVANNA, EnumBiome.SAVANNA.id);
setBiomeClimate(Climate.SAVANNA_MOUNTAINS, EnumBiome.SAVANNA_M.id);
setBiomeClimate(Climate.SAVANNA_PLATEAU, EnumBiome.SAVANNA_PLATEAU.id);
setBiomeClimate(Climate.SAVANNA_PLATEAU_MOUNTAINS, EnumBiome.SAVANNA_PLATEAU_M.id);
setBiomeClimate(Climate.SKY);//, EnumBiome.THE_END.id, EnumBiome.SMALL_END_ISLANDS.id, EnumBiome.END_MIDLANDS.id, EnumBiome.END_HIGHLANDS.id, EnumBiome.END_BARRENS.id

noiseGen = new SimplexOctaveGenerator(new NukkitRandom(1234), 1);
noiseGen.setScale(1 / 8.0D);
}

public static double getTemperature(int biome) {
return CLIMATE_MAP.get(biome).getTemperature();
}

public static double getHumidity(int biome) {
return CLIMATE_MAP.get(biome).getHumidity();
}

public static boolean isWet(int biome) {
return getHumidity(biome) > 0.85D;
}

public static boolean isCold(int biome, int x, int y, int z) {
return getVariatedTemperature(biome, x, y, z) < 0.15D;
}

public static boolean isRainy(int biome, int x, int y, int z) {
boolean rainy = CLIMATE_MAP.get(biome).isRainy();
return rainy && !isCold(biome, x, y, z);
}

public static boolean isSnowy(int biome, int x, int y, int z) {
boolean rainy = CLIMATE_MAP.get(biome).isRainy();
return rainy && isCold(biome, x, y, z);
}

private static double getVariatedTemperature(int biome, int x, int y, int z) {
double temp = CLIMATE_MAP.get(biome).getTemperature();
if (y > 64) {
double variation = noiseGen.noise(x, z, 0.5D, 2.0D) * 4.0D;
return temp - (variation + (y - 64)) * 0.05D / 30.0D;
} else {
return temp;
}
}

private static void setBiomeClimate(Climate temp, int... biomes) {
for (int biome : biomes) {
CLIMATE_MAP.put(biome, temp);
}
}

private static class Climate {

public static final Climate DEFAULT = new Climate(0.5D, 0.5D, true);
public static final Climate PLAINS = new Climate(0.8D, 0.4D, true);
public static final Climate DESERT = new Climate(2.0D, 0.0D, false);
public static final Climate EXTREME_HILLS = new Climate(0.2D, 0.3D, true);
public static final Climate FOREST = new Climate(0.7D, 0.8D, true);
public static final Climate BIRCH_FOREST = new Climate(0.6D, 0.6D, true);
public static final Climate TAIGA = new Climate(0.25D, 0.8D, true);
public static final Climate SWAMPLAND = new Climate(0.8D, 0.9D, true);
public static final Climate ICE_PLAINS = new Climate(0.0D, 0.5D, true);
public static final Climate MUSHROOM = new Climate(0.9D, 1.0D, true);
public static final Climate COLD_BEACH = new Climate(0.05D, 0.3D, true);
public static final Climate JUNGLE = new Climate(0.95D, 0.9D, true);
public static final Climate JUNGLE_EDGE = new Climate(0.95D, 0.8D, true);
public static final Climate COLD_TAIGA = new Climate(-0.5D, 0.4D, true);
public static final Climate MEGA_TAIGA = new Climate(0.3D, 0.8D, true);
public static final Climate SAVANNA = new Climate(1.2D, 0.0D, false);
public static final Climate SAVANNA_MOUNTAINS = new Climate(1.1D, 0.0D, false);
public static final Climate SAVANNA_PLATEAU = new Climate(1.0D, 0.0D, false);
public static final Climate SAVANNA_PLATEAU_MOUNTAINS = new Climate(0.5D, 0.0D, false);
public static final Climate SKY = new Climate(0.5D, 0.5D, false);

private final double temperature;
private final double humidity;
private final boolean rainy;

Climate(double temperature, double humidity, boolean rainy) {
this.temperature = temperature;
this.humidity = humidity;
this.rainy = rainy;
}

public double getTemperature() {
return this.temperature;
}

public double getHumidity() {
return this.humidity;
}

public boolean isRainy() {
return this.rainy;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package worldgeneratorextension.vanillagenerator.biomegrid;

import cn.nukkit.level.Level;
import cn.nukkit.level.biome.EnumBiome;
import cn.nukkit.level.generator.Generator;
import cn.nukkit.math.NukkitRandom;
import worldgeneratorextension.vanillagenerator.NormalGenerator;
import worldgeneratorextension.vanillagenerator.biomegrid.MapLayerWhittaker.ClimateType;
import worldgeneratorextension.vanillagenerator.biomegrid.MapLayerZoom.ZoomType;

public abstract class MapLayer {

private final NukkitRandom random = new NukkitRandom();
private final long seed;

public MapLayer(long seed) {
this.seed = seed;
}

/**
* Creates the instances for the given map.
* @param seed the world seed
* @param environment the type of dimension
* @param worldType the world generator
* @return an array of all map layers this dimension needs
*/
public static MapLayer[] initialize(long seed, int environment, int worldType) {
if (environment == Level.DIMENSION_OVERWORLD && worldType == Generator.TYPE_FLAT) {
return new MapLayer[]{new MapLayerBiomeConstant(seed, EnumBiome.PLAINS.id), null};
} else if (environment == Level.DIMENSION_NETHER) {
return new MapLayer[]{new MapLayerBiomeConstant(seed, EnumBiome.HELL.id), null};
} else if (environment == Level.DIMENSION_THE_END) {
return new MapLayer[]{new MapLayerBiomeConstant(seed, 9), null};//EnumBiome.THE_END.id
}

int zoom = 2;
if (worldType == NormalGenerator.TYPE_LARGE_BIOMES) {
zoom = 4;
}

MapLayer layer = new MapLayerNoise(seed); // this is initial land spread layer
layer = new MapLayerWhittaker(seed + 1, layer, ClimateType.WARM_WET);
layer = new MapLayerWhittaker(seed + 1, layer, ClimateType.COLD_DRY);
layer = new MapLayerWhittaker(seed + 2, layer, ClimateType.LARGER_BIOMES);
for (int i = 0; i < 2; i++) {
layer = new MapLayerZoom(seed + 100 + i, layer, ZoomType.BLURRY);
}
for (int i = 0; i < 2; i++) {
layer = new MapLayerErosion(seed + 3 + i, layer);
}
layer = new MapLayerDeepOcean(seed + 4, layer);

MapLayer layerMountains = new MapLayerBiomeVariation(seed + 200, layer);
for (int i = 0; i < 2; i++) {
layerMountains = new MapLayerZoom(seed + 200 + i, layerMountains);
}

layer = new MapLayerBiome(seed + 5, layer);
for (int i = 0; i < 2; i++) {
layer = new MapLayerZoom(seed + 200 + i, layer);
}
layer = new MapLayerBiomeEdge(seed + 200, layer);
layer = new MapLayerBiomeVariation(seed + 200, layer, layerMountains);
layer = new MapLayerRarePlains(seed + 201, layer);
layer = new MapLayerZoom(seed + 300, layer);
layer = new MapLayerErosion(seed + 6, layer);
layer = new MapLayerZoom(seed + 400, layer);
layer = new MapLayerBiomeEdgeThin(seed + 400, layer);
layer = new MapLayerShore(seed + 7, layer);
for (int i = 0; i < zoom; i++) {
layer = new MapLayerZoom(seed + 500 + i, layer);
}

MapLayer layerRiver = layerMountains;
layerRiver = new MapLayerZoom(seed + 300, layerRiver);
layerRiver = new MapLayerZoom(seed + 400, layerRiver);
for (int i = 0; i < zoom; i++) {
layerRiver = new MapLayerZoom(seed + 500 + i, layerRiver);
}
layerRiver = new MapLayerRiver(seed + 10, layerRiver);
layer = new MapLayerRiver(seed + 1000, layerRiver, layer);

MapLayer layerLowerRes = layer;
for (int i = 0; i < 2; i++) {
layer = new MapLayerZoom(seed + 2000 + i, layer);
}

layer = new MapLayerSmooth(seed + 1001, layer);

return new MapLayer[]{layer, layerLowerRes};
}

public void setCoordsSeed(int x, int z) {
this.random.setSeed(this.seed);
this.random.setSeed(x * this.random.nextInt() + z * this.random.nextInt() ^ this.seed);
}

public int nextInt(int max) {
return this.random.nextBoundedInt(max);
}

public abstract int[] generateValues(int x, int z, int sizeX, int sizeZ);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package worldgeneratorextension.vanillagenerator.biomegrid;

import cn.nukkit.level.biome.EnumBiome;

public class MapLayerBiome extends MapLayer {

private static final int[] WARM = new int[]{EnumBiome.DESERT.id, EnumBiome.DESERT.id, EnumBiome.DESERT.id, EnumBiome.SAVANNA.id, EnumBiome.SAVANNA.id, EnumBiome.PLAINS.id};
private static final int[] WET = new int[]{EnumBiome.PLAINS.id, EnumBiome.PLAINS.id, EnumBiome.FOREST.id, EnumBiome.BIRCH_FOREST.id, EnumBiome.ROOFED_FOREST.id, EnumBiome.EXTREME_HILLS.id, EnumBiome.SWAMP.id};
private static final int[] DRY = new int[]{EnumBiome.PLAINS.id, EnumBiome.FOREST.id, EnumBiome.TAIGA.id, EnumBiome.EXTREME_HILLS.id};
private static final int[] COLD = new int[]{EnumBiome.ICE_PLAINS.id, EnumBiome.ICE_PLAINS.id, EnumBiome.COLD_TAIGA.id};
private static final int[] WARM_LARGE = new int[]{EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU.id};
private static final int[] DRY_LARGE = new int[]{EnumBiome.MEGA_TAIGA.id};
private static final int[] WET_LARGE = new int[]{EnumBiome.JUNGLE.id, EnumBiome.JUNGLE.id, EnumBiome.BAMBOO_JUNGLE.id};

private final MapLayer belowLayer;

public MapLayerBiome(long seed, MapLayer belowLayer) {
super(seed);
this.belowLayer = belowLayer;
}

@Override
public int[] generateValues(int x, int z, int sizeX, int sizeZ) {
int[] values = this.belowLayer.generateValues(x, z, sizeX, sizeZ);

int[] finalValues = new int[sizeX * sizeZ];
for (int i = 0; i < sizeZ; i++) {
for (int j = 0; j < sizeX; j++) {
int val = values[j + i * sizeX];
if (val != 0) {
setCoordsSeed(x + j, z + i);
switch (val) {
case 1:
val = DRY[nextInt(DRY.length)];
break;
case 2:
val = WARM[nextInt(WARM.length)];
break;
case 3:
case 1003:
val = COLD[nextInt(COLD.length)];
break;
case 4:
val = WET[nextInt(WET.length)];
break;
case 1001:
val = DRY_LARGE[nextInt(DRY_LARGE.length)];
break;
case 1002:
val = WARM_LARGE[nextInt(WARM_LARGE.length)];
break;
case 1004:
val = WET_LARGE[nextInt(WET_LARGE.length)];
break;
default:
break;
}
}
finalValues[j + i * sizeX] = val;
}
}
return finalValues;
}
}
Loading

0 comments on commit 34346db

Please sign in to comment.