Search in sources :

Example 6 with EntityRenderDispatcher

use of net.minecraft.client.render.entity.EntityRenderDispatcher in project BedrockIfy by juancarloscp52.

the class PaperDoll method drawPaperDoll.

/**
 * Draw the player entity in the specified position on screen.
 */
private void drawPaperDoll(MatrixStack matrixStack) {
    client.getProfiler().push("Player");
    ClientPlayerEntity player = client.player;
    if (player == null)
        return;
    matrixStack.push();
    int renderPosY = posY;
    // If the player is elytra flying, the entity must be manually centered depending on the pitch.
    if (player.isFallFlying())
        renderPosY = posY - MathHelper.ceil(size * 2 * toMaxAngleRatio(player.pitch));
    else // If the player is swimming, the entity must also be centered in the Y axis.
    if (player.isSwimming()) {
        renderPosY = posY - size;
    }
    // Position the entity on screen.
    int posX = 30;
    matrixStack.translate(posX + settings.getScreenSafeArea(), renderPosY + settings.getScreenSafeArea(), 0);
    matrixStack.scale((float) size, (float) size, -(float) size);
    Quaternion quaternion = Vector3f.POSITIVE_Z.getDegreesQuaternion(180.0F);
    matrixStack.multiply(quaternion);
    // Store previous entity rotations.
    float bodyYaw = player.bodyYaw;
    float yaw = player.yaw;
    float headYaw = player.headYaw;
    // Set the entity desired rotation for drawing.
    float angle = 145;
    if (!player.isFallFlying()) {
        player.yaw = headYaw - bodyYaw + angle;
        player.headYaw = player.yaw;
    } else {
        player.headYaw = angle;
    }
    player.bodyYaw = angle;
    // Draw the entity.
    EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher();
    entityRenderDispatcher.setRenderShadows(false);
    VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
    RenderSystem.runAsFancy(() -> entityRenderDispatcher.render(player, 0, 0, 0, 0.0F, 1.0F, matrixStack, immediate, 15728880));
    immediate.draw();
    entityRenderDispatcher.setRenderShadows(true);
    // Restore previous entity rotations.
    player.bodyYaw = bodyYaw;
    player.yaw = yaw;
    player.headYaw = headYaw;
    matrixStack.pop();
    client.getProfiler().pop();
}
Also used : Quaternion(net.minecraft.util.math.Quaternion) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) EntityRenderDispatcher(net.minecraft.client.render.entity.EntityRenderDispatcher) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 7 with EntityRenderDispatcher

use of net.minecraft.client.render.entity.EntityRenderDispatcher in project RPG-Hud by KurodaAkira.

the class HudElementEntityInspectVanilla method drawEntityOnScreen.

public static void drawEntityOnScreen(int posX, int posY, LivingEntity entity) {
    int scale = 1;
    int s1 = (int) (18 / entity.getHeight());
    int s3 = (int) (18 / entity.getScaleFactor());
    int offset = 0;
    if (s1 > s3) {
        scale = s3;
    } else
        scale = s1;
    if (entity instanceof SquidEntity) {
        scale = 11;
        offset = -13;
    } else if (entity instanceof SpiderEntity) {
        scale = 11;
        offset = -5;
    }
    posY += offset;
    float f = (float) Math.atan((180 / 40.0F));
    float g = (float) Math.atan((0 / 40.0F));
    MatrixStack ms = RenderSystem.getModelViewStack();
    ms.push();
    ms.translate(posX, posY, 1050.0F);
    ms.scale(1.0F, 1.0F, -1.0F);
    RenderSystem.applyModelViewMatrix();
    MatrixStack matrixStack = new MatrixStack();
    matrixStack.translate(0.0D, 0.0D, 1000.0D);
    matrixStack.scale(scale, scale, scale);
    Quaternion quaternion = Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0F);
    Quaternion quaternion2 = Vec3f.POSITIVE_X.getDegreesQuaternion(g * 20.0F);
    quaternion.hamiltonProduct(quaternion2);
    matrixStack.multiply(quaternion);
    float h = entity.bodyYaw;
    float i = entity.getYaw();
    float j = entity.getPitch();
    float k = entity.prevHeadYaw;
    float l = entity.headYaw;
    entity.bodyYaw = 180.0F + f * 20.0F;
    entity.setYaw(180.0F + f * 40.0F);
    entity.setPitch(-g * 20.0F);
    entity.headYaw = entity.getYaw();
    entity.prevHeadYaw = entity.getYaw();
    DiffuseLighting.method_34742();
    EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher();
    quaternion2.conjugate();
    entityRenderDispatcher.setRotation(quaternion2);
    entityRenderDispatcher.setRenderShadows(false);
    VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
    entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, matrixStack, immediate, 15728880);
    immediate.draw();
    entityRenderDispatcher.setRenderShadows(true);
    entity.bodyYaw = h;
    entity.setYaw(i);
    entity.setPitch(j);
    entity.prevHeadYaw = k;
    entity.headYaw = l;
    ms.pop();
    RenderSystem.applyModelViewMatrix();
    DiffuseLighting.enableGuiDepthLighting();
}
Also used : SquidEntity(net.minecraft.entity.passive.SquidEntity) Quaternion(net.minecraft.util.math.Quaternion) MatrixStack(net.minecraft.client.util.math.MatrixStack) SpiderEntity(net.minecraft.entity.mob.SpiderEntity) EntityRenderDispatcher(net.minecraft.client.render.entity.EntityRenderDispatcher) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Aggregations

EntityRenderDispatcher (net.minecraft.client.render.entity.EntityRenderDispatcher)7 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)5 Quaternion (net.minecraft.util.math.Quaternion)5 SquidEntity (net.minecraft.entity.passive.SquidEntity)3 MatrixStack (net.minecraft.client.util.math.MatrixStack)2 IEPlayerListEntry (com.qouteall.immersive_portals.ducks.IEPlayerListEntry)1 IEWorldRenderer (com.qouteall.immersive_portals.ducks.IEWorldRenderer)1 Environment (net.fabricmc.api.Environment)1 TextRenderer (net.minecraft.client.font.TextRenderer)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 PlayerListEntry (net.minecraft.client.network.PlayerListEntry)1 BlockEntityRenderDispatcher (net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 SpiderEntity (net.minecraft.entity.mob.SpiderEntity)1 TranslatableText (net.minecraft.text.TranslatableText)1 Vec3d (net.minecraft.util.math.Vec3d)1 GameMode (net.minecraft.world.GameMode)1