Jump to content

[1.8] Rendering chain for hookshot


TrashCaster

Recommended Posts

So I'm making a hookshot, and I have the chain rendering because I leeched the code from the guardian beam. It works, but it's not at the position I want, nor does it ignore the frustum for whatever reason (in the grapple hook entity, I used this.ignoreFrustumCheck = true which doesn't seem to do anything).

 

Here's what I need to happen.

 

Firstly, the chain needs to render no matter what, so long as the hook is loaded on the client. Second, it needs to appear to be coming out of the hook shot item, kind of like how the fishing line comes out of the rod.

 

I wanted to draw from the hookshot item to the hook, but that's not really possible since the IItemRenderer is deprecated/removed.

 

How should I go about this?

 

[spoiler=Rendering Code]

 

public void doRender(EntityGrappleHook entity, double x, double y, double z, float p_76986_8_, float partialTicks)

{

Tessellator tessellator = Tessellator.getInstance();

WorldRenderer worldrenderer = tessellator.getWorldRenderer();

this.bindEntityTexture(entity);

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

GlStateManager.pushMatrix();

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

 

byte b0 = 0;

float f2 = 0.0F;

float f3 = 0.5F;

float f4 = (float)(0 + b0 * 10) / 32.0F;

float f5 = (float)(5 + b0 * 10) / 32.0F;

float f6 = 0.0F;

float f7 = 0.15625F;

float f8 = (float)(5 + b0 * 10) / 32.0F;

float f9 = (float)(10 + b0 * 10) / 32.0F;

float f10 = 0.05625F;

GlStateManager.enableRescaleNormal();

 

GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);

GlStateManager.scale(f10, f10, f10);

GlStateManager.translate(-4.0F, 0.0F, 0.0F);

GL11.glNormal3f(f10, 0.0F, 0.0F);

 

for (int i = 0; i < 4; ++i)

{

GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);

GL11.glNormal3f(0.0F, 0.0F, f10);

worldrenderer.startDrawingQuads();

worldrenderer.addVertexWithUV(-8.0D, -2.0D, 0.0D, (double)f2, (double)f4);

worldrenderer.addVertexWithUV(8.0D, -2.0D, 0.0D, (double)f3, (double)f4);

worldrenderer.addVertexWithUV(8.0D, 2.0D, 0.0D, (double)f3, (double)f5);

worldrenderer.addVertexWithUV(-8.0D, 2.0D, 0.0D, (double)f2, (double)f5);

tessellator.draw();

}

 

GlStateManager.disableRescaleNormal();

GlStateManager.popMatrix();

 

if (entity.shootingEntity != null) {

Entity shooter = entity.shootingEntity;

renderChain(shooter,entity,x,y,z,partialTicks);

}

super.doRender(entity, x, y, z, p_76986_8_, partialTicks);

}

 

 

    private Vec3 func_177110_a(Entity entity, double height, float partialTicks)

    {

        double d1 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;

        double d2 = height + entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks;

        double d3 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;

        return new Vec3(d1, d2, d3);

    }

 

public void renderChain(Entity shooter, EntityGrappleHook hookEntity, double x, double y, double z, float partialTicks) {

        Tessellator tessellator = Tessellator.getInstance();

        WorldRenderer worldrenderer = tessellator.getWorldRenderer();

        this.bindTexture(chainTexture);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);

        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

        GlStateManager.disableLighting();

        GlStateManager.disableCull();

        GlStateManager.disableBlend();

        GlStateManager.depthMask(true);

        float f3 = 240.0F;

        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, f3, f3);

        GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0);

        float f4 = (float)hookEntity.worldObj.getTotalWorldTime() + partialTicks;

        f4 = 0f;

        float f5 = f4 * 0.5F % 1.0F;

        float f6 = shooter.getEyeHeight()/2f;

        GlStateManager.pushMatrix();

        GlStateManager.translate((float)x, (float)y + f6, (float)z);

        Vec3 vec3 = this.func_177110_a(hookEntity, -(double)hookEntity.height * 0.0D, partialTicks);

        Vec3 vec31 = this.func_177110_a(shooter, (double)f6, partialTicks);

        Vec3 vec32 = vec31.subtract(vec3);

        double d3 = vec32.lengthVector() + 0.0D;

        vec32 = vec32.normalize();

        float f7 = (float)Math.acos(vec32.yCoord);

        float f8 = (float)Math.atan2(vec32.zCoord, vec32.xCoord);

        GlStateManager.rotate((((float)Math.PI / 2F) + -f8) * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);

        GlStateManager.rotate(f7 * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);

        byte b0 = 1;

        double d4 = (double)f4 * 0.05D * (1.0D - (double)(b0 & 1) * 2.5D);

        worldrenderer.startDrawingQuads();

        worldrenderer.setColorRGBA(255, 255, 255, 255);

        double d5 = (double)b0 * 0.02D;

        double d6 = d5 * 1.41D;

        double d7 = 0.0D + Math.cos(d4 + 2.356194490192345D) * d6;

        double d8 = 0.0D + Math.sin(d4 + 2.356194490192345D) * d6;

        double d9 = 0.0D + Math.cos(d4 + (Math.PI / 4D)) * d6;

        double d10 = 0.0D + Math.sin(d4 + (Math.PI / 4D)) * d6;

        double d11 = 0.0D + Math.cos(d4 + 3.9269908169872414D) * d6;

        double d12 = 0.0D + Math.sin(d4 + 3.9269908169872414D) * d6;

        double d13 = 0.0D + Math.cos(d4 + 5.497787143782138D) * d6;

        double d14 = 0.0D + Math.sin(d4 + 5.497787143782138D) * d6;

        double d15 = 0.0D + Math.cos(d4 + Math.PI) * d5;

        double d16 = 0.0D + Math.sin(d4 + Math.PI) * d5;

        double d17 = 0.0D + Math.cos(d4 + 0.0D) * d5;

        double d18 = 0.0D + Math.sin(d4 + 0.0D) * d5;

        double d19 = 0.0D + Math.cos(d4 + (Math.PI / 2D)) * d5;

        double d20 = 0.0D + Math.sin(d4 + (Math.PI / 2D)) * d5;

        double d21 = 0.0D + Math.cos(d4 + (Math.PI * 3D / 2D)) * d5;

        double d22 = 0.0D + Math.sin(d4 + (Math.PI * 3D / 2D)) * d5;

        double d23 = 0.0D;

        double d24 = 0.4999D;

        double d25 = (double)(-1.0F + f5);

        double d26 = d3 * (0.5D / d5) + d25;

        worldrenderer.addVertexWithUV(d15, d3, d16, d24, d26);

        worldrenderer.addVertexWithUV(d15, 0.0D, d16, d24, d25);

        worldrenderer.addVertexWithUV(d17, 0.0D, d18, d23, d25);

        worldrenderer.addVertexWithUV(d17, d3, d18, d23, d26);

        worldrenderer.addVertexWithUV(d19, d3, d20, d24, d26);

        worldrenderer.addVertexWithUV(d19, 0.0D, d20, d24, d25);

        worldrenderer.addVertexWithUV(d21, 0.0D, d22, d23, d25);

        worldrenderer.addVertexWithUV(d21, d3, d22, d23, d26);

        double d27 = 0.0D;

 

        if (hookEntity.ticksExisted % 2 == 0)

        {

            d27 = 0.5D;

        }

 

        worldrenderer.addVertexWithUV(d7, d3, d8, 0.5D, d27 + 0.5D);

        worldrenderer.addVertexWithUV(d9, d3, d10, 1.0D, d27 + 0.5D);

        worldrenderer.addVertexWithUV(d13, d3, d14, 1.0D, d27);

        worldrenderer.addVertexWithUV(d11, d3, d12, 0.5D, d27);

        tessellator.draw();

        GlStateManager.popMatrix();

}

 

 

Link to comment
Share on other sites

You don't need IItemRenderer if your HookShot is an Entity (which it is, judging from your code). Just render everything, Item included, in the Entity render class, and leave the hand-held portion of the item rendered with the standard Item rendering code.

 

If you have part of the hookshot that needs to be at the end of the chain, you should still be able to manually render a texture icon. Take a look at the fishing hook render code for an example of that.

Link to comment
Share on other sites

You don't need IItemRenderer if your HookShot is an Entity (which it is, judging from your code). Just render everything, Item included, in the Entity render class, and leave the hand-held portion of the item rendered with the standard Item rendering code.

 

If you have part of the hookshot that needs to be at the end of the chain, you should still be able to manually render a texture icon. Take a look at the fishing hook render code for an example of that.

 

I honestly don't even know where to start digging.

 

I've searched basically everywhere, and too much is obfuscated that I don't even know what to be looking for.

I know in previous Minecraft versions it was easy to find.

 

 

Also, to prevent any confusion, I'll explain in detail how my hook shot system is working, and rendering.

 

My hookshot item runs on a "two and three state system".

This basically is that it has its normal state, the state that ejects the entity from the player, and the state where the player is being pulled to the entity.

The "two state" part of it is just the fact that the item model/texture has no hook in it in the last two stages.

 

Rendering is being done from the entity, but the issue with that is the renderer is ignoring me setting "ignore frustum check", and also that if the entity gets too far away, the chain disappears since it gets unloaded client side.

 

I also don't know the proper transformations to apply to the one end of the hookshot chain, so it'd be a heck of a lot easier to have it render from the player's hand.

Either way, I have to make GL calls to get the chain to display, so I'd be really happy to have IItemRenderer (or a variant) (re-)added, but just noted that it shouldn't be used for anything other than rendering things that you cannot do with JSON models.

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