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

View File

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

View File

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

View File

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

View File

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