Java Code Examples for net.minecraftforge.client.event.RenderWorldLastEvent#getMatrixStack()

The following examples show how to use net.minecraftforge.client.event.RenderWorldLastEvent#getMatrixStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Render.java    From XRay-Mod with GNU General Public License v3.0 7 votes vote down vote up
static void renderBlocks(RenderWorldLastEvent event) {
       Vector3d view = XRay.mc.gameRenderer.getActiveRenderInfo().getProjectedView();

       MatrixStack stack = event.getMatrixStack();
       stack.translate(-view.x, -view.y, -view.z); // translate

       RenderSystem.pushMatrix();
       RenderSystem.multMatrix(stack.getLast().getMatrix());

       Tessellator tessellator = Tessellator.getInstance();
       BufferBuilder buffer = tessellator.getBuffer();
       Profile.BLOCKS.apply(); // Sets GL state for block drawing

       syncRenderList.forEach(blockProps -> {
           buffer.begin( GL_LINES, DefaultVertexFormats.POSITION_COLOR );
           renderBlockBounding(buffer, blockProps);
           tessellator.draw();
       } );

       Profile.BLOCKS.clean();
       RenderSystem.popMatrix();
}
 
Example 2
Source File: BlockOverlayRender.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void render(RenderWorldLastEvent event, ItemStack item) {
    final Minecraft mc = Minecraft.getInstance();

    IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();

    int range = MiningProperties.getBeamRange(item);
    BlockRayTraceResult lookingAt = VectorHelper.getLookingAt(mc.player, RayTraceContext.FluidMode.NONE, range);
    if (mc.world.getBlockState(VectorHelper.getLookingAt(mc.player, item, range).getPos()) == Blocks.AIR.getDefaultState()) {
        return;
    }

    List<BlockPos> coords = MiningCollect.collect(mc.player, lookingAt, mc.world, MiningProperties.getRange(item));
    Vec3d view = mc.gameRenderer.getActiveRenderInfo().getProjectedView();

    MatrixStack matrix = event.getMatrixStack();
    matrix.push();
    matrix.translate(-view.getX(), -view.getY(), -view.getZ());

    IVertexBuilder builder;
    builder = buffer.getBuffer(MyRenderType.BlockOverlay);
    coords.forEach(e -> {
        if (mc.world.getBlockState(e).getBlock() != ModBlocks.RENDER_BLOCK.get()) {

            matrix.push();
            matrix.translate(e.getX(), e.getY(), e.getZ());
            matrix.translate(-0.005f, -0.005f, -0.005f);
            matrix.scale(1.01f, 1.01f, 1.01f);
            matrix.rotate(Vector3f.YP.rotationDegrees(-90.0F));

            Matrix4f positionMatrix = matrix.getLast().getMatrix();
            BlockOverlayRender.render(positionMatrix, builder, e, Color.GREEN);
            matrix.pop();
        }
    });
    matrix.pop();
    RenderSystem.disableDepthTest();
    buffer.finish(MyRenderType.BlockOverlay);
}
 
Example 3
Source File: RenderMiningLaser.java    From MiningGadgets with MIT License 4 votes vote down vote up
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) {
    Hand activeHand;
    if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) {
        activeHand = Hand.MAIN_HAND;
    } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) {
        activeHand = Hand.OFF_HAND;
    } else {
        return;
    }

    ItemStack stack = player.getHeldItem(activeHand);

    double distance = from.subtract(trace.getHitVec()).length();
    long gameTime = player.world.getGameTime();
    double v = gameTime * speedModifier;
    float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime);
    BufferBuilder wr = Tessellator.getInstance().getBuffer();

    Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();

    MatrixStack matrix = event.getMatrixStack();
    matrix.translate(view.getX(), view.getY(), view.getZ());
    if( trace.getType() == RayTraceResult.Type.MISS )
        matrix.translate(-from.x, -from.y, -from.z);

    RenderSystem.pushMatrix();
    RenderSystem.multMatrix(matrix.getLast().getMatrix());

    RenderSystem.enableColorMaterial();
    // This makes it so we don't clip into the world, we're effectively drawing on it
    RenderSystem.disableDepthTest();
    RenderSystem.enableBlend();
    //This makes it so multiplayer doesn't matter which side the player is standing on to see someone elses laser
    RenderSystem.disableCull();
    RenderSystem.enableTexture();

    RenderSystem.rotatef(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw), 0, 1, 0);
    RenderSystem.rotatef(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch), 1, 0, 0);

    // additive laser beam
    RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    RenderSystem.color4f(r, g, b, 0.7f);
    Minecraft.getInstance().getTextureManager().bindTexture(laserBeamGlow);
    drawBeam(xOffset, yOffset, zOffset, additiveThickness, activeHand, distance, wr, 0.5, 1, ticks);

    // main laser, colored part
    RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    RenderSystem.color4f(r, g, b, 1.0f);
    Minecraft.getInstance().getTextureManager().bindTexture(laserBeam2);
    drawBeam(xOffset, yOffset, zOffset, thickness, activeHand, distance, wr, v, v + distance * 1.5, ticks);
    // white core
    RenderSystem.color4f(MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f, 1.0f);
    Minecraft.getInstance().getTextureManager().bindTexture(laserBeam);
    drawBeam(xOffset, yOffset, zOffset, thickness / 2, activeHand, distance, wr, v, v + distance * 1.5, ticks);

    RenderSystem.enableDepthTest();
    RenderSystem.enableCull();
    RenderSystem.popMatrix();
}
 
Example 4
Source File: RenderMiningLaser2.java    From MiningGadgets with MIT License 4 votes vote down vote up
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) {
    Hand activeHand;
    if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) {
        activeHand = Hand.MAIN_HAND;
    } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) {
        activeHand = Hand.OFF_HAND;
    } else {
        return;
    }

    IVertexBuilder builder;
    ItemStack stack = player.getHeldItem(activeHand);
    double distance = from.subtract(trace.getHitVec()).length();
    long gameTime = player.world.getGameTime();
    double v = gameTime * speedModifier;
    float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime);

    float beam2r = MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f;
    float beam2g = MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f;
    float beam2b =MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f;

    Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
    IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();

    MatrixStack matrix = event.getMatrixStack();

    matrix.push();

    matrix.translate(-view.getX(), -view.getY(), -view.getZ());
    matrix.translate(from.x, from.y, from.z);
    matrix.rotate(Vector3f.YP.rotationDegrees(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw)));
    matrix.rotate(Vector3f.XP.rotationDegrees(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch)));

    MatrixStack.Entry matrixstack$entry = matrix.getLast();
    Matrix3f matrixNormal = matrixstack$entry.getNormal();
    Matrix4f positionMatrix = matrixstack$entry.getMatrix();

    //additive laser beam
    builder = buffer.getBuffer(MyRenderType.LASER_MAIN_ADDITIVE);
    drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, additiveThickness, activeHand, distance, 0.5, 1, ticks, r,g,b,0.7f);

    //main laser, colored part
    builder = buffer.getBuffer(MyRenderType.LASER_MAIN_BEAM);
    drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness, activeHand, distance, v, v + distance * 1.5, ticks, r,g,b,1f);

    //core
    builder = buffer.getBuffer(MyRenderType.LASER_MAIN_CORE);
    drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness/2, activeHand, distance, v, v + distance * 1.5, ticks, beam2r,beam2g,beam2b,1f);
    matrix.pop();
    RenderSystem.disableDepthTest();
    buffer.finish();
}