Jump to content

[SOLVED] 1.11.2 Forge - Missing texture when adding a sprite


Zeher_Monkey

Recommended Posts

I have created a new fluid, and the texture for that fluid isnt being loaded by the game properly. Minecraft is supposed to add fluid textures to the TextureMap, but when it adds my textures it just returns as "missingno". Ive tried adding the sprites manually too, but that isnt working either. Any help is much appreiciated.

 

EventHub:

Spoiler

package com.zeher.orecraft.client.event;

import java.util.ArrayList;
import java.util.Map.Entry;

import com.google.common.collect.Lists;
import com.zeher.orecraft.OreCraft;
import com.zeher.orecraft.client.model.baked.BakedFluidTankFluidModel;
import com.zeher.orecraft.client.model.baked.BakedFluidTankModel;
import com.zeher.orecraft.core.handlers.BlockHandlerOreCraft;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistrySimple;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public final class OreCraftEventHub
{
    
    @SubscribeEvent
    public void onModelBakeEvent(ModelBakeEvent event)
    {
        // generate fluid models for all registered fluids for 16 levels each
        
        Fluid fluid;
        IBakedModel[] bakedFluidModels;
        
        for (Entry<String, Fluid> entry : FluidRegistry.getRegisteredFluids().entrySet())
        {
            fluid = entry.getValue();
            
            bakedFluidModels = new IBakedModel[BakedFluidTankModel.FLUID_LEVELS];
            
            for (int x = 0; x < BakedFluidTankModel.FLUID_LEVELS; x++)
            {
                bakedFluidModels[x] = new BakedFluidTankFluidModel(fluid, x + 1);
            }
            
            BakedFluidTankModel.FLUID_MODELS.put(entry.getKey(), bakedFluidModels);
        }
        
        // get ModelResourceLocations of all tank block variants from the registry except "inventory"
        
        RegistrySimple<ModelResourceLocation, IBakedModel> registry = (RegistrySimple)event.getModelRegistry();
        ArrayList<ModelResourceLocation> modelLocations = Lists.newArrayList();
        
        // as of 1.11.2 (maybe earlier) all resource names must be all lower case
        String modelPath = "block_fluidtank_basic";
        
        for (ModelResourceLocation modelLoc : registry.getKeys())
        {
            if (modelLoc.getResourceDomain().equals(OreCraft.mod_id)
                && modelLoc.getResourcePath().equals(modelPath)
                && !modelLoc.getVariant().equals("inventory"))
            {
                modelLocations.add(modelLoc);
            }
        }
        
        // replace the registered tank block variants with BakedTankModels
        
        IBakedModel registeredModel;
        IBakedModel replacementModel;
        
        for (ModelResourceLocation loc : modelLocations)
        {
            registeredModel = event.getModelRegistry().getObject(loc);
            replacementModel = new BakedFluidTankModel(registeredModel);
            event.getModelRegistry().putObject(loc, replacementModel);
        }
    }
    
    @SubscribeEvent
    public void registerTextures(final TextureStitchEvent.Pre event){
        System.out.println("--------LOAD TEXTURES");
        event.getMap().registerSprite(new ResourceLocation(OreCraft.mod_id + ":" + "blocks/block_fluid/coolant/coolant_flow"));
        event.getMap().registerSprite(new ResourceLocation(OreCraft.mod_id + ":" + "blocks/block_fluid/coolant/coolant_still"));
        
        
        
    }
    
    @SubscribeEvent
    public void registerTextures(final TextureStitchEvent.Post event){
        System.out.println("--------CHECK TEXTURES");
        //event.getMap().registerSprite(new ResourceLocation(OreCraft.mod_id + ":" + "blocks/block_fluid/coolant/coolant_flow"));
        //event.getMap().registerSprite(new ResourceLocation(OreCraft.mod_id + ":" + "blocks/block_fluid/coolant/coolant_still"));
        TextureAtlasSprite texture_sprite = event.getMap().getAtlasSprite("orecraft:blocks/block/block_fluid/coolant/coolant_flow");
        
        if(texture_sprite != null){
            System.out.println(texture_sprite.getIconName() + " ----------- What");
        }
    }
}
 

 

FluidHandler:

Spoiler

package com.zeher.orecraft.core.handlers;

import com.zeher.trzcore.fluid.TRZBlockFluid;
import com.zeher.trzcore.fluid.TRZFluid;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class FluidHandlerOreCraft {
    
    public static ResourceLocation test = new ResourceLocation("tconstruct:blocks/fluids/molten_metal");
    public static ResourceLocation coolant_still = new ResourceLocation("orecraft:blocks/block_fluid/coolant/coolant_still.png");
    public static ResourceLocation coolant_flow = new ResourceLocation("orecraft:blocks/block_fluid/coolant/coolant_flow.png");
    
    
    public static void preInit(){
        final Fluid coolant = new Fluid("coolant", coolant_still, coolant_flow);
        coolant.setUnlocalizedName("coolant").setDensity(FluidRegistry.getFluid("water").getDensity());
        //coolant.setBlock(BlockHandlerOreCraft.block_fluid_coolant).setUnlocalizedName(BlockHandlerOreCraft.block_fluid_coolant.getUnlocalizedName());
        registerFluid(coolant);
        
        
    }
    
    public static void register(){
    }
    
    public static void registerFluid(Fluid fluid){
        FluidRegistry.registerFluid(fluid);
        FluidRegistry.addBucketForFluid(fluid);
    }
    
}
 

 

Edited by Zeher_Monkey
Link to comment
Share on other sites

  • 8 months later...

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.