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

[1.12] Entity rendering as white cube


jonesto95
 Share

Recommended Posts

So I've been trying to add a race cart with a custom entity model, but the models come in as white cubes with no texture or collision. I've been looking at other tutorials for older versions to try and get this to work, but they lead me to deprecated methods and super constructors that take in more parameters than I can.

 

To begin, in the main mod class's preInit(), I register the entity using ModEntities.registerEntities():

public static void registerEntities()
	{
		registerEntity(EntityRaceCart.class, "race_cart", 64, 20, true);
	}
	
	private static void registerEntity(final Class<? extends Entity> entityClass, final String entityName, final int trackingRange, final int updateFrequency, final boolean sendsVelocityUpdates)
	{
		final ResourceLocation registryName = new ResourceLocation(MourningstarMod.MOD_ID, entityName);
		EntityRegistry.registerModEntity(registryName, entityClass, registryName.toString(), entityID++, MourningstarMod.instance, trackingRange, updateFrequency, sendsVelocityUpdates);
	}


Then in the main class's init() I use the Client proxy's init method to access the RenderingRegistry

@Override public void init()
	{		
		RenderingRegistry.registerEntityRenderingHandler(EntityRaceCart.class, renderManager -> new RenderRaceCart(renderManager));
	}

 

Here are my Entity, Model,  and Render classes for reference. The Render class is based heavily off of the RenderBoat class, as I want my entity to function similarly to a boat.

 

EntityRaceCart

Spoiler

package mourningstar.mourningstarmod.entity;

import javax.annotation.Nullable;

import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;

public class EntityRaceCart extends Entity {

	public EntityRaceCart(World worldIn) {
		super(worldIn);
        this.setSize(1.375F, 0.5625F);
	}

	public EntityRaceCart(World worldIn, double x, double y, double z) {
        this(worldIn);
        this.setPosition(x, y, z);
        this.motionX = 0.0D;
        this.motionY = 0.0D;
        this.motionZ = 0.0D;
        this.prevPosX = x;
        this.prevPosY = y;
        this.prevPosZ = z;
	}

	@Override
	protected void entityInit() {
		
	}

	@Override
	protected void readEntityFromNBT(NBTTagCompound compound) {
		
	}

	@Override
	protected void writeEntityToNBT(NBTTagCompound compound) {
		
	}

}

 

ModelRaceCart (generated from Qubble)

Spoiler

package mourningstar.mourningstarmod.client.model;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ModelRaceCart extends ModelBase {
	public ModelRenderer body;
    public ModelRenderer spoiler;
    public ModelRenderer tire2;
    public ModelRenderer tire1;
    public ModelRenderer tire3;
    public ModelRenderer tire4;

    public ModelRaceCart() {
        this.textureWidth = 256;
        this.textureHeight = 128;

        this.body = new ModelRenderer(this, 0, 0);
        this.body.setRotationPoint(-16.0F, -1.0F, 0.0F);
        this.body.addBox(0.0F, 0.0F, -18.0F, 64, 35, 36);
        this.spoiler = new ModelRenderer(this, 0, 0);
        this.spoiler.setRotationPoint(-16.0F, -0.3F, 0.0F);
        this.spoiler.addBox(0.0F, -2.3F, -7.0F, 1, 2, 14);
        this.setRotationAngles(this.spoiler, 0.0F, 0.0F, -0.33964105645913F);
        this.tire2 = new ModelRenderer(this, 0, 0);
        this.tire2.setRotationPoint(-8.0F, 5.0F, 9.0F);
        this.tire2.addBox(-3.0F, -3.0F, 0.0F, 6, 6, 1);
        this.setRotationAngles(this.tire2, 0.0F, 0.0F, 0.7853981633974483F);
        this.tire1 = new ModelRenderer(this, 0, 0);
        this.tire1.setRotationPoint(8.0F, 5.0F, 9.0F);
        this.tire1.addBox(-3.0F, -3.0F, 0.0F, 6, 6, 1);
        this.setRotationAngles(this.tire1, 0.0F, 0.0F, 0.7853981633974483F);
        this.tire3 = new ModelRenderer(this, 0, 0);
        this.tire3.setRotationPoint(8.0F, 5.0F, -10.0F);
        this.tire3.addBox(-3.0F, -3.0F, 0.0F, 6, 6, 1);
        this.setRotationAngles(this.tire3, 0.0F, 0.0F, 0.7853981633974483F);
        this.tire4 = new ModelRenderer(this, 0, 0);
        this.tire4.setRotationPoint(-8.0F, 5.0F, -10.0F);
        this.tire4.addBox(-3.0F, -3.0F, 0.0F, 6, 6, 1);
        this.setRotationAngles(this.tire4, 0.0F, 0.0F, 0.7853981633974483F);
    }

    @Override
    public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float rotationYaw, float rotationPitch, float scale) {
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.body.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.pushMatrix();
        GlStateManager.translate(this.spoiler.offsetX, this.spoiler.offsetY, this.spoiler.offsetZ);
        GlStateManager.translate(this.spoiler.rotationPointX * scale, this.spoiler.rotationPointY * scale, this.spoiler.rotationPointZ * scale);
        GlStateManager.scale(0.5F, 1.3F, 1.1F);
        GlStateManager.translate(-this.spoiler.offsetX, -this.spoiler.offsetY, -this.spoiler.offsetZ);
        GlStateManager.translate(-this.spoiler.rotationPointX * scale, -this.spoiler.rotationPointY * scale, -this.spoiler.rotationPointZ * scale);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.spoiler.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
        GlStateManager.pushMatrix();
        GlStateManager.translate(this.tire2.offsetX, this.tire2.offsetY, this.tire2.offsetZ);
        GlStateManager.translate(this.tire2.rotationPointX * scale, this.tire2.rotationPointY * scale, this.tire2.rotationPointZ * scale);
        GlStateManager.scale(0.9F, 0.9F, 1.0F);
        GlStateManager.translate(-this.tire2.offsetX, -this.tire2.offsetY, -this.tire2.offsetZ);
        GlStateManager.translate(-this.tire2.rotationPointX * scale, -this.tire2.rotationPointY * scale, -this.tire2.rotationPointZ * scale);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.tire2.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
        GlStateManager.pushMatrix();
        GlStateManager.translate(this.tire1.offsetX, this.tire1.offsetY, this.tire1.offsetZ);
        GlStateManager.translate(this.tire1.rotationPointX * scale, this.tire1.rotationPointY * scale, this.tire1.rotationPointZ * scale);
        GlStateManager.scale(0.9F, 0.9F, 1.0F);
        GlStateManager.translate(-this.tire1.offsetX, -this.tire1.offsetY, -this.tire1.offsetZ);
        GlStateManager.translate(-this.tire1.rotationPointX * scale, -this.tire1.rotationPointY * scale, -this.tire1.rotationPointZ * scale);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.tire1.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
        GlStateManager.pushMatrix();
        GlStateManager.translate(this.tire3.offsetX, this.tire3.offsetY, this.tire3.offsetZ);
        GlStateManager.translate(this.tire3.rotationPointX * scale, this.tire3.rotationPointY * scale, this.tire3.rotationPointZ * scale);
        GlStateManager.scale(0.9F, 0.9F, 1.0F);
        GlStateManager.translate(-this.tire3.offsetX, -this.tire3.offsetY, -this.tire3.offsetZ);
        GlStateManager.translate(-this.tire3.rotationPointX * scale, -this.tire3.rotationPointY * scale, -this.tire3.rotationPointZ * scale);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.tire3.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
        GlStateManager.pushMatrix();
        GlStateManager.translate(this.tire4.offsetX, this.tire4.offsetY, this.tire4.offsetZ);
        GlStateManager.translate(this.tire4.rotationPointX * scale, this.tire4.rotationPointY * scale, this.tire4.rotationPointZ * scale);
        GlStateManager.scale(0.9F, 0.9F, 1.0F);
        GlStateManager.translate(-this.tire4.offsetX, -this.tire4.offsetY, -this.tire4.offsetZ);
        GlStateManager.translate(-this.tire4.rotationPointX * scale, -this.tire4.rotationPointY * scale, -this.tire4.rotationPointZ * scale);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 0.0F);
        this.tire4.render(scale);
        GlStateManager.disableBlend();
        GlStateManager.popMatrix();
    }

    public void setRotationAngles(ModelRenderer modelRenderer, float x, float y, float z) {
        modelRenderer.rotateAngleX = x;
        modelRenderer.rotateAngleY = y;
        modelRenderer.rotateAngleZ = z;
    }
    
}

 

 

RenderRaceCart

Spoiler

package mourningstar.mourningstarmod.client.render;

import mourningstar.mourningstarmod.client.model.ModelRaceCart;
import mourningstar.mourningstarmod.entity.EntityRaceCart;
import net.minecraft.client.model.IMultipassModel;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.client.registry.IRenderFactory;

public class RenderRaceCart extends Render<EntityRaceCart>{

	private static final ResourceLocation TEXTURE = new ResourceLocation("textures/entity/race_cart.png");
	protected ModelBase modelRaceCart = new ModelRaceCart();
	
	public RenderRaceCart(RenderManager renderManager) {
		super(renderManager);
	}

	
	@Override protected ResourceLocation getEntityTexture(EntityRaceCart entity) {
		return TEXTURE;
	}

	@Override
    public void doRender(EntityRaceCart entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
        GlStateManager.pushMatrix();
        this.setupTranslation(x, y, z);
        this.setupRotation(entity, entityYaw, partialTicks);
        this.bindEntityTexture(entity);

        if (this.renderOutlines)
        {
            GlStateManager.enableColorMaterial();
            GlStateManager.enableOutlineMode(this.getTeamColor(entity));
        }
        
        this.modelRaceCart.render(entity, partialTicks, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        if (this.renderOutlines)
        {
            GlStateManager.disableOutlineMode();
            GlStateManager.disableColorMaterial();
        }

        GlStateManager.popMatrix();
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }

    public void setupRotation(EntityRaceCart entity, float p_188311_2_, float p_188311_3_)
    {
        GlStateManager.rotate(180.0F - p_188311_2_, 0.0F, 1.0F, 0.0F);
        GlStateManager.scale(-1.0F, -1.0F, 1.0F);
    }

    public void setupTranslation(double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y+ 0.375F, (float)z);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityBoat entity)
    {
        return TEXTURE;
    }

    public boolean isMultipass()
    {
        return true;
    }

    public void renderMultipass(EntityRaceCart p_188300_1_, double p_188300_2_, double p_188300_4_, double p_188300_6_, float p_188300_8_, float p_188300_9_)
    {
        GlStateManager.pushMatrix();
        this.setupTranslation(p_188300_2_, p_188300_4_, p_188300_6_);
        this.setupRotation(p_188300_1_, p_188300_8_, p_188300_9_);
        this.bindEntityTexture(p_188300_1_);
        ((IMultipassModel)this.modelRaceCart).renderMultipass(p_188300_1_, p_188300_9_, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GlStateManager.popMatrix();
    }
}

 

 

Link to comment
Share on other sites

RenderingRegistry.registerEntityRenderingHandler(Class<T>, IRenderFactory<? super T>) must be called before init. It won't do anything if called in init or later.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Changed that, and it didn't like me casting the model as an IMultipassModel, so I fixed that in the Model class. Now I have an empty renderMultipass method in there. (Do I even need to make this a multipass model?)

Now when I right-click the item that spawns the car, nothing shows up.

Link to comment
Share on other sites

Update

The cube no longer renders (I honestly forget how I managed that one, yay!), but I have since added a collision box that does work. The box takes the shape of the cube that should be there.
I also know the RenderRaceCart.doRender() method is called (and by extension, the ModelRaceCart.render() method as well), but, again, nothing is showing up. I feel something is wrong in these methods...?

Link to comment
Share on other sites

Got it. The render method in the Model class had a bunch of junk in it that seemed to break the rendering. I just need the body.render, spoiler.render, etc. statements. Only issue is that seemed to break the scaling I had on the model. Now it's just a bit of number-tweaking from there to get it right again.

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.

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



×
×
  • Create New...

Important Information

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