mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-14 03:36:03 +00:00
make registry return optional for get operations
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user