make registry return optional for get operations

This commit is contained in:
dfsek
2021-12-01 17:48:41 -07:00
parent 4cc07a7b02
commit a69be58b58
17 changed files with 73 additions and 86 deletions

View File

@@ -72,7 +72,7 @@ public class PlatformImpl extends AbstractPlatform {
worlds.forEach(world -> {
FabricChunkGeneratorWrapper chunkGeneratorWrapper = ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator());
chunkGeneratorWrapper.setPack(getConfigRegistry().get(chunkGeneratorWrapper.getPack().getID()));
chunkGeneratorWrapper.setPack(getConfigRegistry().get(chunkGeneratorWrapper.getPack().getID()).orElseThrow());
});
return succeed;

View File

@@ -72,7 +72,13 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
config -> config.group(
Codec.STRING.fieldOf("pack")
.forGetter(ConfigPack::getID)
).apply(config, config.stable(FabricEntryPoint.getPlatform().getConfigRegistry()::get)));
).apply(config, config.stable(id -> FabricEntryPoint.getPlatform()
.getConfigRegistry()
.get(id)
.orElseThrow(
() -> new IllegalArgumentException(
"No such config pack " +
id)))));
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(
instance -> instance.group(

View File

@@ -24,6 +24,7 @@ import net.minecraft.util.dynamic.RegistryLookupCodec;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -34,16 +35,19 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
public class TerraBiomeSource extends BiomeSource {
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
Codec.STRING.fieldOf("pack").forGetter(ConfigPack::getID)
)
.apply(config, config.stable(
FabricEntryPoint.getPlatform()
.getConfigRegistry()::get))));
id -> FabricEntryPoint.getPlatform()
.getConfigRegistry()
.get(id)
.orElseThrow(
() -> new IllegalArgumentException(
"No such config pack " +
id))))));
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed),

View File

@@ -78,10 +78,10 @@ public abstract class GeneratorOptionsMixin {
l, false);
prop = prop.substring(prop.indexOf(":") + 1);
ConfigPack config = main.getConfigRegistry().get(prop);
if(config == null) throw new IllegalArgumentException("No such pack " + prop);
String finalProp = prop;
ConfigPack config = main.getConfigRegistry().get(prop).orElseThrow(() -> new IllegalArgumentException(
"No such pack " + finalProp));
main.getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes