Jump to content

Get Armor-stand part inside GUI


Recommended Posts

So I have created a GUI in which I have rendered an Armor-stand. My goal is it to get the exact part that the player clicked at (an arm, a leg, the torso, e.t.c.).

I can't use Minecraft#objectMouseHover, since the Entity hasn't been added to the world (it's only rendered). For the same reason, I can't use World#rayTrace().

Is there an easy way of accomplishing what I want to do, or do I manually have to calculate the "inverse projection"?

Here's the code that I use to render the Armor-stand (basically what Minecraft does inside the player inventory):

    private void renderInside() {
        final int i = guiLeft + windowWidth / 2;
        final int j = guiTop + windowHeight / 2 + 80;
        final int scale = 80;
        RenderSystem.translatef(i, j, 1050.0F);
        RenderSystem.scalef(1.0F, 1.0F, -1.0F);
        MatrixStack matrixstack = new MatrixStack();
        matrixstack.func_227861_a_(0.0D, 0.0D, 1000.0D);
        matrixstack.func_227862_a_((float)scale, (float)scale, (float)scale);
        // horizontal scale
        Quaternion quaternion = Vector3f.field_229183_f_.func_229187_a_(180.0F);
        // vertical scale
        Quaternion quaternion1 = Vector3f.field_229179_b_.func_229187_a_(-previousPitch * 20.0F);
        // renderYawOffset: everything but base plate
        float f2 = armorStandEntity.renderYawOffset;
        float f4 = armorStandEntity.rotationPitch;
        float f5 = armorStandEntity.prevRotationYawHead;
        float f6 = armorStandEntity.rotationYawHead;
        armorStandEntity.renderYawOffset = 180.0F + previousYaw * 20.0F;
        armorStandEntity.rotationPitch = - previousPitch;
        armorStandEntity.rotationYawHead = armorStandEntity.rotationYaw;
        armorStandEntity.prevRotationYawHead = armorStandEntity.rotationYaw;
        EntityRendererManager entityrenderermanager = minecraft.getRenderManager();
        IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance().func_228019_au_().func_228487_b_();
        entityrenderermanager.func_229084_a_(armorStandEntity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, matrixstack, irendertypebuffer$impl, 15728880);
        armorStandEntity.renderYawOffset = f2;
        armorStandEntity.rotationPitch = f4;
        armorStandEntity.prevRotationYawHead = f5;
        armorStandEntity.rotationYawHead = f6;


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.