-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
PeachesMLG
wants to merge
25
commits into
master
Choose a base branch
from
ocean-generator-&-others
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ocean generator #741
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b6cba19
implementing the ocean generator
sh0inx 1923acb
Cleanup
PeachesMLG ac96453
Merge remote-tracking branch 'origin' into ocean-generator-&-others
sh0inx 7d972d1
Updated Generators
sh0inx aca7991
Update OceanGenerator.java
sh0inx 7bdc78b
Merge branch 'master' into ocean-generator-&-others
sh0inx 3e646d2
fixed the generator!
sh0inx 61c80ad
Merge branch 'master' into ocean-generator-&-others
sh0inx 9cc68b0
refactored world generation to createWorld()
sh0inx 3d20ad2
added generator type logging
sh0inx 9b82606
Updated calls to regenerateTerrain to use .join()
sh0inx 545e414
das suggested we format the enum differently so we did
sh0inx 741577d
Merge branch 'master' into ocean-generator-&-others
sh0inx 0801168
Added flatlands generator (#845)
sh0inx d0fe9f8
added a more explicit comment
sh0inx 00b4258
made the delete world method a lil nicer (ty das)
sh0inx 75f991c
removed generateChunkData
sh0inx d262577
reverted deleteWorld method overhaul
sh0inx 587f133
remove imports
sh0inx 0bfba52
Re-implemented ChunkData method, cleaned up cache world creation
sh0inx ee13fe2
Removed shouldGenerateDecorations methods (temporarily)
sh0inx 099bf9a
Update IridiumSkyblock.java
sh0inx 824d84d
Merge branch 'master' into ocean-generator-&-others
dlsf 208779a
Fix imports
dlsf 5d64c01
Merge branch 'master' into ocean-generator-&-others
sh0inx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 110 additions & 0 deletions
110
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,110 @@ | ||
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 | ||
)); | ||
|
||
@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 | ||
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; | ||
|
||
} | ||
} | ||
} |
166 changes: 166 additions & 0 deletions
166
src/main/java/com/iridium/iridiumskyblock/generators/OceanGenerator.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,166 @@ | ||
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 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) | ||
* (getOceanGenerator(world.getEnvironment()).maxFloorHeight - getOceanGenerator(world.getEnvironment()).minFloorHeight) | ||
+ getOceanGenerator(world.getEnvironment()).minFloorHeight); | ||
|
||
// 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(getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial()) | ||
); | ||
} | ||
|
||
// Generate sand on top of gravel | ||
chunkData.setBlock(x, currentFloorHeight, z, | ||
Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).floor.parseMaterial()) | ||
); | ||
|
||
// Generate water or lava on top of the floor | ||
for (int y = currentFloorHeight + 1; y <= getOceanGenerator(world.getEnvironment()).liquidHeight; y++) { | ||
chunkData.setBlock(x, y, z, Objects.requireNonNull( | ||
getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial())); | ||
} | ||
|
||
biomeGrid.setBiome(x, z, Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).biome.getBiome())); | ||
} | ||
} | ||
|
||
return chunkData; | ||
} | ||
|
||
public void generateOcean(World world, int x, int z) { | ||
|
||
Random random = new Random((world.getSeed())); | ||
|
||
SimplexOctaveGenerator generator = new SimplexOctaveGenerator(random, 8); | ||
generator.setScale(0.005D); | ||
|
||
int currentFloorHeight = (int) ((generator.noise( | ||
x, z, 1.5D, 0.5D, true) + 1) | ||
* (getOceanGenerator(world.getEnvironment()).maxFloorHeight - getOceanGenerator(world.getEnvironment()).minFloorHeight) | ||
+ getOceanGenerator(world.getEnvironment()).minFloorHeight); | ||
|
||
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() != getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial() | ||
&& getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial() != null) { | ||
|
||
if (block.getState() instanceof InventoryHolder) { | ||
((InventoryHolder) block.getState()).getInventory().clear(); | ||
} | ||
block.setType(Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).underFloor.parseMaterial()), false); | ||
} | ||
} | ||
|
||
// Generate sand on top of gravel | ||
if (world.getBlockAt(x, currentFloorHeight, z).getType() != getOceanGenerator(world.getEnvironment()).floor.parseMaterial() | ||
&& getOceanGenerator(world.getEnvironment()).floor.parseMaterial() != null) { | ||
|
||
if (world.getBlockAt(x, currentFloorHeight, z).getState() instanceof InventoryHolder) { | ||
((InventoryHolder) world.getBlockAt(x, currentFloorHeight, z).getState()).getInventory().clear(); | ||
} | ||
|
||
for(int y = currentFloorHeight; y < currentFloorHeight + 5; y++) { | ||
world.getBlockAt(x, currentFloorHeight, z) | ||
.setType(Objects.requireNonNull(getOceanGenerator(world.getEnvironment()).floor.parseMaterial()), false); | ||
currentFloorHeight++; | ||
} | ||
|
||
} | ||
|
||
// Generate water or lava on top of the floor | ||
for (int y = currentFloorHeight + 1; y <= getOceanGenerator(world.getEnvironment()).liquidHeight; y++) { | ||
Block block = world.getBlockAt(x, y, z); | ||
if (block.getType() != getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial() && getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial() != null) { | ||
if (block.getState() instanceof InventoryHolder) { | ||
((InventoryHolder) block.getState()).getInventory().clear(); | ||
} | ||
block.setType(getOceanGenerator(world.getEnvironment()).liquidType.parseMaterial(), false); | ||
} | ||
} | ||
|
||
// Replace everything else with air | ||
for (int y = getOceanGenerator(world.getEnvironment()).liquidHeight + 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 getOceanGenerator(worldInfo.getEnvironment()).decorate; | ||
} | ||
|
||
@Override | ||
public boolean canSpawn(@NotNull World world, int x, int z) { | ||
return getOceanGenerator(world.getEnvironment()).canSpawnEntities; | ||
} | ||
|
||
private Generators.OceanGeneratorWorld getOceanGenerator(Environment environment) { | ||
switch (environment) { | ||
case NETHER: { | ||
return IridiumSkyblock.getInstance().getGenerators().oceanGenerator.nether; | ||
} | ||
case THE_END: { | ||
return IridiumSkyblock.getInstance().getGenerators().oceanGenerator.end; | ||
} | ||
default: { | ||
return IridiumSkyblock.getInstance().getGenerators().oceanGenerator.overworld; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.iridium.iridiumskyblock.generators; | ||
|
||
import com.iridium.iridiumskyblock.IridiumSkyblock; | ||
import com.iridium.iridiumskyblock.configs.Generators; | ||
import org.bukkit.World; | ||
import org.bukkit.generator.BlockPopulator; | ||
import org.bukkit.generator.ChunkGenerator; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
|
||
public class VoidGenerator extends ChunkGenerator { | ||
|
@@ -15,7 +18,13 @@ public class VoidGenerator extends ChunkGenerator { | |
|
||
@Override | ||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biomeGrid) { | ||
return createChunkData(world); | ||
final ChunkData chunkData = createChunkData(world); | ||
for (int x = 0; x < 16; x++) { | ||
for (int z = 0; z < 16; z++) { | ||
biomeGrid.setBiome(x, z, Objects.requireNonNull(getSkyblockGenerator(world.getEnvironment()).biome.getBiome())); | ||
} | ||
} | ||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly redundent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont remember why this was here, but i remember it being important, so if it breaks you can just revert the change ig |
||
return chunkData; | ||
} | ||
|
||
public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomeGrid) { | ||
|
@@ -27,12 +36,25 @@ public byte[][] generateBlockSections(World world, Random random, int x, int z, | |
|
||
@Override | ||
public boolean canSpawn(@NotNull World world, int x, int z) { | ||
return true; | ||
return getSkyblockGenerator(world.getEnvironment()).canSpawnEntities; | ||
} | ||
|
||
@Override | ||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
private Generators.SkyblockGeneratorWorld getSkyblockGenerator(World.Environment environment) { | ||
switch (environment) { | ||
case NETHER: { | ||
return IridiumSkyblock.getInstance().getGenerators().skyblockGenerator.nether; | ||
} | ||
case THE_END: { | ||
return IridiumSkyblock.getInstance().getGenerators().skyblockGenerator.end; | ||
} | ||
default: { | ||
return IridiumSkyblock.getInstance().getGenerators().skyblockGenerator.overworld; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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