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

mcil-common

v0.1.1

Published

Parses MCIL and converts it to a set of blocks

Downloads

11

Readme

MCIL Common

This package is used by the mcil-mcedit, mcil-command and mcil-world repositories to do the common process of parsing MCIL and converting it into a block sequence. The individual modules then take care of outputting platform-dependant information.

Usage

Installation from NPM:

$ npm install mcil-common --save

Basic usage:

var mcil = require('mcil-common');
var code = /* get the code */;

mcil.trace(code, { width: 100, height: 100, depth: 100 }, function(block) {
    console.log("Place a " + block.name + " at (" + [block.x, block.y, block.z] + ")");
});

Layout

The library attempts to follow a linear output, where commands continue out towards the longest axis. It starts at the initial branch, and lays out blocks in the pattern set.

When a command block instruction is encountered, a command block is placed at the current position, and the position is moved in the direction. All of the command blocks except the first one are set to chain and are always active. When a 'wait' instruction is encountered, there are two things that could happen depending on the wait duration: for a short wait duration, one or more repeaters are placed sequentially. For a longer duration, a command block loop is setup that increments a scoreboard value every tick, and continues the branch execution once the value has reached a certain amount.

To provide optimum performance, the library optimizes branch operations. When a branch instruction is encountered, the library first checks if the new branch is referenced elsewhere. If it is not, the branch is able to be joined directly to the original branch.

The resulting branch may look like this:

Diagram

In this diagram, the main branch is yellow wool, the secondary branch is blue wool, and the "decider" command block is red.

If the branch is encountered elsewhere, the library must place the branch contents in a location where it can be triggered by all references. The branch is then activated by setblock-ing a redstone block at the beginning of the branch, which then clears the redstone block and continues branch execution.

Block Conflicts

mcil-common gracefully handles the case where two execution blocks need to go in the same place, by redirecting one of the streams. This is done on a 'first in first served' basis, whereby the earlier a branch is executed, the higher its priority when it comes to redirecting. The library also redirects a branch when the branch reaches the world edge (set by the second parameter to mcil.trace).

When redirecting is required, the library will attempt to simply 'wrap around'.

Diagram

As shown in this diagram, the blue branch reaches the yellow branch, and so wraps around to be facing the opposite direction as it originally was.

Command normalisation

Any relative coordinates in a command are changed to be relative to the origin point, or the coordinates (0,0,0) in the world representation. To do this, the library must 'guess' which axis the relative direction is for.

By default, mcil-common will use the first relative coordinate as the X-axis, the second as the Y-axis, and the third as the Z-axis. The library provides some 'flags' to customize this behaviour, however.

There are four flags, all of which go after the numbder in the relative coordinate. These flags are:

  • * - specifies that the library should not change the relative coordinate. For example, ~5* will become ~5
  • x or X - specifies that the coordinate is on the X-axis. For example, ~5x or ~5X
  • y or Y - specifies that the coordinate is on the Y-axis. For example, ~5y or ~5Y
  • z or Z - specifies that the coordinate is on the Z-axis. For example, ~5z or ~5Z

If a coordinate is specified to be on a certain axis, the remaining coordinates, if they do not have a flag, will use positions relative to that coordinate. For example, if a coordinate is specified as to be on the Y axis, the next one will be guessed to be on the Z axis, and the next one on the X axis, unless an axis is explicitly provided.