InternalResourcePack.java
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.mumfrey.liteloader.resources;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.data.IMetadataSection;
import net.minecraft.client.resources.data.IMetadataSerializer;
import net.minecraft.util.ResourceLocation;
/**
* Resource pack which returns resources using Class::getResourceAsStream() on the specified class
*
* @author Adam Mummery-Smith
*/
public class InternalResourcePack implements IResourcePack
{
/**
* Domains supported by this resource pack
*/
private final Set<String> resourceDomains = new HashSet<String>();
/**
* Name of this resource pack
*/
private final String packName;
/**
* Class to execute getResourceAsStream() upon
*/
private final Class<?> resourceClass;
/**
* @param name
* @param resourceClass
* @param domains
*/
public InternalResourcePack(String name, Class<?> resourceClass, String... domains)
{
if (domains.length < 1) throw new IllegalArgumentException("No domains specified for internal resource pack");
this.packName = name;
this.resourceClass = resourceClass;
for (String domain : domains)
this.resourceDomains.add(domain);
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#getInputStream(net.minecraft.util.ResourceLocation)
*/
@Override
public InputStream getInputStream(ResourceLocation resourceLocation) throws IOException
{
return this.getResourceStream(resourceLocation);
}
/**
* @param resourceLocation
*/
private InputStream getResourceStream(ResourceLocation resourceLocation)
{
return this.resourceClass.getResourceAsStream(String.format("/assets/%s/%s", resourceLocation.getResourceDomain(), resourceLocation.getResourcePath()));
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#resourceExists(net.minecraft.util.ResourceLocation)
*/
@Override
public boolean resourceExists(ResourceLocation resourceLocation)
{
return this.getResourceStream(resourceLocation) != null;
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#getResourceDomains()
*/
@Override
public Set<String> getResourceDomains()
{
return this.resourceDomains;
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#getPackMetadata(net.minecraft.client.resources.data.IMetadataSerializer, java.lang.String)
*/
@Override
public IMetadataSection getPackMetadata(IMetadataSerializer par1MetadataSerializer, String par2Str) throws IOException
{
return null;
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#getPackImage()
*/
@Override
public BufferedImage getPackImage() throws IOException
{
return null;
}
/* (non-Javadoc)
* @see net.minecraft.client.resources.IResourcePack#getPackName()
*/
@Override
public String getPackName()
{
return this.packName;
}
}