Resource packs, part two. FML mods are now resource packs. Vanilla will scan anything under 'assets'
and turn it into a resource prefix. Use resourcelocations to look stuff up.
This commit is contained in:
parent
58a00d68a4
commit
5d0d45ea40
8 changed files with 157 additions and 7 deletions
|
@ -13,6 +13,7 @@
|
|||
package cpw.mods.fml.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -169,6 +170,8 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
try
|
||||
{
|
||||
Loader.instance().loadMods();
|
||||
// Reload resources
|
||||
client.func_110436_a();
|
||||
}
|
||||
catch (WrongMinecraftVersionException wrong)
|
||||
{
|
||||
|
@ -563,14 +566,24 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
@Override
|
||||
public void addModAsResource(ModContainer container)
|
||||
{
|
||||
File modSource = container.getSource();
|
||||
if (modSource.isFile())
|
||||
Class<?> resourcePackType = container.getCustomResourcePackClass();
|
||||
if (resourcePackType != null)
|
||||
{
|
||||
resourcePackList.add(new FileResourcePack(modSource));
|
||||
}
|
||||
else if (modSource.isDirectory())
|
||||
{
|
||||
resourcePackList.add(new FolderResourcePack(modSource));
|
||||
try
|
||||
{
|
||||
ResourcePack pack = (ResourcePack) resourcePackType.getConstructor(ModContainer.class).newInstance(container);
|
||||
resourcePackList.add(pack);
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
FMLLog.log(Level.SEVERE, "The container %s (type %s) returned an invalid class for it's resource pack.", container.getName(), container.getClass().getName());
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.log(Level.SEVERE, e, "An unexpected exception occurred constructing the custom resource pack for %s", container.getName());
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
53
fml/client/cpw/mods/fml/client/FMLFileResourcePack.java
Normal file
53
fml/client/cpw/mods/fml/client/FMLFileResourcePack.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package cpw.mods.fml.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
|
||||
import net.minecraft.client.resources.FileResourcePack;
|
||||
|
||||
public class FMLFileResourcePack extends FileResourcePack {
|
||||
|
||||
private ModContainer container;
|
||||
|
||||
public FMLFileResourcePack(ModContainer container)
|
||||
{
|
||||
super(container.getSource());
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String func_130077_b()
|
||||
{
|
||||
return "FMLFileResourcePack:"+container.getName();
|
||||
}
|
||||
@Override
|
||||
protected InputStream func_110591_a(String resourceName) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.func_110591_a(resourceName);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if ("pack.mcmeta".equals(resourceName))
|
||||
{
|
||||
FMLLog.log(container.getName(), Level.WARNING, "Mod %s is missing a pack.mcmeta file, things may not work well", container.getName());
|
||||
return new ByteArrayInputStream(("{\n" +
|
||||
" \"pack\": {\n"+
|
||||
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
|
||||
" \"pack_format\": 1\n"+
|
||||
"}\n" +
|
||||
"}").getBytes(Charsets.UTF_8));
|
||||
}
|
||||
else throw ioe;
|
||||
}
|
||||
}
|
||||
}
|
52
fml/client/cpw/mods/fml/client/FMLFolderResourcePack.java
Normal file
52
fml/client/cpw/mods/fml/client/FMLFolderResourcePack.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package cpw.mods.fml.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.client.resources.FolderResourcePack;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
|
||||
public class FMLFolderResourcePack extends FolderResourcePack {
|
||||
|
||||
private ModContainer container;
|
||||
|
||||
public FMLFolderResourcePack(ModContainer container)
|
||||
{
|
||||
super(container.getSource());
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String func_130077_b()
|
||||
{
|
||||
return "FMLFileResourcePack:"+container.getName();
|
||||
}
|
||||
@Override
|
||||
protected InputStream func_110591_a(String resourceName) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.func_110591_a(resourceName);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if ("pack.mcmeta".equals(resourceName))
|
||||
{
|
||||
FMLLog.log(container.getName(), Level.WARNING, "Mod %s is missing a pack.mcmeta file, things may not work well", container.getName());
|
||||
return new ByteArrayInputStream(("{\n" +
|
||||
" \"pack\": {\n"+
|
||||
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
|
||||
" \"pack_format\": 1\n"+
|
||||
"}\n" +
|
||||
"}").getBytes(Charsets.UTF_8));
|
||||
}
|
||||
else throw ioe;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -175,4 +175,9 @@ public class DummyModContainer implements ModContainer
|
|||
{
|
||||
return EMPTY_PROPERTIES;
|
||||
}
|
||||
@Override
|
||||
public Class<?> getCustomResourcePackClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -596,4 +596,17 @@ public class FMLModContainer implements ModContainer
|
|||
{
|
||||
return customModProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCustomResourcePackClass()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getSource().isDirectory() ? Class.forName("cpw.mods.fml.client.FMLFolderResourcePack", true, getClass().getClassLoader()) : Class.forName("cpw.mods.fml.client.FMLFileResourcePack",true, getClass().getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,4 +161,10 @@ public class InjectedModContainer implements ModContainer
|
|||
{
|
||||
return wrappedContainer.getCustomModProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCustomResourcePackClass()
|
||||
{
|
||||
return wrappedContainer.getCustomResourcePackClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,4 +136,6 @@ public interface ModContainer
|
|||
|
||||
public static final Map<String,String> EMPTY_PROPERTIES = ImmutableMap.of();
|
||||
Map<String,String> getCustomModProperties();
|
||||
|
||||
public Class<?> getCustomResourcePackClass();
|
||||
}
|
||||
|
|
|
@ -621,4 +621,10 @@ public class ModLoaderModContainer implements ModContainer
|
|||
{
|
||||
return EMPTY_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCustomResourcePackClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue