Jump to content

Projectile entity rendering - change length of arrow?

Jay Avery

Recommended Posts

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



public class RenderProjectile extends Render<EntityArrow> {

    public final ResourceLocation texture;

    public RenderProjectile(RenderManager renderManager, ResourceLocation resourceLocation) {

        this.texture = resourceLocation;

    protected ResourceLocation
            getEntityTexture(EntityArrow entity) {

        return this.texture;

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


        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        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();


        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.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)
        vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.15625D)
        vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.3125D)
        vertexbuffer.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.3125D)

        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)
        vertexbuffer.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.15625D)
        vertexbuffer.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.3125D)
        vertexbuffer.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.3125D)

        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)
            vertexbuffer.pos(8.0D, -2.0D, 0.0D).tex(0.5D, 0.0D)
            vertexbuffer.pos(8.0D, 2.0D, 0.0D).tex(0.5D, 0.15625D)
            vertexbuffer.pos(-8.0D, 2.0D, 0.0D).tex(0.0D, 0.15625D)

        if (this.renderOutlines) {

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