Fix crash when saving world settings with custom biome generator.
Fixes #14. Minecraft still prints a small error that the biome generator cannot be saved. I've added "Custom biome generators cannot be stored in the level.dat, please ignore this error" to that error.
This commit is contained in:
parent
14fec06cfd
commit
ea6ed9827d
@ -2,6 +2,7 @@ package nl.rutgerkok.worldgeneratorapi.internal;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -14,8 +15,8 @@ import net.minecraft.server.v1_16_R1.BiomeBase;
|
|||||||
import net.minecraft.server.v1_16_R1.Biomes;
|
import net.minecraft.server.v1_16_R1.Biomes;
|
||||||
import net.minecraft.server.v1_16_R1.IRegistry;
|
import net.minecraft.server.v1_16_R1.IRegistry;
|
||||||
import net.minecraft.server.v1_16_R1.WorldChunkManager;
|
import net.minecraft.server.v1_16_R1.WorldChunkManager;
|
||||||
import net.minecraft.server.v1_16_R1.WorldChunkManagerHell;
|
|
||||||
import nl.rutgerkok.worldgeneratorapi.BiomeGenerator;
|
import nl.rutgerkok.worldgeneratorapi.BiomeGenerator;
|
||||||
|
import nl.rutgerkok.worldgeneratorapi.WorldGeneratorApi;
|
||||||
|
|
||||||
public class InjectedBiomeGenerator extends WorldChunkManager {
|
public class InjectedBiomeGenerator extends WorldChunkManager {
|
||||||
|
|
||||||
@ -25,10 +26,13 @@ public class InjectedBiomeGenerator extends WorldChunkManager {
|
|||||||
* generators.) Instead, we serialize as if we are a biome generator that
|
* generators.) Instead, we serialize as if we are a biome generator that
|
||||||
* generates only oceans.
|
* generates only oceans.
|
||||||
*/
|
*/
|
||||||
private static final Codec<WorldChunkManagerHell> DUMMY_CODEC = IRegistry.BIOME.fieldOf("biome")
|
private static final Codec<InjectedBiomeGenerator> DUMMY_CODEC = IRegistry.BIOME.fieldOf(
|
||||||
.xmap(biome -> new WorldChunkManagerHell(biome), biomeGenToSerialize -> {
|
"[" + WorldGeneratorApi.class.getSimpleName()
|
||||||
|
+ "] Custom biome generators cannot be stored in the level.dat, please ignore this error")
|
||||||
|
.xmap(biome -> new InjectedBiomeGenerator(), biomeGenToSerialize -> {
|
||||||
|
// Serializes as a single-biome generator
|
||||||
return Biomes.OCEAN;
|
return Biomes.OCEAN;
|
||||||
})
|
})
|
||||||
.stable().codec();
|
.stable().codec();
|
||||||
|
|
||||||
private static List<BiomeBase> toBiomeBase(Set<Biome> biomes) {
|
private static List<BiomeBase> toBiomeBase(Set<Biome> biomes) {
|
||||||
@ -53,6 +57,16 @@ public class InjectedBiomeGenerator extends WorldChunkManager {
|
|||||||
|
|
||||||
private final BiomeGenerator biomeGenerator;
|
private final BiomeGenerator biomeGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor only used for deserialization. Just provides a dummy biome
|
||||||
|
* generator, as the biome generator plugin should inject its own biome
|
||||||
|
* generator.
|
||||||
|
*/
|
||||||
|
private InjectedBiomeGenerator() {
|
||||||
|
super(Arrays.asList(Biomes.OCEAN));
|
||||||
|
this.biomeGenerator = (x, y, z) -> Biome.OCEAN;
|
||||||
|
}
|
||||||
|
|
||||||
public InjectedBiomeGenerator(BiomeGenerator biomeGenerator) {
|
public InjectedBiomeGenerator(BiomeGenerator biomeGenerator) {
|
||||||
super(toBiomeBase(biomeGenerator.getStructureBiomes()));
|
super(toBiomeBase(biomeGenerator.getStructureBiomes()));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user