Skip to content

Instantly share code, notes, and snippets.

View 3vorp's full-sized avatar

Evorp 3vorp

View GitHub Profile
@3vorp
3vorp / configurablePortal.js
Last active July 16, 2024 18:49
Configurable Minecraft nether portal atlas generation script for Node.js. Made possible by coyo_t's work and the Minecraft wiki (original code at http://catsofwar.com/mc_proctex/mc.html).
const { createCanvas, ImageData } = require("@napi-rs/canvas");
const { writeFileSync } = require("fs");
/**
* @typedef {Object} PortalOptions
* @property {Number} width
* @property {Number} height
* @property {Number} [frameCount]
* @property {Number} [spiralCount]
* @property {Number} [noise]
@3vorp
3vorp / require.py
Last active February 28, 2024 22:47
CommonJS styled require() for modules in Python. Supports JSON and implicit extensions.
from importlib.util import spec_from_file_location, module_from_spec
def require(path: str):
"""
JavaScript styled require with relative paths and JSON support.
"""
if (path.endswith(".json")):
from json import loads
with open(path, "r") as f:
return loads(f.read())
@3vorp
3vorp / extendTileSheet.js
Last active March 3, 2024 08:41
Extend a tilesheet with ping-ponging and frame duplication. Useful for manipulating Minecraft atlases.
const { loadImage, createCanvas } = require("@napi-rs/canvas");
const { writeFileSync } = require("fs");
const { readFile } = require("fs/promises");
/**
* @typedef TileSheetOptions
* @property {string | URL | Buffer | ArrayBufferLike | Uint8Array | import("@napi-rs/canvas").Image | import("stream").Readable} src - What to load
* @property {number} [duplicate] - How many duplicates to create (default 2)
* @property {boolean} [pingPong] - Whether to ping-pong the animation or not (default false)
*/
@3vorp
3vorp / jsToVue.ts
Last active July 16, 2024 18:48
Convert JS Vue template strings to Vue SFC files. Doesn't handle formatting, imports, and the templates have to be in backticks to work, but it can bulk edit an entire project.
import { readdirSync, statSync, readFileSync, mkdirSync, existsSync, writeFileSync } from "fs";
import { sep } from "path";
const INPUT_JS_PATH = "./pages";
const EMITTED_VUE_PATH = "./vue";
function walkSync(dir: string, filelist: string[] = []) {
// add trailing slash if not present
if (!dir.endsWith(sep)) dir += sep;
for (const file of readdirSync(dir)) {
@3vorp
3vorp / batchRecolor.js
Last active March 6, 2024 06:09
Batch recolor an image to match a series of provided templates.
const { loadImage, createCanvas } = require("@napi-rs/canvas");
const { readdirSync, writeFileSync, existsSync, mkdirSync } = require("fs");
const { join } = require("path");
/** @typedef {string | URL | Buffer | ArrayBufferLike | Uint8Array | import("@napi-rs/canvas").Image | import("stream").Readable} ImageSource */
/** @typedef {[number, number, number, number]} ColorTuple - [r, g, b, a] array of colors */
/**
* @typedef ReplacementData
@3vorp
3vorp / convertPack.js
Last active July 16, 2024 22:17
Convert a Minecraft resource pack between versions and editions with (relative) ease.
const { copyFile, mkdir } = require("fs/promises");
// why is there no async exists function
const { existsSync } = require("fs");
const DEBUG = false;
if (!Object.groupBy || typeof Object.groupBy !== "function") {
console.error(`You need a newer version of Node.js to run this program! (>=21.0)`);
process.exit(1);
}