Improve UX when a resource mount cannot be found

- Add a full example of the docs. Hopefully is a little more explicit.
 - Print a warning when the mount is empty.

Closes #762
This commit is contained in:
Jonathan Coates 2021-04-13 13:01:28 +01:00
parent 058d63e77f
commit 8494ba8ce2
2 changed files with 16 additions and 1 deletions

View File

@ -98,7 +98,9 @@ public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull
* resource folder onto a computer's file system.
*
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
* resources with the same domain and path.
* resources with the same domain and path. For instance, ComputerCraft's resources are stored in
* "/data/computercraft/lua/rom". We construct a mount for that with
* {@code createResourceMount("computercraft", "lua/rom")}.
*
* @param domain The domain under which to look for resources. eg: "mymod".
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".

View File

@ -103,9 +103,13 @@ private ResourceMount( String namespace, String subPath, IReloadableResourceMana
private void load()
{
boolean hasAny = false;
String existingNamespace = null;
FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) );
for( ResourceLocation file : manager.listResources( subPath, s -> true ) )
{
existingNamespace = file.getNamespace();
if( !file.getNamespace().equals( namespace ) ) continue;
String localPath = FileSystem.toLocal( file.getPath(), subPath );
@ -114,6 +118,15 @@ private void load()
}
root = hasAny ? newRoot : null;
if( !hasAny )
{
ComputerCraft.log.warn("Cannot find any files under /data/{}/{} for resource mount.", namespace, subPath);
if( newRoot != null )
{
ComputerCraft.log.warn("There are files under /data/{}/{} though. Did you get the wrong namespace?", existingNamespace, subPath);
}
}
}
private FileEntry get( String path )