-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implementing the ocean generator * Cleanup * Updated Generators updated generators to allow server owners to set the default biome and whether they'd like their oceans to be decorated or not (includes ores, deposits, and geodes, no caves) * Update OceanGenerator.java cleaned up some residual das code * fixed the generator! uh so we basically create a duplicate of the world on first generation of an island that will then be used to copy and paste the terrain under the islands the first generation is slow because it has to create the worlds, but once this is done its exactly like the deleting blocks method except in reverse * refactored world generation to createWorld() - moved the cache world creation to the create world method so that the plugin does not lag on island creation - changed setting to GeneratorType enum - added vanilla generation option (takes advantage of null chunk generator) - deletes and regenerates cache world on bad seed comparison so that the cache world matches even on generator change * added generator type logging * Updated calls to regenerateTerrain to use .join() - moved the check for if the generator is a terrain generator to the methods that call regenerateTerrain * das suggested we format the enum differently so we did Co-authored-by: Daniel Scherf <[email protected]> * Added flatlands generator (#845) * Added flatlands generator - also added some logging about the generator type to ensure that server admins know what the correct enum values are * forgot to import arrays, silly me * added a more explicit comment * made the delete world method a lil nicer (ty das) Co-authored-by: Daniel Scherf <[email protected]> * removed generateChunkData * reverted deleteWorld method overhaul * remove imports * Re-implemented ChunkData method, cleaned up cache world creation * Removed shouldGenerateDecorations methods (temporarily) * Update IridiumSkyblock.java plugin would incorrectly report invalid generator type for VOID because i didnt add the case for void, so it would default * Fix imports --------- Co-authored-by: Shyanne <[email protected]> Co-authored-by: Daniel Scherf <[email protected]> Co-authored-by: Daniel Scherf <[email protected]>
- Loading branch information
1 parent
a8b32b7
commit 50b4862
Showing
8 changed files
with
641 additions
and
7 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
160 changes: 160 additions & 0 deletions
160
src/main/java/com/iridium/iridiumskyblock/configs/Generators.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 |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.iridium.iridiumskyblock.configs; | ||
|
||
import com.cryptomorin.xseries.XBiome; | ||
import com.cryptomorin.xseries.XMaterial; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
|
||
@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; | ||
} | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
src/main/java/com/iridium/iridiumskyblock/generators/FlatGenerator.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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.iridium.iridiumskyblock.generators; | ||
|
||
import com.cryptomorin.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.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 | ||
// BREAKS BELOW 1.18 | ||
//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; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.