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
@@ -34,10 +34,8 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
public Supplier<OpenRegistry<TerraBiome>> registrySupplier(ConfigPack pack) {
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<TerraBiome>) (t, c, loader) -> {
if(c.equals("SELF")) return null;
TerraBiome obj = registry.get((String) c);
if(obj == null)
throw new LoadException("No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry.");
return obj;
return registry.get((String) c).orElseThrow(() -> new LoadException(
"No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry."));
});
}
@@ -22,6 +22,6 @@ public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
@Override
public TerraBiome parse(CommandSender sender, String arg) {
Player player = (Player) sender;
return player.world().getConfig().getRegistry(TerraBiome.class).get(arg);
return player.world().getConfig().getRegistry(TerraBiome.class).get(arg).orElse(null);
}
}