Jump to content

[1.8.8] ResourceLocation as a directory [SOLVED]


RANKSHANK

Recommended Posts

Hey guys, I was wondering if anyone knows of a way grab ResourceLocation as a directory, or even just get a list of files in a given folder of the loaded resource packs. At the moment I'm just reading from a txt file with file names listed in it since I have set locations I need to parse through. It works but I was hoping for something a little cleaner and more end user friendly

 

Also since this doesn't deserve its own thread; is there a call for binding custom IMetadata instances? I've resorted to using reflection and being lazy with some parsing

 

 

	for(Field f : Minecraft.class.getDeclaredFields())
		if(IMetadataSerializer.class == f.getType())
			try {
				f.setAccessible(true);
				((IMetadataSerializer)f.get(Minecraft.getMinecraft())).registerMetadataSectionType(new SpriteSerializer(), Sprite.class);
				break;
			} catch (Exception e) {
				e.printStackTrace();
			}

 

 

Once again works perfectly, just wondering if there's anything cleaner that I've missed

I think its my java of the variables.

Link to comment
Share on other sites

I have some explanation of ways to access resources here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-modding-tips_9.html

 

The key point is that Minecraft has a resource manager class that provides various methods. One of the methods gets all the resources: Minecraft.getMinecraft().getResourceManager().getAllResources(). I think it maybe can help do what you want.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thanks for the response!

 

I've read through the IResourcePack handling and it's not what I'm looking for unfortunately... IResourcePack is used to add a new Resource Locale, such as a new type of compressed file or a fed byte stream for a given domain, but that won't provide any existing resource packs' (selected/server/default) file list... I actually need to handle the IResourcePack so I can look through the files inside of it

 

At this point it's looking like I'm going to need to use some reflection to grab the fallback resource manager for my domain at SimpleReloadableResourceManager#domainResourceManagers, reflect into that fallback resource manager to get FallbackResourceManager#resourcePacks to iterate through so I can run a switch by the type of IResourcePack in it to access the files in the location.

i.e. AbstractResourcePack#resourcePackFile  && DefaultResourcePack#mapAssets

 

Thankfully it appears that the FallbackResourceManager has the resource packs listed in the order of importance.

 

Once I have my list of files I'll be able to split their paths so I can create their correlating resource locations and feed them back into the game.

I think its my java of the variables.

Link to comment
Share on other sites

I didn't say to look at IResourcePack. I said to look at the resource manager, which works on resource locations. It is the same thing that Minecraft uses to find all the block models, entity models, textures, etc. It looks in a folder and gives a List of all the resources in it.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I didn't say to look at IResourcePack. I said to look at the resource manager, which works on resource locations. It is the same thing that Minecraft uses to find all the block models, entity models, textures, etc. It looks in a folder and gives a List of all the resources in it.

Actually the resource packs do all of the manual lifting, ResourceManager just queires the loaded resource pack instances. My issue with getting a directory is that the IResourcePacks will only return files to the ResourceManager, directories churn out null values aplenty.

 

Got it 100% working with the dynamic texture loading. Basic premise is:

/* boolean code at play */ 
List<IResourcePack> packs = Minecraft.getMinecraft().getResourceManager().domainResourceManagers.get(MyMod.ID).resourcePacks;
for(IResourcePack pack: packs) // Invert the list parsing. FallbackResourceManager#resourcePacks is kept in reverse order
    if(pack instanceof AbstractResourcePack){
        List<String> locations = parseDirectory(pack.resourcePackFile);
        if(locations.size() > 0)
            for(String s: locations)
                TextureMap.registerSprite(new ResourceLocation(MyMod.ID, s));
        else
            continue; 
        break; //So we don't load more textures once we've picked up the first resource pack that contains them.
    }

Quite a few bits of reflection in the non boolean code but it works perfectly. Probably a bit of lag during texture loading added since I have to compare against all of the entries in a zipped texture pack.

 

If anyone wants to read through my actual code for this just let me know.

I think its my java of the variables.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.