Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

Bump - can anyone help? My next idea is to just start randomly altering numbers in the GlStateManager and vertexbuffer methods to see what happens...

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.