update platform biome delegate logic

This commit is contained in:
dfsek 2022-12-18 22:44:06 -07:00
parent 73af05bf09
commit c90ca076ab
5 changed files with 12 additions and 24 deletions

View File

@ -18,6 +18,7 @@
package com.dfsek.terra.mod.config;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.registry.Registry;
import net.minecraft.world.biome.Biome;
@ -31,7 +32,7 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
public class ProtoPlatformBiome implements PlatformBiome {
private final Identifier identifier;
private RegistryKey<Biome> delegate;
private RegistryEntry<Biome> delegate;
public ProtoPlatformBiome(Identifier identifier) {
this.identifier = identifier;
@ -46,11 +47,11 @@ public class ProtoPlatformBiome implements PlatformBiome {
return identifier;
}
public RegistryKey<Biome> getDelegate() {
public RegistryEntry<Biome> getDelegate() {
return delegate;
}
public void setDelegate(RegistryKey<Biome> delegate) {
public void setDelegate(RegistryEntry<Biome> delegate) {
this.delegate = Objects.requireNonNull(delegate);
}
}

View File

@ -35,10 +35,7 @@ public final class Codecs {
id)))));
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
.create(instance -> instance.group(RegistryOps.getEntryCodec(RegistryKeys.BIOME)
.fieldOf("biome_registry")
.stable()
.forGetter(TerraBiomeSource::getBiomeRegistry),
.create(instance -> instance.group(
CONFIG_PACK.fieldOf("pack")
.stable()
.forGetter(TerraBiomeSource::getPack))

View File

@ -38,16 +38,14 @@ import com.dfsek.terra.mod.util.SeedHack;
public class TerraBiomeSource extends BiomeSource {
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBiomeSource.class);
private final Registry<net.minecraft.world.biome.Biome> biomeRegistry;
private ConfigPack pack;
public TerraBiomeSource(Registry<net.minecraft.world.biome.Biome> biomes, ConfigPack pack) {
public TerraBiomeSource(ConfigPack pack) {
super(StreamSupport
.stream(pack.getBiomeProvider()
.getBiomes()
.spliterator(), false)
.map(b -> biomes.entryOf(((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate())));
this.biomeRegistry = biomes;
.map(b -> ((ProtoPlatformBiome) b.getPlatformBiome()).getDelegate()));
this.pack = pack;
LOGGER.debug("Biomes: " + getBiomes());
@ -60,22 +58,16 @@ public class TerraBiomeSource extends BiomeSource {
@Override
public RegistryEntry<Biome> getBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseSampler noiseSampler) {
return biomeRegistry
.entryOf(((ProtoPlatformBiome) pack
return ((ProtoPlatformBiome) pack
.getBiomeProvider()
.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2, SeedHack.getSeed(noiseSampler))
.getPlatformBiome()).getDelegate()
);
.getPlatformBiome()).getDelegate();
}
public BiomeProvider getProvider() {
return pack.getBiomeProvider();
}
public Registry<net.minecraft.world.biome.Biome> getBiomeRegistry() {
return biomeRegistry;
}
public ConfigPack getPack() {
return pack;
}

View File

@ -67,7 +67,7 @@ public class PresetUtil {
PRESETS.add(generatorID);
TerraBiomeSource biomeSource = new TerraBiomeSource(biomeRegistry, pack);
TerraBiomeSource biomeSource = new TerraBiomeSource(pack);
ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(biomeSource, pack, overworld);
DimensionOptions dimensionOptions = new DimensionOptions(overworldDimensionType, generator);

View File

@ -54,7 +54,7 @@ public final class BiomeUtil {
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(registry.getEntry(vanilla).orElseThrow());
} else {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
@ -65,14 +65,12 @@ public final class BiomeUtil {
if(registry.containsId(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(MinecraftUtil.getEntry(registry, identifier)
.orElseThrow()
.getKey()
.orElseThrow());
} else {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(Registry.registerReference(registry,
MinecraftUtil.registerKey(identifier)
.getValue(),
minecraftBiome).getKey().orElseThrow());
minecraftBiome));
}
Map<RegistryKey<net.minecraft.world.biome.Biome>, VillagerType> villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();