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

minecraft-inventory-gui

v1.0.1

Published

Render Minecraft inventory GUIs in the browser

Downloads

10

Readme

minecraft-inventory-gui

NPM version Build Status

minecraft-inventory-gui provides a GUI library to interact with minecraft inventories. It does not by itself implement any inventory logic such as clicks, shift clicking, etc. and this is left to the user. This allows the lib to be used in a wide variety of environments, and across different editions of the game.

At this moment in time, the usage for the library looks like this (ES6 import required, in the future we may export a WebComponent):

npm i minecraft-inventory-gui
import { CanvasEventManager } from 'minecraft-inventory-gui'
import * as InventoryWindows from 'minecraft-inventory-gui'

The CanvasEventManager provides an interface to interact with a DOM canvas and handles events such as cursor drags, clicks, etc.

InventoryWindows exposes many different windows such as CreateInventory, SurvivalInventory, etc. that can draw onto a CanvasEventManager instance.

const win = new InventoryWindows.PlayerWin(canvasManager, { getImage })

All of the InventoryWindows have a second dataProvider argument. This should have a getImage function that should return an Image instance, and take a "path" parameter. This function is called whenever an icon (such as a minecraft item or background image) needs to be rendered. It's then cached inside the renderer for that path.

Usage

An example implementation, hosted on Github Pages is found in web/ directory. This example does not connect with any minecraft protocol APIs, it simply simulates an offline inventory.

After an inventory is drawn to the screen, whenever the user interacts with the inventory, the the InventoryWindow emits itemEvent, click, and tooltip events. The notable one is itemEvent which is triggered every time an interaction with an item happens in the inventory.

on('itemEvent', id, type, pos, data)

  • id - the ID of the element which triggered the event
  • type the specific action that occurred, click, doubleClick, rightClick, release.
  • pos the X and Y canvas position where the interaction occurred
  • data [container, slot] - Contains the string container ID where the interaction occurred and its slot. For example, the PlayerWin has a inventory 9x3 grid, clicking the second item would return ["survivalItems", 1].

Based on these emitted events, you can implement inventory logic ontop. Each of the InventoryWindows contain variables which contain arrays of items. You can update these arrays to update the items inside a specific container.

See https://github.com/extremeheat/minecraft-inventory-gui/blob/master/lib/inventories.mjs for a list of properties.

These adjustments should be automatically re-rendered by your render loop.

See https://github.com/extremeheat/minecraft-inventory-gui/tree/master/web for an example implementation.

WIP

  • Export an easier interface without here without needing the user to implement inventory logic, like the web/ example.