-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating worlds with single biome
- Loading branch information
1 parent
08ac65e
commit 71e47d2
Showing
17 changed files
with
242 additions
and
8 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
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
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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/mvplugins/multiverse/core/world/SingleBiomeProvider.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,37 @@ | ||
package org.mvplugins.multiverse.core.world; | ||
|
||
import org.bukkit.WorldCreator; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.generator.BiomeProvider; | ||
import org.bukkit.generator.WorldInfo; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Helps create a world with only 1 type of Biome specified. Used in {@link WorldCreator#biomeProvider(BiomeProvider)} | ||
*/ | ||
public class SingleBiomeProvider extends BiomeProvider { | ||
|
||
private final Biome biome; | ||
private final List<Biome> biomes; | ||
|
||
public SingleBiomeProvider(Biome biome) { | ||
this.biome = biome; | ||
this.biomes = List.of(biome); | ||
} | ||
|
||
@Override | ||
public @NotNull Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) { | ||
return this.biome; | ||
} | ||
|
||
@Override | ||
public @NotNull List<Biome> getBiomes(@NotNull WorldInfo worldInfo) { | ||
return this.biomes; | ||
} | ||
|
||
public Biome getBiome() { | ||
return biome; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.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,33 @@ | ||
package org.mvplugins.multiverse.core.world.config; | ||
|
||
import org.bukkit.block.Biome; | ||
import org.mvplugins.multiverse.core.configuration.functions.NodeSerializer; | ||
Check warning on line 4 in src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java GitHub Actions / checkstyle / checkstyle
|
||
|
||
public class BiomeSerializer implements NodeSerializer<Biome> { | ||
Check warning on line 6 in src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java GitHub Actions / checkstyle / checkstyle
|
||
|
||
static final String VANILLA_BIOME_BEHAVIOUR = "@vanilla"; | ||
Check warning on line 8 in src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java GitHub Actions / checkstyle / checkstyle
|
||
|
||
@Override | ||
Check warning on line 10 in src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java GitHub Actions / checkstyle / checkstyle
|
||
public Biome deserialize(Object object, Class<Biome> type) { | ||
if (object instanceof Biome) { | ||
return (Biome) object; | ||
} | ||
try { | ||
String biomeStr = String.valueOf(object); | ||
if (biomeStr.equalsIgnoreCase(VANILLA_BIOME_BEHAVIOUR)) { | ||
return null; | ||
} | ||
return Biome.valueOf(biomeStr.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object serialize(Biome biome, Class<Biome> type) { | ||
if (biome == null || biome == Biome.CUSTOM) { | ||
return VANILLA_BIOME_BEHAVIOUR; | ||
} | ||
return biome.name().toLowerCase(); | ||
} | ||
} |
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
Oops, something went wrong.