npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@madlad3718/mcveclib

v0.2.9

Published

A library of advanced matrix and vector operations for use within the Minecraft scripting API.

Downloads

40

Readme

MCVecLib

A library of advanced matrix and vector operations for use within Minecraft Bedrock's scripting API. Most operations from the HLSL intrisics are implemented as well as some additional functions that are highly versatile, including conversions between the API's various interfaces.

Namespaces:

  1. Vec2: Includes operations on the Vector2 interface for creation, manipulation and usage.
  2. Vec3: Includes operations on the Vector3 interface for creation, manipulation and usage.
  3. Mat2: Includes various 2x2 matrix operations through the Matrix2 interface. Enables construction, multiplication, inversion and more.
  4. Mat3: Includes various 3x3 matrix operations through the Matrix3 interface. Enables construction, multiplication, inversion and more.
  5. RandVec: Includes utilities for generating random vectors from various uniform distributions.

Examples:

Get the angle between the closest entity and the player's view direction:

import { Vec3 } from "@madlad3718/mcveclib";
import { Player } from "@minecraft/server";

function angleToClosestEntity(player: Player): number {
    // Get the closest entity to the player.
    const entity = player.dimension.getEntities({
        location: player.location,
        closest: 1
    })[0];

    // Get the difference vector pointing from the player's location
    // to the entity's location.
    const to_entity = Vec3.sub(entity.location, player.location);

    // Compute the dot product between the player's view vector and
    // the normalized player-entity difference vector.
    const view = player.getViewDirection();
    const v_dot_e = Vec3.dot(view, Vec3.normalize(to_entity));

    // Return the arccosine of the dot product. The dot product of two 
    // vectors A and B returns |A||B|cosθ, where θ is the angle between.
    return Math.acos(v_dot_e);
}

Get a random block within a 30° offset from a player's view direction:

import { Mat3, RandVec } from "@madlad3718/mcveclib";
import { Player, Block } from "@minecraft/server";

function randomVisibleBlock(player: Player): Block | undefined {
    // Get the player's head position and view vector.
    const origin = player.getHeadLocation();
    const view = player.getViewDirection();

    // Build a tangent-normal-binormal matrix around the view vector.
    // This represents a basis for the player's view space.
    const basis = Mat3.buildTNB(view);

    // Compute the direction by multiplying a random spherical cap
    // sample with maximum offset of 30° by the view matrix.
    const direction = Mat3.mul(basis, RandVec.cap(Math.PI / 6));

    // Get the block by casting a ray from the player's head position
    // in the computed direction.
    return player.dimension.getBlockFromRay(origin, direction);
}