2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.client;
|
2013-07-02 15:11:50 +00:00
|
|
|
|
2013-07-10 19:47:13 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
2013-07-02 15:11:50 +00:00
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2017-07-13 04:50:28 +00:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2014-09-23 05:01:24 +00:00
|
|
|
|
2018-03-18 01:41:16 +00:00
|
|
|
import net.minecraftforge.fml.common.FMLLog;
|
2017-06-23 05:33:11 +00:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
2013-07-02 15:11:50 +00:00
|
|
|
|
2013-07-10 19:47:13 +00:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
2013-11-10 16:49:06 +00:00
|
|
|
import net.minecraft.client.resources.FileResourcePack;
|
2015-05-11 03:55:11 +00:00
|
|
|
import net.minecraftforge.fml.common.FMLContainerHolder;
|
2018-06-15 19:03:35 +00:00
|
|
|
import net.minecraftforge.fml.ModContainer;
|
2013-11-10 16:49:06 +00:00
|
|
|
|
2015-04-11 04:31:09 +00:00
|
|
|
public class FMLFileResourcePack extends FileResourcePack implements FMLContainerHolder {
|
2013-07-02 15:11:50 +00:00
|
|
|
|
|
|
|
private ModContainer container;
|
|
|
|
|
|
|
|
public FMLFileResourcePack(ModContainer container)
|
|
|
|
{
|
|
|
|
super(container.getSource());
|
|
|
|
this.container = container;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-19 07:15:53 +00:00
|
|
|
public String getPackName()
|
2013-07-02 15:11:50 +00:00
|
|
|
{
|
|
|
|
return "FMLFileResourcePack:"+container.getName();
|
|
|
|
}
|
|
|
|
@Override
|
2014-03-19 07:15:53 +00:00
|
|
|
protected InputStream getInputStreamByName(String resourceName) throws IOException
|
2013-07-02 15:11:50 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-03-19 07:15:53 +00:00
|
|
|
return super.getInputStreamByName(resourceName);
|
2013-07-02 15:11:50 +00:00
|
|
|
}
|
|
|
|
catch (IOException ioe)
|
|
|
|
{
|
|
|
|
if ("pack.mcmeta".equals(resourceName))
|
|
|
|
{
|
2018-03-18 01:41:16 +00:00
|
|
|
FMLLog.log.debug("Mod {} is missing a pack.mcmeta file, substituting a dummy one", container.getName());
|
2013-07-02 15:11:50 +00:00
|
|
|
return new ByteArrayInputStream(("{\n" +
|
|
|
|
" \"pack\": {\n"+
|
|
|
|
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
|
2016-11-16 06:59:31 +00:00
|
|
|
" \"pack_format\": 2\n"+
|
2013-07-02 15:11:50 +00:00
|
|
|
"}\n" +
|
2017-07-13 04:50:28 +00:00
|
|
|
"}").getBytes(StandardCharsets.UTF_8));
|
2013-07-02 15:11:50 +00:00
|
|
|
}
|
|
|
|
else throw ioe;
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 19:47:13 +00:00
|
|
|
|
|
|
|
@Override
|
2014-03-19 07:15:53 +00:00
|
|
|
public BufferedImage getPackImage() throws IOException
|
2013-07-10 19:47:13 +00:00
|
|
|
{
|
2014-03-19 07:15:53 +00:00
|
|
|
return ImageIO.read(getInputStreamByName(container.getMetadata().logoFile));
|
2013-07-10 19:47:13 +00:00
|
|
|
}
|
2015-04-11 04:31:09 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ModContainer getFMLContainer()
|
|
|
|
{
|
|
|
|
return container;
|
|
|
|
}
|
2013-07-02 15:11:50 +00:00
|
|
|
}
|