Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Retexturing IModel


TheTrollguy_
 Share

Recommended Posts

Hi,

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 :)

 

CODE:

 

Spoiler

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;
	}

	@Override
	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);
			}
			else
			{
				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)
		{
			@Override
			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);
					vec.add(translationVector);
					vec.get(newData);
					this.parent.put(element, newData);
				}
				else
				{
					this.parent.put(element, data);	
				}
			}
		});
		return builder.build();
	}

	@Override
	public boolean isAmbientOcclusion() {
		return true;
	}

	@Override
	public boolean isGui3d() {
		return true;
	}

	@Override
	public boolean isBuiltInRenderer() {
		return false;
	}


	@Override
	public ItemOverrideList getOverrides() {
		return null;
	}

	@Override
	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.

Guest
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I have been trying to download Forge but the Windows Installer isn't coming up, I can see the installer one would use for Linux but no Windows, I have downloaded Java and Jarfix but nothing is working, can someone help?  
    • So I thought that when a capability is attached to an item/entity/etc... the capability will stay until whatever it's attached to is gone. But this doesn't seem to be the case, as when I printed to console whenever a capability is attached, it seems as though a new version of the capability is attached to an item every time I select it in my hotbar, hover over it in inventory, etc. Is this how it's supposed to work? If so, why?
    • Hi, I'm trying to set up a simple forge server just to play with a couple of my friends, but no matter what I do or try I cannot seem to get a Mods folder and for the actual forge part of the server to actually launch. Every time I try to launch the forge.jar via a .bat file I just get a bunch of errors [Errors below] I'm not sure what I'm doing wrong. If I can get some help that would be awesome, thanks C:\Users\User\Desktop\Server>java -Xms2G -Xmx6G -jar forge-1.12.2-14.23.5.2855.jar nogui A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.base/java.lang.reflect.Method.invoke(Method.java:567)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')         at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more C:\Users\User\Desktop\Server>pause Press any key to continue . . .  
    • Is it ok if i ask what that is?
    • And just in case I also set the amount of RAM it can use in the gradle.properties file to org.gradle.jvmargs=-Xmx8G.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.