Jump to content

IResourcePack explanation


Dijkstra

Recommended Posts

I have been told if need save resources outside of my mod i will need to use IResourcePack so i made a new class that implements it, it added a lot of new methods but i do not know what any of them mean so if some one could tell what needs to been done with these methods so that I use resources outside of my mod that would be great. Also i would like to know how this be wired up.

 

 

public class resources implements IResourcePack{

@Override
public InputStream getInputStream(ResourceLocation p_110590_1_)
		throws IOException {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean resourceExists(ResourceLocation p_110589_1_) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public Set getResourceDomains() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_,
		String p_135058_2_) throws IOException {
	// TODO Auto-generated method stub
	return null;
}

@Override
public BufferedImage getPackImage() throws IOException {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getPackName() {
	// TODO Auto-generated method stub
	return null;
}

}

 

Link to comment
Share on other sites

Hello i would just like to note one thing, do not take it the wrong but it may be self explanatory to you but you probably used it a lot, i have not so do not know where to start.

 

I think there one that i get  which is getPackName() i am guessing that is any sting i like. but the others i have no idea where to start it would be nice if you could explain what each one does maybe an example and explain how what you put affect the outcomes. 

Link to comment
Share on other sites

Also - if you have problem writing implementation of those - look type hierarchy on IResourcePack - especially FileResourcePack which can load .zip/.jar files as ResourcePacks (yes, its ready-to-use, and I recomment using this, instead of loading e.g non-zipped folder structure).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

 

public class resources implements IResourcePack{

private String playerName = Minecraft.getMinecraft().thePlayer.getDisplayName();
Class AbstractResourcePack = AbstractResourcePack.class;
public static void load(){
	File directory = new File("Wardrobe/Players");
	if (!directory.exists()) {
            try {
                directory.mkdirs();
            } catch (SecurityException secEx) {
                secEx.printStackTrace(System.out);
                directory = null;
            }
        }
	File pack = new File("Wardrobe/pack.mcmeta");
	if(!pack.exists()){
		try {
			pack.createNewFile();
			String[] text = new String[]{"{",
				   "\"pack\":{",
			      "\"pack_format\":1",
			      "\"description\":\"Current Player's Skins\"",
			   "}",
			"}"};
			BufferedWriter bw = new BufferedWriter(new FileWriter("Wardrobe/pack.mcmeta"));
			for(int i = 0; i<text.length-1; i++){
				bw.write(text[i]);
				bw.newLine();
				bw.flush();
			}
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}

@Override
public InputStream getInputStream(ResourceLocation p_110590_1_) throws IOException {
	return DefaultResourcePack.class.getResourceAsStream("Wardrobe/Players/"+p_110590_1_.getResourcePath()+".png");
}
@Override
public boolean resourceExists(ResourceLocation p_110589_1_) {
	return new File("Wardrode/PLayers/"+p_110589_1_.getResourcePath()+".png").exists();
}

@Override
public Set getResourceDomains() {
	return ImmutableSet.of("skins");
}
@Override
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_) throws IOException {
	try {
		Method readMetadata = AbstractResourcePack.class.getMethod("readMetadata", new Class[]{IMetadataSerializer.class, InputStream.class, String.class});
		readMetadata.setAccessible(true);
		FileInputStream fileinputstream =  new FileInputStream(new File("Wardrobe/pack.mcmeta"));
		IMetadataSection returnValue;
		returnValue = (IMetadataSection) readMetadata.invoke(null, p_135058_1_, fileinputstream, p_135058_2_);
		return returnValue;
	}
	catch(Exception e){	
		return null;
	}
}
@Override
public BufferedImage getPackImage() throws IOException {
	return ImageIO.read(DefaultResourcePack.class.getResourceAsStream("/" + (new ResourceLocation("pack.png")).getResourcePath()));
}

@Override
public String getPackName() {
	return "Skins";
}
public static File getMcDir()
{
	if (MinecraftServer.getServer() != null && MinecraftServer.getServer().isDedicatedServer())
	{
		return new File(".");
	}
	return Minecraft.getMinecraft().mcDataDir;
}
}

 

 

Here is my code i assume it is fine, but it will not load unless i tell it to right, i want to know how to get it load, so that would be do in an another file right, like linking up an event handlers.

Link to comment
Share on other sites

 

public class resources implements IResourcePack{
public static void load(){
	File directory = new File("Wardrobe/Players");
	if (!directory.exists()) {
            try {
                directory.mkdirs();
            } catch (SecurityException secEx) {
                secEx.printStackTrace(System.out);
                directory = null;
            }
        }
	File pack = new File("Wardrobe/pack.mcmeta");
	if(!pack.exists()){
		try {
			pack.createNewFile();
			String[] text = new String[]{"{",
				   "\"pack\":{",
			      "\"pack_format\":1",
			      "\"description\":\"Current Player's Skins\"",
			   "}",
			"}"};
			BufferedWriter bw = new BufferedWriter(new FileWriter("Wardrobe/pack.mcmeta"));
			for(int i = 0; i<text.length-1; i++){
				bw.write(text[i]);
				bw.newLine();
				bw.flush();
			}
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	try {
		Field defaultResourcePacks = Minecraft.class.getDeclaredField("defaultResourcePacks");
		defaultResourcePacks.setAccessible(true);
		List packs = (List) defaultResourcePacks.get(Minecraft.getMinecraft());
		packs.add(new resources());
		defaultResourcePacks.set(Minecraft.getMinecraft(), packs);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
@Override
public InputStream getInputStream(ResourceLocation p_110590_1_) throws IOException {
	return DefaultResourcePack.class.getResourceAsStream("Wardrobe/Players/"+p_110590_1_.getResourcePath()+".png");
}
@Override
public boolean resourceExists(ResourceLocation p_110589_1_) {
	return new File("Wardrode/PLayers/"+p_110589_1_.getResourcePath()+".png").exists();
}

@Override
public Set getResourceDomains() {
	return ImmutableSet.of("skins");
}
@Override
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_) throws IOException {
	try {
		Method readMetadata = AbstractResourcePack.class.getMethod("readMetadata", new Class[]{IMetadataSerializer.class, InputStream.class, String.class});
		readMetadata.setAccessible(true);
		FileInputStream fileinputstream =  new FileInputStream(new File("Wardrobe/pack.mcmeta"));
		IMetadataSection returnValue;
		returnValue = (IMetadataSection) readMetadata.invoke(null, p_135058_1_, fileinputstream, p_135058_2_);
		return returnValue;
	}
	catch(Exception e){	
		return null;
	}
}
@Override
public BufferedImage getPackImage() throws IOException {
	return ImageIO.read(DefaultResourcePack.class.getResourceAsStream("/" + (new ResourceLocation("pack.png")).getResourcePath()));
}

@Override
public String getPackName() {
	return "Skins";
}
public static File getMcDir()
{
	if (MinecraftServer.getServer() != null && MinecraftServer.getServer().isDedicatedServer())
	{
		return new File(".");
	}
	return Minecraft.getMinecraft().mcDataDir;
}
}

 

 

I have put my pack in the defaultResourcePacks list and removed the line from top which gets the player name as it not use, but for lot wrong you are going have tell what is wrong as it looks fine to me.

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.