Skip to content

Commit

Permalink
fixed empty populator list & worked on populators more
Browse files Browse the repository at this point in the history
WHERE IS MY KELP MOJANG
  • Loading branch information
sh0inx committed Jan 2, 2025
1 parent 0027713 commit b986d99
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ private void setBlockPopulators() {
|| IridiumSkyblock.getInstance().getConfiguration().generatorType.equalsIgnoreCase("ocean-legacy")) {

IridiumSkyblock.getInstance().getBlockPopulatorList().put(World.Environment.NORMAL, Arrays.asList(
new KelpBlockPopulator(),
new MagmaBlockPopulator(),
new SeagrassBlockPopulator()
new KelpBlockPopulator()
//new MagmaBlockPopulator()
//new SeagrassBlockPopulator()
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,15 @@ && getOceanGenerator(world.getEnvironment()).floor.get() != null) {
}
}

if(IridiumSkyblock.getInstance().getGenerators().useLegacyPopulators) {

} else {
if(!IridiumSkyblock.getInstance().getGenerators().useLegacyPopulators) {
shouldGenerateCaves(world, random, x, z);
shouldGenerateDecorations(world, random , x, z);
shouldGenerateMobs(world, random, x, z);
}

}

@Override
public List<BlockPopulator> getDefaultPopulators(World world) {
public @NotNull List<BlockPopulator> getDefaultPopulators(World world) {
if(IridiumSkyblock.getInstance().getGenerators().useLegacyPopulators) {
return IridiumSkyblock.getInstance().getBlockPopulatorList().get(world.getEnvironment());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import org.jetbrains.annotations.NotNull;
Expand All @@ -24,6 +25,8 @@ public OceanGeneratorLegacy(String name, boolean generatesTerrain, boolean lower
super(name, generatesTerrain, lowerHorizon);
}

SkyblockBiomeProvider biomeProvider = new SkyblockBiomeProvider();

@Override
public @NotNull ChunkData generateChunkData(
@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biomeGrid) {
Expand All @@ -34,12 +37,6 @@ public OceanGeneratorLegacy(String name, boolean generatesTerrain, boolean lower

final ChunkData chunkData = createChunkData(world);

SkyblockBiomeProvider biomeProvider = new SkyblockBiomeProvider();
List<Biome> biomeList = getOceanGenerator(world.getEnvironment()).biomeDataConfig.stream()
.filter(biomeDataConfig -> biomeDataConfig.biome.get() != null)
.map(biomeDataConfig -> biomeDataConfig.biome.get())
.collect(Collectors.toList());

for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
int currentFloorHeight = (int) ((generator.noise(
Expand Down Expand Up @@ -78,7 +75,7 @@ public OceanGeneratorLegacy(String name, boolean generatesTerrain, boolean lower
}

if(!IridiumSkyblock.getInstance().getGenerators().biomeGradient) {
biomeGrid.setBiome(x, z, Objects.requireNonNull(biomeList.get(random.nextInt(biomeList.size()))));
biomeGrid.setBiome(x, z, Objects.requireNonNull(biomeProvider.biomeList.get(random.nextInt(biomeProvider.biomeList.size()))));
} else {
biomeGrid.setBiome(x, z, Objects.requireNonNull(biomeProvider.getBiome(world, x, 0 ,z)));
}
Expand Down Expand Up @@ -190,6 +187,14 @@ && getOceanGenerator(world.getEnvironment()).floor.get() != null) {
}
}

@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(World world) {
if(IridiumSkyblock.getInstance().getBlockPopulatorList().get(world.getEnvironment()) == null) {
return super.getDefaultPopulators(world);
}
return IridiumSkyblock.getInstance().getBlockPopulatorList().get(world.getEnvironment());
}

private Generators.OceanGeneratorWorld getOceanGenerator(Environment environment) {
switch (environment) {
case NETHER: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class SkyblockBiomeProvider extends BiomeProvider {
// Apparently this can happen.
if(worldInfo == null) { return Biome.THE_VOID; }

// APPARENTLY THIS CAN HAPPEN???
if(biomeList.isEmpty()) {
getBiomes(worldInfo);
}

if(biomeList.size() == 1) {
return biomeList.get(0);
}
Expand All @@ -37,7 +42,7 @@ public class SkyblockBiomeProvider extends BiomeProvider {
@NotNull
public List<Biome> getBiomes(@NotNull WorldInfo worldInfo) {

biomeList = sortBiomeData(validateList(getBiomeDataConfig(worldInfo.getEnvironment())));
this.biomeList = sortBiomeData(validateList(getBiomeDataConfig(worldInfo.getEnvironment())));

IridiumSkyblock.getInstance().getLogger().info("Biomes for: " + worldInfo.getName());
for(int i = 0; i < biomeList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.iridium.iridiumskyblock.generators.blockPopulators;

import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.noise.SimplexNoiseGenerator;

Expand All @@ -17,11 +16,16 @@ public class KelpBlockPopulator extends BlockPopulator {
@Override
public void populate(World world, Random random, Chunk chunk) {
SimplexNoiseGenerator generator = new SimplexNoiseGenerator(random);
ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot();

// Range is from -1 to 1.
double noise = generator.getNoise(chunk.getX(), chunk.getZ());
int minHeight = 0;

List<Material> air = Arrays.asList(
Material.AIR,
Material.CAVE_AIR,
Material.VOID_AIR
);

List<Material> greenBlocks = Arrays.asList(
Material.GRAVEL,
Material.SAND,
Expand All @@ -41,30 +45,34 @@ public void populate(World world, Random random, Chunk chunk) {
minHeight = world.getMinHeight();
} catch(NoSuchMethodError ignored) {}

for(int x=0; x<16; x++) {
for(int x=0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
// Range is from -1 to 1.
if (generator.getNoise(x, z) > 0.065) { continue; }

for(int y = minHeight; y < world.getMaxHeight(); y++) {

Block block = chunk.getBlock(x, y, z);
Biome biome = block.getBiome();
if(greenBiomes.stream().noneMatch(biomeType -> biomeType == biome)) { continue; }
BlockData blockData = chunkSnapshot.getBlockData(x, y, z);

if (block.getType() != Material.WATER) { continue; }
if (air.stream().noneMatch(blockType -> blockType == blockData.getMaterial())) { continue; }
if (blockData.getMaterial() != Material.WATER) { continue; }

Material underBlock = chunk.getBlock(x, y - 1, z).getType();
if (greenBlocks.stream().noneMatch(blockType -> blockType == underBlock)) { continue; }
if(greenBiomes.stream().noneMatch(biomeType -> biomeType == block.getBiome())) { continue; }

if (noise > 0.065) { continue; }
Material underBlock = chunkSnapshot.getBlockData(x, y - 1, z).getMaterial();
if (greenBlocks.stream().noneMatch(blockType -> blockType == underBlock)) { continue; }

chunk.getBlock(x, y, z).setType(Material.KELP_PLANT, true);
block.setType(Material.KELP_PLANT, true);

Material overBlock = chunk.getBlock(x, y + 1, z).getType();
int count = 1;
for(int age = random.nextInt(2, 25); age < 25; age++) {
Material overBlock = chunkSnapshot.getBlockData(x, y + count, z).getMaterial();
if(overBlock != Material.WATER) { break; }
chunk.getBlock(x, y + 1, z).setType(Material.KELP_PLANT, true);
chunk.getBlock(x, y + count, z).setType(Material.KELP_PLANT, true);
count++;
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public class MagmaBlockPopulator extends BlockPopulator {
public void populate(World world, Random random, Chunk chunk) {
SimplexNoiseGenerator generator = new SimplexNoiseGenerator(random);

// Range is from -1 to 1.
double noise = generator.getNoise(chunk.getX(), chunk.getZ());
int minHeight = 0;

List<Material> air = Arrays.asList(
Material.AIR,
Material.CAVE_AIR,
Material.VOID_AIR
);

List<Material> greenBlocks = Arrays.asList(
Material.GRAVEL,
Material.DIRT,
Expand Down Expand Up @@ -49,6 +53,8 @@ public void populate(World world, Random random, Chunk chunk) {
for(int y = minHeight; y < world.getMaxHeight(); y++) {

Block block = chunk.getBlock(x, y, z);
if (air.stream().noneMatch(blockType -> blockType == block.getType())) { continue; }

Biome biome = block.getBiome();
if(greenBiomes.stream().noneMatch(biomeType -> biomeType == biome)) { continue; }

Expand All @@ -57,7 +63,8 @@ public void populate(World world, Random random, Chunk chunk) {
Material underBlock = chunk.getBlock(x, y - 1, z).getType();
if (greenBlocks.stream().noneMatch(blockType -> blockType == underBlock)) { continue; }

if (noise > 0.82) { continue; }
// Range is from -1 to 1.
if (generator.getNoise(x, z) > 0.82) { continue; }

chunk.getBlock(x, y - 1, z).setType(Material.MAGMA_BLOCK, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public class SeagrassBlockPopulator extends BlockPopulator {
public void populate(World world, Random random, Chunk chunk) {
SimplexNoiseGenerator generator = new SimplexNoiseGenerator(random);

// Range is from -1 to 1.
double noise = generator.getNoise(chunk.getX(), chunk.getZ());
int minHeight = 0;

List<Material> air = Arrays.asList(
Material.AIR,
Material.CAVE_AIR,
Material.VOID_AIR
);

List<Material> greenBlocks = Arrays.asList(
Material.GRAVEL,
Material.SAND,
Expand All @@ -47,6 +51,8 @@ public void populate(World world, Random random, Chunk chunk) {
for(int y = minHeight; y < world.getMaxHeight(); y++) {

Block block = chunk.getBlock(x, y, z);
if (air.stream().noneMatch(blockType -> blockType == block.getType())) { continue; }

Biome biome = block.getBiome();

if(greenBiomes.stream().noneMatch(biomeType -> biomeType == biome)) { continue; }
Expand All @@ -56,7 +62,8 @@ public void populate(World world, Random random, Chunk chunk) {
Material underBlock = chunk.getBlock(x, y - 1, z).getType();
if (greenBlocks.stream().noneMatch(blockType -> blockType == underBlock)) { continue; }

if (noise > 0.079) { continue; }
// Range is from -1 to 1.
if (generator.getNoise(x, z) > 0.079) { continue; }

if(random.nextBoolean()) {
chunk.getBlock(x, y, z).setType(Material.SEAGRASS, true);
Expand Down

0 comments on commit b986d99

Please sign in to comment.