Jump to content

Recommended Posts

Posted (edited)

I've created a spear item which, when used, throws a custom arrow entity. I've set up a renderer which is basically copied from the vanilla arrow renderers, and it does nearly what I want. The only problem is that I've used a custom texture which is based on the format of the arrow texture but longer than the vanilla arrow (here is the image file). But when the entity renders, it cuts off the longer part and shortens it to the length of a vanilla arrow. Here is my render class, (all the code is on github):

 

Spoiler

@SideOnly(Side.CLIENT)
public class RenderProjectile extends Render<EntityArrow> {

    public final ResourceLocation texture;

    public RenderProjectile(RenderManager renderManager, ResourceLocation resourceLocation) {

        super(renderManager);
        this.texture = resourceLocation;
    }

    @Override
    protected ResourceLocation
            getEntityTexture(EntityArrow entity) {

        return this.texture;
    }

    @Override
    public void doRender(EntityArrow entity, double x, double y,
            double z, float entityYaw, float partialTicks) {

        this.bindEntityTexture(entity);

        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.pushMatrix();
        GlStateManager.disableLighting();
        GlStateManager.translate((float) x, (float) y, (float) z);
        GlStateManager.rotate(entity.prevRotationYaw +
                (entity.rotationYaw - entity.prevRotationYaw) *
                partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(entity.prevRotationPitch +
                (entity.rotationPitch - entity.prevRotationPitch) *
                partialTicks, 0.0F, 0.0F, 1.0F);

        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer vertexbuffer = tessellator.getBuffer();

        GlStateManager.enableRescaleNormal();

        float f9 = entity.arrowShake - partialTicks;
        
        if (f9 > 0.0F) {
            
            float f10 = -MathHelper.sin(f9 * 3.0F) * f9;
            GlStateManager.rotate(f10, 0.0F, 0.0F, 1.0F);
        }

        GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
        GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);
        GlStateManager.translate(-4.0F, 0.0F, 0.0F);

        if (this.renderOutlines) {
            
            GlStateManager.enableColorMaterial();
            GlStateManager.enableOutlineMode(this.getTeamColor(entity));
        }

        GlStateManager.glNormal3f(0.05625F, 0.0F, 0.0F);

        vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
        vertexbuffer.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.15625D)
                .endVertex();
        vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.15625D)
                .endVertex();
        vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.3125D)
                .endVertex();
        vertexbuffer.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.3125D)
                .endVertex();
        tessellator.draw();

        GlStateManager.glNormal3f(-0.05625F, 0.0F, 0.0F);
        vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
        vertexbuffer.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.15625D)
                .endVertex();
        vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.15625D)
                .endVertex();
        vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.3125D)
                .endVertex();
        vertexbuffer.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.3125D)
                .endVertex();
        tessellator.draw();

        for (int j = 0; j < 4; ++j) {

            GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.glNormal3f(0.0F, 0.0F, 0.05625F);
            vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
            vertexbuffer.pos(-8.0D, -2.0D, 0.0D).tex(0.0D, 0.0D)
                    .endVertex();
            vertexbuffer.pos(8.0D, -2.0D, 0.0D).tex(0.5D, 0.0D)
                    .endVertex();
            vertexbuffer.pos(8.0D, 2.0D, 0.0D).tex(0.5D, 0.15625D)
                    .endVertex();
            vertexbuffer.pos(-8.0D, 2.0D, 0.0D).tex(0.0D, 0.15625D)
                    .endVertex();
            tessellator.draw();
        }

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

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

 

 

So, all I want to know is, where in the rendering code does it define the length of the rendered entity and the section of the image that it uses. I am completely confused by the way most rendering code works, and it's not documented well enough for me to figure it out by reading. Can anyone point me in the right direction?

Edited by Jay Avery
Posted

As far as I know arrows have a model like other entities. If you don't like the length of the model already there, you need to create your own model with the appropriate length.

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.