Search in sources :

Example 1 with IMagnifyingGlassInspector

use of com.infinityraider.agricraft.api.v1.client.IMagnifyingGlassInspector in project AgriCraft by AgriCraft.

the class MagnifyingGlassViewHandler method inspectionRender.

@SubscribeEvent
@SuppressWarnings("unused")
public void inspectionRender(RenderWorldLastEvent event) {
    // Check if the player is in first person
    if (!Minecraft.getInstance().gameSettings.getPointOfView().func_243192_a()) {
        return;
    }
    // Check if an inspection renderer is present and cache it (another thread might set it to null)
    IMagnifyingGlassInspector inspector = this.inspector;
    if (inspector == null) {
        return;
    }
    // Check if the inspector has a target and cache (another thread might set it to null)
    Target target = this.lastTarget;
    if (target == null) {
        return;
    }
    // Fetch and push matrix to the matrix stack
    MatrixStack transforms = event.getMatrixStack();
    transforms.push();
    // Correct for render view
    Vector3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
    transforms.translate(-projectedView.x, -projectedView.y, -projectedView.z);
    // Move to the player's eye position
    Vector3d eyes = this.getPlayer().getEyePosition(event.getPartialTicks());
    transforms.translate(eyes.getX(), eyes.getY(), eyes.getZ());
    // Fetch the player's target
    Vector3d hit = target.getTargetVector(event.getPartialTicks());
    Vector3d view = hit.subtract(eyes).normalize();
    // Translate offset
    transforms.translate(GENOME_OFFSET * view.getX(), GENOME_OFFSET * view.getY(), GENOME_OFFSET * view.getZ());
    // Fetch player look orientation;
    float yaw = (float) (Math.PI * this.getPlayer().getYaw(event.getPartialTicks())) / 180;
    float pitch = (float) (Math.PI * this.getPlayer().getPitch(event.getPartialTicks())) / 180;
    // Rotate for yaw
    transforms.rotate(Vector3f.YP.rotation(-yaw));
    // Render
    transforms.push();
    inspector.doInspectionRender(transforms, event.getPartialTicks(), target.getTargetEntity());
    transforms.pop();
    // Pop last transformation matrix from the stack
    transforms.pop();
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) IMagnifyingGlassInspector(com.infinityraider.agricraft.api.v1.client.IMagnifyingGlassInspector) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

IMagnifyingGlassInspector (com.infinityraider.agricraft.api.v1.client.IMagnifyingGlassInspector)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1