Jump to content

[1.12.2] Retexturing IModel


Recommended Posts


I want to retexture my IModel, but the thing is I just end up with the 'missing texture' texture.

I've been stuck with this problem for hours now, soo any help would be appreciated :)





package com.thetrollguy.traffic_stuff_mod.feature.cone.client;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;

import javax.annotation.Nullable;
import javax.vecmath.Tuple4f;
import javax.vecmath.Vector4f;

import com.google.common.collect.ImmutableMap;
import com.thetrollguy.traffic_stuff_mod.feature.BlockAdaptable;
import com.thetrollguy.traffic_stuff_mod.feature.BlockTrafficStuffMod;
import com.thetrollguy.traffic_stuff_mod.feature.EnumBlockAdaptationType;
import com.thetrollguy.traffic_stuff_mod.feature.cone.BlockCone;
import com.thetrollguy.traffic_stuff_mod.feature.cone.ConeColor;
import com.thetrollguy.traffic_stuff_mod.feature.cone.ConePosition;
import com.thetrollguy.traffic_stuff_mod.feature.cone.ConeShape;
import com.thetrollguy.traffic_stuff_mod.utils.Info;
import com.thetrollguy.traffic_stuff_mod.utils.Utils;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.client.model.pipeline.VertexTransformer;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.property.IExtendedBlockState;

public class BakedModelCone implements IBakedModel {
	public static HashMap<String, List<BakedQuad>> QUADS = new HashMap<String, List<BakedQuad>>();

	private IModel model;
	private boolean retextured = false;
	private IModelState modelState;                                           // *THE JUNK* Is there any way
	private VertexFormat vertexFormat;                                        // to make this tidy and not pass
	private Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter;// a bunch of objects to the construcor?
	public BakedModelCone(IModel model, IModelState modelState, VertexFormat vertexFormat, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
		this.model = model;
		this.modelState = modelState;
		this.vertexFormat = vertexFormat;
		this.bakedTextureGetter = bakedTextureGetter;

	public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long random)
		ConeColor color = ((BlockCone) state.getBlock()).color;
		List<BakedQuad> quads = new LinkedList<BakedQuad>();
		if (!retextured)
			this.model = model.retexture(
				ImmutableMap.of("particle",  "traffic_stuff_mod:textures/blocks/cone/cone_" + color + "_particle", 
				 				"primary",   "traffic_stuff_mod:textures/blocks/cone/cone_" + color, 
				 				"secondary", "traffic_stuff_mod:textures/blocks/cone/cone_" + color.getSecondaryColor()));
			this.retextured = true;		
		if (state instanceof IExtendedBlockState)
			ConeShape shape = ((BlockCone) state.getBlock()).shape;
			ConePosition position = state.getValue(BlockCone.POSITION);
			EnumBlockAdaptationType type = ((IExtendedBlockState) state).getValue(BlockAdaptable.ADAPTATION_TYPE);
			String key = Utils.String.combineToString(shape, color, position, type);

			if (QUADS.containsKey(key))
				return QUADS.get(key);
				IBakedModel bakedModel = model.bake(modelState, vertexFormat, bakedTextureGetter);
				float heightReduction = ((IExtendedBlockState) state).getValue(BlockAdaptable.ADAPTATION_TYPE).heightReduction;
				for (BakedQuad quad : bakedModel.getQuads(state, side, random))
					quads.add(translate(quad, shape.getTranslationVector(position, heightReduction)));				
				QUADS.put(key, quads);
		return quads;

	protected static BakedQuad translate(BakedQuad quad, Vector4f translationVector)
		UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.ITEM);

		quad.pipe(new VertexTransformer(builder)
			public void put(int element, float... data)
				VertexFormatElement formatElement = DefaultVertexFormats.ITEM.getElement(element);
				if (formatElement.getUsage() == VertexFormatElement.EnumUsage.POSITION)
					float[] newData = new float[4];
					Vector4f vec = new Vector4f(data);
					this.parent.put(element, newData);
					this.parent.put(element, data);	
		return builder.build();

	public boolean isAmbientOcclusion() {
		return true;

	public boolean isGui3d() {
		return true;

	public boolean isBuiltInRenderer() {
		return false;

	public ItemOverrideList getOverrides() {
		return null;

	public TextureAtlasSprite getParticleTexture() {
		// TODO Auto-generated method stub
		return null;




Link to comment
Share on other sites

  • 2 weeks later...

Thanks diesieben07!

Now another thing that makes zero sense to me related to IBakedModel.


The method getQuads accepts EnumFacing as one of its arguments. While I was experimenting with something, I found out that sometimes, when the method gets called, null gets passed as the EnumFacing argument. Why is that? I know that if IBlockState argument is null, the quads are for an item model.


The reason is written on the Forge Docs: mcforge.readthedocs.io/en/latest/models/advanced/ibakedmodel/#getquads

Edited by TheTrollguy_
Found the answer
Link to comment
Share on other sites

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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.