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.pushMatrix();
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);
quaternion.multiply(quaternion1);
matrixstack.func_227863_a_(quaternion);
// 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();
quaternion1.conjugate();
entityrenderermanager.func_229089_a_(quaternion1);
entityrenderermanager.setRenderShadow(false);
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);
irendertypebuffer$impl.func_228461_a_();
entityrenderermanager.setRenderShadow(true);
armorStandEntity.renderYawOffset = f2;
armorStandEntity.rotationPitch = f4;
armorStandEntity.prevRotationYawHead = f5;
armorStandEntity.rotationYawHead = f6;
RenderSystem.popMatrix();
}