实现了加载外部的贴图,已经可以在药水UI上使用,
部分代码:
但是不知道如何让物品也可以使用到这样的贴图。
希望各位带哥指条明路。
部分代码:
但是不知道如何让物品也可以使用到这样的贴图。
希望各位带哥指条明路。
本帖最后由 roj234 于 2019-5-13 19:47 编辑
复制代码复制代码复制代码复制代码
engine.bindTexture(k);
}
}
}
刚刚手写的有点错误已经修改好了
对了怎么折叠?
用法:
1 TextureLoader.add("modid", "type", "name", InputStream);
2 new TextureLoader();
示例(这里是MC的石头)
TextureLoader.add("minecraft", "blocks", "stone", InputStream);
InputStream是图片
PPPS破烂MCBBS编辑器
- Filename: Textureloader.java
- Filename: WebTexture.java
- package mi.util.client.texture;
- import mi.MI;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.io.InputStream;
- import net.minecraft.client.renderer.texture.AbstractTexture;
- import net.minecraft.client.renderer.texture.TextureUtil;
- import net.minecraft.client.resources.IResource;
- import net.minecraft.client.resources.IResourceManager;
- import net.minecraft.client.resources.data.TextureMetadataSection;
- import net.minecraft.util.ResourceLocation;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import org.apache.commons.io.IOUtils;
- @SideOnly(Side.CLIENT)
- public class WebTexture
- extends AbstractTexture
- {
- protected final ResourceLocation textureLocation;
- private final InputStream is;
- public WebTexture(ResourceLocation loc, InputStream image)
- {
- this.textureLocation = loc;
- this.is = image;
- }
- public void loadTexture(IResourceManager man)
- throws IOException
- {
- deleteGlTexture();
- IResource res = null;
- try
- {
- res = man.getResource(this.textureLocation);
- BufferedImage img = TextureUtil.readBufferedImage(is);
- boolean blur = false;
- boolean clamp = false;
- if (res.hasMetadata()) {
- try
- {
- TextureMetadataSection meta = (TextureMetadataSection)res.getMetadata("texture");
- if (meta != null)
- {
- blur = meta.getTextureBlur();
- clamp = meta.getTextureClamp();
- }
- }
- catch (RuntimeException e)
- {
- MI.logger().warn("Failed reading metadata of: "+this.textureLocation,e);
- }
- }
- TextureUtil.uploadTextureImageAllocate(getGlTextureId(), img, blur, clamp);
- }
- finally
- {
- IOUtils.closeQuietly(res);
- }
- }
- }
- package mi.util.client.texture;
- import mi.Config;
- import mi.util.ReflectionHelper;
- import net.minecraft.client.renderer.texture.TextureManager;
- import net.minecraft.client.resources.*;
- import net.minecraft.client.Minecraft;
- import net.minecraft.util.ResourceLocation;
- import java.io.*;
- import java.util.*;
- public final class TextureLoader implements IResourceManagerReloadListener{
- private static TextureManager engine;
- private static final Map<ResourceLocation, InputStream> data = new HashMap<ResourceLocation, InputStream>();
- private static Map<String, FallbackResourceManager> resMap;
-
- public TextureLoader() {
- //engine = FMLClientHandler.instance().getClient().renderEngine;
- engine = Minecraft.getMinecraft().getTextureManager();
-
- IReloadableResourceManager man;
- try{
- if(Config.isMDKEnviroment)
- man = (IReloadableResourceManager)ReflectionHelper.getPrivateField(engine, "resourceManager");
- else
- man = (IReloadableResourceManager)ReflectionHelper.getPrivateField(engine, "field_110582_d");
- }catch(Exception e){
- e.printStackTrace();
- throw new RuntimeException("TextureManager get failed");
- }
- man.registerReloadListener(this);
-
- onResourceManagerReload(man);
- }
- public static InputStream getStreamByLoc(ResourceLocation resloc) throws IOException{
- if (resloc.getPath().contains("..")) {
- throw new IOException("Invalid relative path to resource: " + resloc);
- }
- FallbackResourceManager man = resMap.get(resloc.getNamespace());
- if (man != null) {
- List<IResourcePack> resourcePacks;
- try{
- if(Config.isMDKEnviroment)
- resourcePacks = (List<IResourcePack>)ReflectionHelper.getPrivateField(man, "resourcePacks");
- else
- resourcePacks = (List<IResourcePack>)ReflectionHelper.getPrivateField(man, "field_110540_a");
- }catch(Exception e){
- throw new IOException("Resourcepack get failed");
- }
- IResourcePack pack = null;
- for (int i = resourcePacks.size() - 1; i >= 0; i--) {
- pack = resourcePacks.get(i);
-
- if (pack.resourceExists(resloc)) {
- return pack.getInputStream(resloc);
- }
- }
- }
- throw new FileNotFoundException("TextureNotFoundException: "+resloc.toString());
- }
-
- @Override
- public void onResourceManagerReload(IResourceManager man){
- try{
- if(Config.isMDKEnviroment)
- resMap = (Map<String, FallbackResourceManager>)ReflectionHelper.getPrivateField(man, "domainResourceManagers");
- else
- resMap = (Map<String, FallbackResourceManager>)ReflectionHelper.getPrivateField(man, "field_110548_a");
- }catch(Exception e){
- e.printStackTrace();
- //throw new AntiCheatException("Texture map get failed");
- }
- loadAll();
- bindAll();
- }
-
- public static void add(String modid, String type, String name ,InputStream stream){
- data.put(new ResourceLocation(modid, "textures/"+type+"/"+name+".png"), stream);
- }
-
- public static void loadAll(){
- for(Map.Entry<ResourceLocation, InputStream> entry : data.entrySet()){
- engine.loadTexture(entry.getKey(), new WebTexture(entry.getKey(), entry.getValue()));
- }
- }
-
- public static void bindAll(){
- for(ResourceLocation k : data.keySet()){
engine.bindTexture(k);
}
}
}
刚刚手写的有点错误已经修改好了
对了怎么折叠?
用法:
1 TextureLoader.add("modid", "type", "name", InputStream);
2 new TextureLoader();
示例(这里是MC的石头)
TextureLoader.add("minecraft", "blocks", "stone", InputStream);
InputStream是图片
PPPS破烂MCBBS编辑器
至于吗,都动上反射了?ModelLoader.setCustomModelResourceLocation或者ModelBakeryEvent,了解一下。
森林蝙蝠 发表于 2019-5-13 19:37
至于吗,都动上反射了?ModelLoader.setCustomModelResourceLocation或者ModelBakeryEvent,了解一下。 ...
- ResourceLocation resloc;
- if(item instanceof ItemBlock)
- {
- ItemBlock itemBlock = (ItemBlock) item;
- Block block = itemBlock.getBlock();
- resloc = block.getRegistryName();
- }else{
- resloc = item.getRegistryName();
- }
- ModelLoader.setCustomModelResourceLocation(item,meta,new ModelResourceLocation(resloc, "inventory"));
然后呢。。。怎么设置
roj234 发表于 2019-5-13 19:48
然后呢。。。怎么设置
不用ItemBlock,那个方法就是给物品用的。
本帖最后由 roj234 于 2019-5-13 19:54 编辑
直接Item.getRegistryName()?
不过我想的是上面的问题
这里只能设定模型文件而不是png
森林蝙蝠 发表于 2019-5-13 19:51
不用ItemBlock,那个方法就是给物品用的。
直接Item.getRegistryName()?
不过我想的是上面的问题
这里只能设定模型文件而不是png