Skip to content

Commit

Permalink
implementing the ocean generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sh0inx committed Sep 23, 2023
1 parent d9a5445 commit b6cba19
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.iridium.iridiumskyblock.configs.*;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.generators.OceanGenerator;
import com.iridium.iridiumskyblock.generators.VoidGenerator;
import com.iridium.iridiumskyblock.listeners.*;
import com.iridium.iridiumskyblock.managers.*;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class IridiumSkyblock extends IridiumTeams<Island, User> {
private Schematics schematics;
private Shop shop;
private Settings settings;
private Generators generators;

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

switch(IridiumSkyblock.getInstance().getConfiguration().generatorType) {
case "ocean": {
this.chunkGenerator = new OceanGenerator();
break;
}
default: {
this.chunkGenerator = new VoidGenerator();
break;
}
}
}

@Override
Expand Down Expand Up @@ -157,6 +169,7 @@ public void loadConfigs() {
this.schematics = getPersist().load(Schematics.class);
this.shop = getPersist().load(Shop.class);
this.settings = getPersist().load(Settings.class);
this.generators = getPersist().load(Generators.class);
super.loadConfigs();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Configuration() {
public String defaultDescription = "Default island description :c";
public String worldName = "IridiumSkyblock";
public String spawnWorldName = "world";
public String generatorType = "skyblock";
public String islandTitleTop = "&9%island_name%";
public String islandTitleBottom = "&7%island_description%";
public String paster = "worldedit";
Expand Down
95 changes: 95 additions & 0 deletions src/main/java/com/iridium/iridiumskyblock/configs/Generators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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.XMaterial;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Generators {

public Map<String, Generators.GeneratorConfig> generators = ImmutableMap.<String, GeneratorConfig>builder()

.put("skyblock", new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorConfig(
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(true),
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(true),
new com.iridium.iridiumskyblock.configs.Generators.SkyblockGeneratorWorld(true)))

.put("ocean", new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorConfig(
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XMaterial.SAND,
XMaterial.STONE,
XMaterial.WATER,
63, 48, 53, true
),
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XMaterial.SOUL_SAND,
XMaterial.NETHERRACK,
XMaterial.LAVA,
63, 48, 53, true
),
new com.iridium.iridiumskyblock.configs.Generators.OceanGeneratorWorld(
XMaterial.END_STONE,
XMaterial.END_STONE,
XMaterial.VOID_AIR,
63, 48, 53, true
)))
.build();

@NoArgsConstructor
@AllArgsConstructor
public static class GeneratorConfig {
public Generators.SkyblockGeneratorConfig skyblock;
public Generators.OceanGeneratorConfig ocean;
}

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

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

@NoArgsConstructor
public static class SkyblockGeneratorWorld {
public boolean canSpawnEntities;

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

@NoArgsConstructor
public static class OceanGeneratorWorld {

public XMaterial floor;
public XMaterial underFloor;
public XMaterial liquidType;
public int liquidHeight;
public int minFloorHeight;
public int maxFloorHeight;
public boolean canSpawnEntities;

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

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
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.BiomeProvider;
import org.bukkit.generator.WorldInfo;

import java.util.Map;
import java.util.Objects;
import java.util.Random;

public class OceanGenerator extends ChunkGenerator {

@Override
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biomeGrid) {
SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
final ChunkData chunkData = createChunkData(world);
generator.setScale(0.005D);

for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
int currentFloorHeight = (int) ((generator.noise(chunkX * 16 + x, chunkZ * 16 + z, 1.5D, 0.5D, true) + 1) * (getMaxFloorHeight(world.getEnvironment()) - getMinFloorHeight(world.getEnvironment())) + getMinFloorHeight(world.getEnvironment()));

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

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

// Generate sand on top of gravel
chunkData.setBlock(x, currentFloorHeight, z,
Objects.requireNonNull(getFloor(world.getEnvironment()).parseMaterial())
);

// Generate water or lava on top of the floor
for (int y = currentFloorHeight + 1; y <= getliquidHeight(world.getEnvironment()); y++) {
chunkData.setBlock(x, y, z, Objects.requireNonNull(getLiquidType(world.getEnvironment()).parseMaterial()));
}
}
}

return chunkData;
}

public void generateWater(World world, int x, int z) {
SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
generator.setScale(0.005D);

int currentFloorHeight = (int) ((generator.noise(x, z, 1.5D, 0.5D, true) + 1) * (getMaxFloorHeight(world.getEnvironment()) - getMinFloorHeight(world.getEnvironment())) + getMinFloorHeight(world.getEnvironment()));
int minHeightWorld = LocationUtils.getMinHeight(world);

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

// Generate gravel layer
for (int y = minHeightWorld + 1; y < currentFloorHeight; y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != getUnderFloor(world.getEnvironment()).parseMaterial() && getUnderFloor(world.getEnvironment()).parseMaterial() != null) {
if (block.getState() instanceof InventoryHolder) {
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setType(getUnderFloor(world.getEnvironment()).parseMaterial(), false);
}
}

// Generate sand on top of gravel
if (world.getBlockAt(x, currentFloorHeight, z).getType() != getFloor(world.getEnvironment()).parseMaterial() && getFloor(world.getEnvironment()).parseMaterial() != null) {
if (world.getBlockAt(x, currentFloorHeight, z).getState() instanceof InventoryHolder) {
((InventoryHolder) world.getBlockAt(x, currentFloorHeight, z).getState()).getInventory().clear();
}
world.getBlockAt(x, currentFloorHeight, z).setType(getFloor(world.getEnvironment()).parseMaterial(), false);
}

// Generate water or lava on top of the floor
XMaterial oceanMaterial = world.getEnvironment() == Environment.NETHER ? XMaterial.LAVA : XMaterial.WATER;
for (int y = currentFloorHeight + 1; y <= getliquidHeight(world.getEnvironment()); y++) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() != oceanMaterial.parseMaterial() && oceanMaterial.parseMaterial() != null) {
if (block.getState() instanceof InventoryHolder) {
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setType(oceanMaterial.parseMaterial(), false);
}
}

// Replace everything else with air
for (int y = getliquidHeight(world.getEnvironment()) + 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);
}
}
}

@Override
public boolean canSpawn(@NotNull World world, int x, int z) {
return true;
}

@Override
public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) {
return null;
}

Map<String, Generators.GeneratorConfig> generatorConfig = IridiumSkyblock.getInstance().getGenerators().generators;

public XMaterial getFloor(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("floor").nether.floor;
}
case THE_END: {
return generatorConfig.get("floor").ocean.end.floor;
}
default: {
return generatorConfig.get("floor").ocean.overworld.floor;
}
}
}

public XMaterial getUnderFloor(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("underFloor").ocean.nether.underFloor;
}
case THE_END: {
return generatorConfig.get("underFloor").ocean.end.underFloor;
}
default: {
return generatorConfig.get("underFloor").ocean.overworld.underFloor;
}
}
}

public XMaterial getLiquidType(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("liquidType").ocean.nether.liquidType;
}
case THE_END: {
return generatorConfig.get("liquidType").ocean.end.liquidType;
}
default: {
return generatorConfig.get("liquidType").ocean.overworld.liquidType;
}
}
}

public int getliquidHeight (Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("liquidHeight").ocean.nether.liquidHeight;
}
case THE_END: {
return generatorConfig.get("liquidHeight").ocean.end.liquidHeight;
}
default: {
return generatorConfig.get("liquidHeight").ocean.overworld.liquidHeight;
}
}
}

public int getMinFloorHeight(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("minFloorHeight").ocean.nether.minFloorHeight;
}
case THE_END: {
return generatorConfig.get("minFloorHeight").ocean.end.minFloorHeight;
}
default: {
return generatorConfig.get("minFloorHeight").ocean.overworld.minFloorHeight;
}
}
}

public int getMaxFloorHeight(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("maxFloorHeight").ocean.nether.maxFloorHeight;
}
case THE_END: {
return generatorConfig.get("maxFloorHeight").ocean.end.maxFloorHeight;
}
default: {
return generatorConfig.get("maxFloorHeight").ocean.overworld.maxFloorHeight;
}
}
}

public boolean getCanSpawnEntities(Environment environment) {
switch(environment) {
case NETHER: {
return generatorConfig.get("canSpawnEntities").ocean.nether.canSpawnEntities;
}
case THE_END: {
return generatorConfig.get("canSpawnEntities").ocean.end.canSpawnEntities;
}
default: {
return generatorConfig.get("canSpawnEntities").ocean.overworld.canSpawnEntities;
}
}
}

}
Loading

0 comments on commit b6cba19

Please sign in to comment.