Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocean generator #741

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b6cba19
implementing the ocean generator
sh0inx Sep 23, 2023
1923acb
Cleanup
PeachesMLG Sep 23, 2023
ac96453
Merge remote-tracking branch 'origin' into ocean-generator-&-others
sh0inx Sep 23, 2023
7d972d1
Updated Generators
sh0inx Sep 23, 2023
aca7991
Update OceanGenerator.java
sh0inx Sep 24, 2023
7bdc78b
Merge branch 'master' into ocean-generator-&-others
sh0inx Feb 2, 2024
3e646d2
fixed the generator!
sh0inx Feb 2, 2024
61c80ad
Merge branch 'master' into ocean-generator-&-others
sh0inx Feb 19, 2024
9cc68b0
refactored world generation to createWorld()
sh0inx Feb 19, 2024
3d20ad2
added generator type logging
sh0inx Mar 6, 2024
9b82606
Updated calls to regenerateTerrain to use .join()
sh0inx Mar 16, 2024
545e414
das suggested we format the enum differently so we did
sh0inx Mar 16, 2024
741577d
Merge branch 'master' into ocean-generator-&-others
sh0inx Mar 16, 2024
0801168
Added flatlands generator (#845)
sh0inx May 10, 2024
d0fe9f8
added a more explicit comment
sh0inx May 10, 2024
00b4258
made the delete world method a lil nicer (ty das)
sh0inx May 10, 2024
75f991c
removed generateChunkData
sh0inx May 10, 2024
d262577
reverted deleteWorld method overhaul
sh0inx May 10, 2024
587f133
remove imports
sh0inx May 10, 2024
0bfba52
Re-implemented ChunkData method, cleaned up cache world creation
sh0inx May 13, 2024
ee13fe2
Removed shouldGenerateDecorations methods (temporarily)
sh0inx May 13, 2024
099bf9a
Update IridiumSkyblock.java
sh0inx Jul 21, 2024
824d84d
Merge branch 'master' into ocean-generator-&-others
dlsf Sep 4, 2024
208779a
Fix imports
dlsf Sep 4, 2024
5d64c01
Merge branch 'master' into ocean-generator-&-others
sh0inx Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.iridium.iridiumskyblock.configs.*;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.generators.FlatGenerator;
import com.iridium.iridiumskyblock.generators.OceanGenerator;
import com.iridium.iridiumskyblock.generators.VoidGenerator;
import com.iridium.iridiumskyblock.listeners.*;
import com.iridium.iridiumskyblock.managers.*;
Expand All @@ -27,6 +29,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

Expand All @@ -49,6 +52,7 @@ public class IridiumSkyblock extends IridiumTeams<Island, User> {
private Shop shop;
private Biomes biomes;
private Settings settings;
private Generators generators;

private IslandPlaceholderBuilder teamsPlaceholderBuilder;
private UserPlaceholderBuilder userPlaceholderBuilder;
Expand Down Expand Up @@ -79,7 +83,31 @@ public IridiumSkyblock() {
@Override
public void onLoad() {
super.onLoad();
this.chunkGenerator = new VoidGenerator();

getLogger().info("Loading world generator...");
getLogger().info("Generator Type = " + IridiumSkyblock.getInstance().getConfiguration().generatorType);

// This switch statement is here so that if we end up adding another generator type, we can throw it in this.
switch (IridiumSkyblock.getInstance().getConfiguration().generatorType) {
case OCEAN: {
this.chunkGenerator = new OceanGenerator();
break;
}
case FLAT: {
this.chunkGenerator = new FlatGenerator();
break;
}
case VANILLA: {
this.chunkGenerator = null;
break;
}
default: {
getLogger().warning("Invalid generator type [" + IridiumSkyblock.getInstance().getConfiguration().generatorType + "], valid types are " + Arrays.toString(GeneratorType.values()));
getLogger().info("Generator Type = " + GeneratorType.VOID);
this.chunkGenerator = new VoidGenerator();
break;
}
}
}

@Override
Expand Down Expand Up @@ -161,6 +189,8 @@ public void loadConfigs() {
this.shop = getPersist().load(Shop.class);
this.biomes = getPersist().load(Biomes.class);
this.settings = getPersist().load(Settings.class);
this.generators = getPersist().load(Generators.class);
getLogger().info("GENERATOR TYPE: " + IridiumSkyblock.getInstance().getConfiguration().generatorType);
super.loadConfigs();

int maxSize = enhancements.sizeEnhancement.levels.values().stream()
Expand Down Expand Up @@ -195,6 +225,7 @@ public void saveConfigs() {
getPersist().save(shop);
getPersist().save(biomes);
getPersist().save(settings);
getPersist().save(generators);
saveSchematics();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.iridium.iridiumcore.Item;
import com.iridium.iridiumcore.dependencies.xseries.XMaterial;
import com.iridium.iridiumcore.dependencies.xseries.XSound;
import com.iridium.iridiumskyblock.managers.GeneratorType;
import com.iridium.iridiumteams.Reward;
import org.bukkit.World;

Expand Down Expand Up @@ -43,6 +44,7 @@ public Configuration() {
public String defaultDescription = "Default island description :c";
public String worldName = "IridiumSkyblock";
public String spawnWorldName = "world";
public GeneratorType generatorType = GeneratorType.VOID;
public String islandTitleTop = "&9%island_name%";
public String islandTitleBottom = "&7%island_description%";
public String paster = "worldedit";
Expand Down
163 changes: 163 additions & 0 deletions src/main/java/com/iridium/iridiumskyblock/configs/Generators.java
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are Biomes neccisary here? they will get overridden when you create an island, so will just be more confusing to people configuring no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added them for consistency, they do affect things spawning outside of an island for terrain generation purposes, but you're right

Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.iridium.iridiumskyblock.configs;

import com.google.common.collect.ImmutableMap;
import com.iridium.iridiumcore.dependencies.fasterxml.annotation.JsonIgnoreProperties;
import com.iridium.iridiumcore.dependencies.xseries.XBiome;
import com.iridium.iridiumcore.dependencies.xseries.XMaterial;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Generators {

public Generators.SkyblockGeneratorConfig skyblockGenerator = new SkyblockGeneratorConfig(
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(
XBiome.PLAINS,
true
),
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(
XBiome.NETHER_WASTES,
true
),
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(
XBiome.THE_END,
true
)
);

public Generators.OceanGeneratorConfig oceanGenerator = new OceanGeneratorConfig(
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XBiome.OCEAN,
XMaterial.SAND,
XMaterial.STONE,
XMaterial.WATER,
63, 48, 53,
true,
true
),
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XBiome.NETHER_WASTES,
XMaterial.SOUL_SAND,
XMaterial.NETHERRACK,
XMaterial.LAVA,
63, 48, 53,
true,
true
),
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XBiome.END_BARRENS,
XMaterial.END_STONE,
XMaterial.END_STONE,
XMaterial.VOID_AIR,
63, 48, 53,
true,
true
));

public Generators.FlatGeneratorConfig flatGenerator = new FlatGeneratorConfig(
new com.iridium.iridiumskyblock.configs.Generators.FlatGeneratorWorld(
XBiome.PLAINS,
XMaterial.GRASS_BLOCK,
XMaterial.DIRT,
-59,
true,
true
),
new com.iridium.iridiumskyblock.configs.Generators.FlatGeneratorWorld(
XBiome.NETHER_WASTES,
XMaterial.NETHERRACK,
XMaterial.NETHERRACK,
5,
true,
true
),
new com.iridium.iridiumskyblock.configs.Generators.FlatGeneratorWorld(
XBiome.END_BARRENS,
XMaterial.END_STONE,
XMaterial.END_STONE,
5,
true,
true
));

@NoArgsConstructor
@AllArgsConstructor
public static class SkyblockGeneratorConfig {
public SkyblockGeneratorWorld overworld;
public SkyblockGeneratorWorld nether;
public SkyblockGeneratorWorld end;
}

@NoArgsConstructor
@AllArgsConstructor
public static class OceanGeneratorConfig {
public OceanGeneratorWorld overworld;
public OceanGeneratorWorld nether;
public OceanGeneratorWorld end;
}

@NoArgsConstructor
@AllArgsConstructor
public static class FlatGeneratorConfig {
public FlatGeneratorWorld overworld;
public FlatGeneratorWorld nether;
public FlatGeneratorWorld end;
}

@NoArgsConstructor
public static class SkyblockGeneratorWorld {
public XBiome biome;
public boolean canSpawnEntities;

public SkyblockGeneratorWorld(XBiome biome, boolean canSpawnEntities) {
this.biome = biome;
this.canSpawnEntities = canSpawnEntities;
}
}

@NoArgsConstructor
public static class OceanGeneratorWorld {
public XBiome biome;
public XMaterial floor;
public XMaterial underFloor;
public XMaterial liquidType;
public int liquidHeight;
public int minFloorHeight;
public int maxFloorHeight;
public boolean decorate;
public boolean canSpawnEntities;

public OceanGeneratorWorld(XBiome biome, XMaterial floor, XMaterial underFloor, XMaterial liquidType, int liquidHeight, int minFloorHeight, int maxFloorHeight, boolean decorate, boolean canSpawnEntities) {
this.biome = biome;
this.floor = floor;
this.underFloor = underFloor;
this.liquidType = liquidType;
this.liquidHeight = liquidHeight;
this.minFloorHeight = minFloorHeight;
this.maxFloorHeight = maxFloorHeight;
this.decorate = decorate;
this.canSpawnEntities = canSpawnEntities;
}
}

@NoArgsConstructor
public static class FlatGeneratorWorld {
public XBiome biome;
public XMaterial floor;
public XMaterial underFloor;
public int floorHeight;
public boolean decorate;
public boolean canSpawnEntities;

public FlatGeneratorWorld(XBiome biome, XMaterial floor, XMaterial underFloor, int floorHeight, boolean decorate, boolean canSpawnEntities) {
this.biome = biome;
this.floor = floor;
this.underFloor = underFloor;
this.floorHeight = floorHeight;
this.decorate = decorate;
this.canSpawnEntities = canSpawnEntities;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.iridium.iridiumskyblock.generators;

import com.iridium.iridiumcore.dependencies.xseries.XMaterial;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.configs.Generators;
import com.iridium.iridiumskyblock.utils.LocationUtils;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import org.jetbrains.annotations.NotNull;
import org.bukkit.generator.WorldInfo;

import java.util.*;

public class FlatGenerator extends ChunkGenerator {

@Override
public @NotNull ChunkData generateChunkData(
@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biomeGrid) {

final ChunkData chunkData = createChunkData(world);
int floorHeight = getFlatGenerator(world.getEnvironment()).floorHeight;

for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {

// Generate layer of bedrock
chunkData.setBlock(x, LocationUtils.getMinHeight(world), z,
Objects.requireNonNull(XMaterial.BEDROCK.parseMaterial())
);

// Generate dirt layer
for (int y = LocationUtils.getMinHeight(world) + 1; y < floorHeight; y++) {
chunkData.setBlock(x, y, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial())
);
}

// Generate grass on top of dirt
chunkData.setBlock(x, floorHeight, z,
Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).floor.parseMaterial())
);

biomeGrid.setBiome(x, z, Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).biome.getBiome()));
}
}

return chunkData;
}

public void generateFlatland(World world, int x, int z) {

Random random = new Random((world.getSeed()));

int floorHeight = getFlatGenerator(world.getEnvironment()).floorHeight;
int minFloorHeight = world.getMinHeight();

// Generate layer of bedrock
if (world.getBlockAt(x, minFloorHeight, z).getType() != XMaterial.BEDROCK.parseMaterial()) {
if (world.getBlockAt(x, minFloorHeight, z).getState() instanceof InventoryHolder) {
((InventoryHolder) world.getBlockAt(x, minFloorHeight, z).getState()).getInventory().clear();
}
world.getBlockAt(x, minFloorHeight, z).setType(Material.BEDROCK, false);
}

// Generate dirt layer
for (int y = minFloorHeight + 1; y < floorHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial() != null) {

if (block.getState() instanceof InventoryHolder) {
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setType(Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).underFloor.parseMaterial()), false);
}
}

// Generate grass on top of dirt
if (world.getBlockAt(x, floorHeight, z).getType() != getFlatGenerator(world.getEnvironment()).floor.parseMaterial()
&& getFlatGenerator(world.getEnvironment()).floor.parseMaterial() != null) {

if (world.getBlockAt(x, floorHeight, z).getState() instanceof InventoryHolder) {
((InventoryHolder) world.getBlockAt(x, floorHeight, z).getState()).getInventory().clear();
}

world.getBlockAt(x, floorHeight, z)
.setType(Objects.requireNonNull(getFlatGenerator(world.getEnvironment()).floor.parseMaterial()), false);

}

// Replace everything else with air
for (int y = floorHeight + 1; y < world.getMaxHeight(); y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != Material.AIR) {
if (block.getState() instanceof InventoryHolder) {
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setType(Material.AIR, false);
}
}

// Generate kelp, ores, and mineral deposits
shouldGenerateDecorations(world, random , x, z);
}

@Override
public boolean shouldGenerateDecorations(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z) {
return getFlatGenerator(worldInfo.getEnvironment()).decorate;
}

@Override
public boolean canSpawn(@NotNull World world, int x, int z) {
return getFlatGenerator(world.getEnvironment()).canSpawnEntities;
}

private Generators.FlatGeneratorWorld getFlatGenerator(Environment environment) {
switch (environment) {
case NETHER: {
return IridiumSkyblock.getInstance().getGenerators().flatGenerator.nether;
}
case THE_END: {
return IridiumSkyblock.getInstance().getGenerators().flatGenerator.end;
}
default: {
return IridiumSkyblock.getInstance().getGenerators().flatGenerator.overworld;
}
}
}
}
Loading
Loading