Skip to content

Commit

Permalink
Added the ability to configure the default biomes for all the worlds (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 5, 2022
1 parent ecb16dd commit 431d128
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 40 deletions.
Expand Up @@ -864,6 +864,11 @@ interface Normal {
*/
boolean isSchematicOffset();

/**
* Get the default biome for the world.
*/
String getBiome();

}

interface Nether {
Expand Down Expand Up @@ -892,6 +897,11 @@ interface Nether {
*/
boolean isSchematicOffset();

/**
* Get the default biome for the world.
*/
String getBiome();

}

interface End {
Expand Down Expand Up @@ -920,6 +930,11 @@ interface End {
*/
boolean isSchematicOffset();

/**
* Get the default biome for the world.
*/
String getBiome();

/**
* Whether ender-dragon fights should be enabled for islands or not.
* Config-path: worlds.end.dragon-fight
Expand Down
Expand Up @@ -82,14 +82,17 @@ public final class SettingsContainer {
public final boolean normalWorldEnabled;
public final boolean normalWorldUnlocked;
public final boolean normalSchematicOffset;
public final String normalBiome;
public final boolean netherWorldEnabled;
public final boolean netherWorldUnlocked;
public final String netherWorldName;
public final boolean netherSchematicOffset;
public final String netherBiome;
public final boolean endWorldEnabled;
public final boolean endWorldUnlocked;
public final String endWorldName;
public final boolean endSchematicOffset;
public final String endBiome;
public final boolean endDragonFight;
public final String worldsDifficulty;
public final String spawnLocation;
Expand Down Expand Up @@ -278,16 +281,19 @@ else if (sections.length == 3)
normalWorldEnabled = config.getBoolean("worlds.normal.enabled", true);
normalWorldUnlocked = config.getBoolean("worlds.normal.unlock", true);
normalSchematicOffset = config.getBoolean("worlds.normal.schematic-offset", true);
normalBiome = config.getString("worlds.normal.biome", "PLAINS");
netherWorldEnabled = config.getBoolean("worlds.nether.enabled", false);
netherWorldUnlocked = config.getBoolean("worlds.nether.unlock", true);
String netherWorldName = config.getString("worlds.nether.name", "");
this.netherWorldName = netherWorldName.isEmpty() ? islandWorldName + "_nether" : netherWorldName;
netherSchematicOffset = config.getBoolean("worlds.nether.schematic-offset", true);
netherBiome = config.getString("worlds.nether.biome", "NETHER_WASTES");
endWorldEnabled = config.getBoolean("worlds.end.enabled", false);
endWorldUnlocked = config.getBoolean("worlds.end.unlock", false);
String endWorldName = config.getString("worlds.end.name", "");
this.endWorldName = endWorldName.isEmpty() ? islandWorldName + "_the_end" : endWorldName;
endSchematicOffset = config.getBoolean("worlds.end.schematic-offset", true);
endBiome = config.getString("worlds.end.biome", "THE_END");
endDragonFight = endWorldEnabled && config.getBoolean("worlds.end.dragon-fight", false) && ServerVersion.isAtLeast(ServerVersion.v1_9);
String defaultWorldEnvironment = config.getString("worlds.default-world");
if (defaultWorldEnvironment.equalsIgnoreCase("normal") && normalWorldEnabled) {
Expand Down
Expand Up @@ -66,6 +66,11 @@ public boolean isUnlocked() {
public boolean isSchematicOffset() {
return container.normalSchematicOffset;
}

@Override
public String getBiome() {
return container.normalBiome;
}
}

private class NetherSection implements Nether {
Expand All @@ -89,6 +94,11 @@ public String getName() {
public boolean isSchematicOffset() {
return container.netherSchematicOffset;
}

@Override
public String getBiome() {
return container.netherBiome;
}
}

private class EndSection implements End {
Expand All @@ -113,6 +123,11 @@ public boolean isSchematicOffset() {
return container.endSchematicOffset;
}

@Override
public String getBiome() {
return container.endBiome;
}

@Override
public boolean isDragonFight() {
return container.endDragonFight;
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -287,6 +287,9 @@ worlds:
unlock: true
# Should the schematics in this world will not be counted towards worth and level values?
schematic-offset: true
# The default biome for the world.
# If the biome is invalid, PLAINS will be set.
biome: PLAINS
# Settings related to the nether world.
nether:
# Should the nether world be enabled?
Expand All @@ -298,6 +301,9 @@ worlds:
name: ''
# Should the schematics in this world will not be counted towards worth and level values?
schematic-offset: true
# The default biome for the world.
# If the biome is invalid, NETHER (or it's 1.16 equivalent) will be used.
biome: NETHER_WASTES
end:
# Should the end world be enabled?
enabled: false
Expand All @@ -308,6 +314,9 @@ worlds:
name: ''
# Should the schematics in this world will not be counted towards worth and level values?
schematic-offset: true
# The default biome for the world.
# If the biome is invalid, THE_END will be used.
biome: THE_END
# Should dragon fight be enabled? This will spawn dragons for each island.
# This feature is in beta, expect bugs!
dragon-fight: false
Expand Down
Expand Up @@ -25,21 +25,37 @@ public IslandsGeneratorImpl(SuperiorSkyblockPlugin plugin) {
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
ChunkData chunkData = createChunkData(world);

Biome targetBiome;

switch (world.getEnvironment()) {
case NORMAL: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.PLAINS);
break;
}
case NETHER: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.HELL);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNether().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.HELL;
}
break;
}
case THE_END: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.SKY);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getEnd().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.SKY;
}
break;
}
default: {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNormal().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.PLAINS;
}
break;
}
}

plugin.getNMSWorld().setBiome(biomeGrid, targetBiome);

if (chunkX == 0 && chunkZ == 0 && world.getEnvironment() == plugin.getSettings().getWorlds().getDefaultWorld()) {
chunkData.setBlock(0, 99, 0, Material.BEDROCK);
}
Expand Down
Expand Up @@ -25,21 +25,37 @@ public IslandsGeneratorImpl(SuperiorSkyblockPlugin plugin) {
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
ChunkData chunkData = createChunkData(world);

Biome targetBiome;

switch (world.getEnvironment()) {
case NORMAL: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.PLAINS);
break;
}
case NETHER: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.NETHER);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNether().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.NETHER;
}
break;
}
case THE_END: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.THE_END);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getEnd().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.THE_END;
}
break;
}
default: {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNormal().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.PLAINS;
}
break;
}
}

plugin.getNMSWorld().setBiome(biomeGrid, targetBiome);

if (chunkX == 0 && chunkZ == 0 && world.getEnvironment() == plugin.getSettings().getWorlds().getDefaultWorld()) {
chunkData.setBlock(0, 99, 0, Material.BEDROCK);
}
Expand Down
Expand Up @@ -25,21 +25,37 @@ public IslandsGeneratorImpl(SuperiorSkyblockPlugin plugin) {
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
ChunkData chunkData = createChunkData(world);

Biome targetBiome;

switch (world.getEnvironment()) {
case NORMAL: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.PLAINS);
break;
}
case NETHER: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.NETHER_WASTES);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNether().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.NETHER_WASTES;
}
break;
}
case THE_END: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.THE_END);
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getEnd().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.THE_END;
}
break;
}
default: {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNormal().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.PLAINS;
}
break;
}
}

plugin.getNMSWorld().setBiome(biomeGrid, targetBiome);

if (chunkX == 0 && chunkZ == 0 && world.getEnvironment() == plugin.getSettings().getWorlds().getDefaultWorld()) {
chunkData.setBlock(0, 99, 0, Material.BEDROCK);
}
Expand Down
Expand Up @@ -25,21 +25,34 @@ public IslandsGeneratorImpl(SuperiorSkyblockPlugin plugin) {
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
ChunkData chunkData = createChunkData(world);

Biome targetBiome;

switch (world.getEnvironment()) {
case NORMAL: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.PLAINS);
break;
case NETHER -> {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNether().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.NETHER_WASTES;
}
}
case NETHER: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.NETHER_WASTES);
break;
case THE_END -> {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getEnd().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.THE_END;
}
}
case THE_END: {
plugin.getNMSWorld().setBiome(biomeGrid, Biome.THE_END);
break;
default -> {
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNormal().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.PLAINS;
}
}
}

plugin.getNMSWorld().setBiome(biomeGrid, targetBiome);

if (chunkX == 0 && chunkZ == 0 && world.getEnvironment() == plugin.getSettings().getWorlds().getDefaultWorld()) {
chunkData.setBlock(0, 99, 0, Material.BEDROCK);
}
Expand Down
Expand Up @@ -11,18 +11,52 @@
import org.bukkit.generator.WorldInfo;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Random;

@SuppressWarnings({"unused", "NullableProblems"})
public final class IslandsGeneratorImpl extends IslandsGenerator {

private final SuperiorSkyblockPlugin plugin;
private final EnumMap<World.Environment, Biome> biomeEnumMap = new EnumMap<>(World.Environment.class);

public IslandsGeneratorImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;

{
Biome targetBiome;
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNormal().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.PLAINS;
}

biomeEnumMap.put(World.Environment.NORMAL, targetBiome == Biome.CUSTOM ? Biome.PLAINS : targetBiome);
}

{
Biome targetBiome;
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getNether().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.NETHER_WASTES;
}
biomeEnumMap.put(World.Environment.NETHER, targetBiome == Biome.CUSTOM ? Biome.NETHER_WASTES : targetBiome);
}

{
Biome targetBiome;
try {
targetBiome = Biome.valueOf(plugin.getSettings().getWorlds().getEnd().getBiome().toUpperCase());
} catch (IllegalArgumentException error) {
targetBiome = Biome.THE_END;
}
biomeEnumMap.put(World.Environment.THE_END, targetBiome == Biome.CUSTOM ? Biome.THE_END : targetBiome);
}

}

@Override
Expand All @@ -39,16 +73,12 @@ public BiomeProvider getDefaultBiomeProvider(@NotNull WorldInfo worldInfo) {
return new BiomeProvider() {
@Override
public @NotNull Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
return switch (worldInfo.getEnvironment()) {
case NETHER -> Biome.NETHER_WASTES;
case THE_END -> Biome.THE_END;
default -> Biome.PLAINS;
};
return biomeEnumMap.getOrDefault(worldInfo.getEnvironment(), Biome.PLAINS);
}

@Override
public @NotNull List<Biome> getBiomes(@NotNull WorldInfo worldInfo) {
return Arrays.asList(Biome.NETHER_WASTES, Biome.THE_END, Biome.PLAINS);
return new ArrayList<>(biomeEnumMap.values());
}

};
Expand Down

0 comments on commit 431d128

Please sign in to comment.