New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mc-command-patch

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mc-command-patch - npm Package Compare versions

Comparing version
0.1.1
to
0.1.2
+6
dist/command/circle.d.ts
import { commandParser } from "../commandMap";
/**
* 画圆命令 “circle x y z r edge_block fill_block”
* @param command
*/
export declare const drawCircle: commandParser;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawCircle = void 0;
/**
* Bresenham方法生成八分之一个圆弧,圆心为坐标原点
* @param radius 半径
*/
function bresenham(radius) {
const pointArray = [];
let x = 0;
let y = radius;
let d = 3 - 2 * radius;
while (x < y) {
pointArray.push([x, y]);
if (d < 0) {
d = d + 4 * x + 6;
}
else {
d = d + 4 * (x - y) + 10;
y--;
}
x++;
}
if (x === y) {
pointArray.push([x, y]);
}
return pointArray;
}
/**
* 将八分之一个圆的坐标扩展为整个圆的坐标
* @param x
* @param y
* @param partPoints
*/
function buildWhole(x, y, partPoints) {
// 通过Set去除可能出现的重复点
const pointSet = new Set();
for (const point of partPoints) {
pointSet.add(x + point[0] + " " + (y + point[1]));
pointSet.add(x + point[1] + " " + (y + point[0]));
pointSet.add(x + point[0] + " " + (y - point[1]));
pointSet.add(x + point[1] + " " + (y - point[0]));
pointSet.add(x - point[0] + " " + (y + point[1]));
pointSet.add(x - point[1] + " " + (y + point[0]));
pointSet.add(x - point[0] + " " + (y - point[1]));
pointSet.add(x - point[1] + " " + (y - point[0]));
}
return [...pointSet].map((value) => value.split(" ").map((n) => Number(n)));
}
/**
* 给定圆心坐标和半径,生成圆的边缘坐标
* @param x
* @param y
* @param radius 半径
*/
function getCircleEdge(x, y, radius) {
return buildWhole(x, y, bresenham(radius));
}
/**
* 给定圆心坐标和半径,生成圆的内部坐标
* @param x
* @param y
* @param radius 半径
*/
function getCircleFill(x, y, radius) {
const edgePoints = bresenham(radius);
const fillPoints = [];
for (const p of edgePoints) {
for (let i = p[0]; i < p[1]; i++) {
fillPoints.push([p[0], i]);
}
}
return buildWhole(x, y, fillPoints);
}
/**
* 画圆命令 “circle x y z r edge_block fill_block”
* @param command
*/
const drawCircle = (command) => {
const arr = command.split(" ");
const [, x, y, z, r, edgeBlock, fillBlock] = arr;
const edgePoints = getCircleEdge(Number(x), Number(z), Number(r));
const result = edgePoints.map(p => `fill ${p[0]} ${y} ${p[1]} ${p[0]} ${y} ${p[1]} ${edgeBlock}`);
if (fillBlock) {
const fillPoints = getCircleFill(Number(x), Number(z), Number(r));
return result.concat(fillPoints.map(p => `fill ${p[0]} ${y} ${p[1]} ${p[0]} ${y} ${p[1]} ${fillBlock}`));
}
else {
return result;
}
};
exports.drawCircle = drawCircle;
import { commandParser } from "../commandMap";
/**
* 一键清理 “clean snow <x y z> [n=10] [h=5]”
* @param command
*/
export declare const clean: commandParser;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clean = void 0;
/**
* 一键清理 “clean snow <x y z> [n=10] [h=5]”
* @param command
*/
const clean = (command) => {
var _a, _b;
const arr = command.split(" ");
if (arr.length >= 5) {
const target = arr[1];
const x = Number(arr[2]);
const y = Number(arr[3]);
const z = Number(arr[4]);
const n = Number((_a = arr[5]) !== null && _a !== void 0 ? _a : "10");
const h = Number((_b = arr[6]) !== null && _b !== void 0 ? _b : "5");
if (target === "snow") {
return [
`fill ${x + n} ${y + h} ${z + n} ${x - n} ${y - h} ${z - n} air 0 replace snow_layer`,
];
}
else if (target === "water") {
return [
`fill ${x + n} ${y + h} ${z + n} ${x - n} ${y - h} ${z - n} air 0 replace water`,
];
}
}
return [];
};
exports.clean = clean;
export declare const drawPicture: (command: string) => Promise<string[]>;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawPicture = void 0;
const axios_1 = __importDefault(require("axios"));
const pngjs_1 = require("pngjs");
const picture_1 = require("../picture");
const drawPicture = (command) => {
const [, x, y, z, target, url] = command.split(" ");
return new Promise((resolve) => {
if (["north", "south", "east", "west"].indexOf(target) < 0) {
resolve([]);
}
axios_1.default.get(url, { responseType: 'arraybuffer' })
.then((res) => {
if (res.headers["content-type"] === "image/png") {
new pngjs_1.PNG().parse(res.data, (err, data) => {
resolve(picture_1.mapColorConvert(Number(x), Number(y), Number(z), data, target));
});
}
});
});
};
exports.drawPicture = drawPicture;
export { drawCircle } from "./circle";
export { clean } from "./clean";
export { drawPicture } from "./draw";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawPicture = exports.clean = exports.drawCircle = void 0;
var circle_1 = require("./circle");
Object.defineProperty(exports, "drawCircle", { enumerable: true, get: function () { return circle_1.drawCircle; } });
var clean_1 = require("./clean");
Object.defineProperty(exports, "clean", { enumerable: true, get: function () { return clean_1.clean; } });
var draw_1 = require("./draw");
Object.defineProperty(exports, "drawPicture", { enumerable: true, get: function () { return draw_1.drawPicture; } });
export declare type commandParser = (command: string) => string[] | Promise<string[]>;
/**
* 拆分命令为命令组
* @param command
* @return string[]
*/
export declare const parseCommand: commandParser;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCommand = void 0;
// 后续考虑对命令参数进行验证
const command_1 = require("./command");
// 设置天气
const setWeather = (command) => ["weather " + command];
// 设置时间
const setTime = (command) => [
"time set " + command.split(" ")[0],
];
/**
* 提供命令名与对应的处理方法
*/
const commandMap = new Map();
// 修改天气
commandMap.set("clear", setWeather);
commandMap.set("rain", setWeather);
commandMap.set("thunder", setWeather);
// 修改时间
commandMap.set("day", setTime);
commandMap.set("noon", setTime);
commandMap.set("night", setTime);
commandMap.set("midnight", setTime);
// 画圆
commandMap.set("circle", command_1.drawCircle);
// 地图像素画
commandMap.set("draw", command_1.drawPicture);
// 清扫
commandMap.set("clean", command_1.clean);
/**
* 拆分命令为命令组
* @param command
* @return string[]
*/
const parseCommand = (command) => {
let arr = command.split(" ");
const parser = commandMap.get(arr[0]);
if (parser != null) {
return parser(command);
}
return [command];
};
exports.parseCommand = parseCommand;
export { parseCommand } from './commandMap';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCommand = void 0;
var commandMap_1 = require("./commandMap");
Object.defineProperty(exports, "parseCommand", { enumerable: true, get: function () { return commandMap_1.parseCommand; } });
import { PNG } from "pngjs";
declare type Color = {
r: number;
g: number;
b: number;
id: string;
data: number;
};
export declare class ColorPool {
private colorList;
addColor(r: number, g: number, b: number, id: string, data?: number): void;
/**
* 从颜色池中选择一个最接近的颜色
*/
private chooseColor;
/**
* 将图片与颜色池中的颜色相匹配
* @param png pngjs打开的PNG数据
* @param bgBlock 用于填充透明背景的方块
*/
fitPicture(png: PNG, bgBlock?: string): Color[][];
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorPool = void 0;
class ColorPool {
constructor() {
this.colorList = [];
}
addColor(r, g, b, id, data = 0) {
this.colorList.push({ r: r, g: g, b: b, id: id, data: data });
}
/**
* 从颜色池中选择一个最接近的颜色
*/
chooseColor(r, g, b) {
const colorMap = new Map();
this.colorList.forEach(color => {
const rmean = (r + color.r) / 2;
const R2 = Math.pow(r - color.r, 2);
const G2 = Math.pow(g - color.g, 2);
const B2 = Math.pow(b - color.b, 2);
colorMap.set(Math.sqrt((2 + rmean / 256) * R2 + 4 * G2 + (2 + (255 - rmean) / 256) * B2), color);
});
const array = Array.from(colorMap.keys());
const returnColor = colorMap.get(array.sort((a, b) => a - b)[0]);
if (returnColor != undefined) {
return returnColor;
}
else {
return this.colorList[0];
}
}
/**
* 将图片与颜色池中的颜色相匹配
* @param png pngjs打开的PNG数据
* @param bgBlock 用于填充透明背景的方块
*/
fitPicture(png, bgBlock = "air") {
const result = [];
for (let y = 0; y < png.height; y++) {
const line = [];
for (let x = 0; x < png.width; x++) {
const idx = (png.width * y + x) << 2;
if (png.data[idx + 3] > 250) {
line.push(this.chooseColor(png.data[idx], png.data[idx + 1], png.data[idx + 2]));
}
else {
line.push({ r: 0, g: 0, b: 0, id: bgBlock, data: 0 });
}
}
result.push(line);
}
return result;
}
}
exports.ColorPool = ColorPool;
export { mapColorConvert } from './mapColor';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapColorConvert = void 0;
var mapColor_1 = require("./mapColor");
Object.defineProperty(exports, "mapColorConvert", { enumerable: true, get: function () { return mapColor_1.mapColorConvert; } });
import { PNG } from "pngjs";
/**
* 在指定坐标处绘制一副像素画
* @param x
* @param y
* @param z
* @param png png图片
* @param towards 基点为图片左上角,确定朝向
*/
export declare const mapColorConvert: (x: number, y: number, z: number, png: PNG, towards: string) => string[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapColorConvert = void 0;
const colorPool_1 = require("./colorPool");
const mapColor = new colorPool_1.ColorPool();
// 数据值参考 https://minecraft-zh.gamepedia.com/地图物品格式
mapColor.addColor(127, 178, 56, "grass");
mapColor.addColor(247, 233, 163, "planks", 2);
mapColor.addColor(199, 199, 199, "web");
mapColor.addColor(255, 0, 0, "redstone_block");
mapColor.addColor(160, 160, 255, "blue_ice");
mapColor.addColor(167, 167, 167, "iron_block");
mapColor.addColor(0, 124, 0, "leaves");
mapColor.addColor(255, 255, 255, "concrete", 0);
mapColor.addColor(164, 168, 184, "clay");
mapColor.addColor(151, 109, 77, "dirt");
mapColor.addColor(112, 112, 112, "smooth_stone");
mapColor.addColor(64, 64, 255, "water");
mapColor.addColor(143, 119, 72, "planks", 0);
mapColor.addColor(255, 252, 245, "quartz_block");
mapColor.addColor(216, 127, 51, "concrete", 1);
mapColor.addColor(178, 76, 216, "concrete", 2);
mapColor.addColor(102, 153, 216, "concrete", 3);
mapColor.addColor(229, 229, 51, "concrete", 4);
mapColor.addColor(127, 204, 25, "concrete", 5);
mapColor.addColor(242, 127, 165, "concrete", 6);
mapColor.addColor(76, 76, 76, "concrete", 7);
mapColor.addColor(153, 153, 153, "concrete", 8);
mapColor.addColor(76, 127, 153, "concrete", 9);
mapColor.addColor(127, 63, 178, "concrete", 10);
mapColor.addColor(51, 76, 178, "concrete", 11);
mapColor.addColor(102, 76, 51, "concrete", 12);
mapColor.addColor(102, 127, 51, "concrete", 13);
mapColor.addColor(153, 51, 51, "concrete", 14);
mapColor.addColor(25, 25, 25, "concrete", 15);
mapColor.addColor(250, 238, 77, "gold_block");
mapColor.addColor(92, 219, 213, "diamond_block");
mapColor.addColor(74, 128, 255, "lapis_block");
mapColor.addColor(0, 217, 58, "emerald_block");
mapColor.addColor(129, 86, 49, "planks", 1);
mapColor.addColor(112, 2, 0, "netherrack");
mapColor.addColor(209, 177, 161, "stained_hardened_clay", 0);
mapColor.addColor(159, 82, 36, "stained_hardened_clay", 1);
mapColor.addColor(149, 87, 108, "stained_hardened_clay", 2);
mapColor.addColor(112, 108, 138, "stained_hardened_clay", 3);
mapColor.addColor(186, 133, 36, "stained_hardened_clay", 4);
mapColor.addColor(103, 117, 53, "stained_hardened_clay", 5);
mapColor.addColor(160, 77, 78, "stained_hardened_clay", 6);
mapColor.addColor(57, 41, 35, "stained_hardened_clay", 7);
mapColor.addColor(135, 107, 98, "stained_hardened_clay", 8);
mapColor.addColor(87, 92, 92, "stained_hardened_clay", 9);
mapColor.addColor(122, 73, 88, "stained_hardened_clay", 10);
mapColor.addColor(76, 62, 92, "stained_hardened_clay", 11);
mapColor.addColor(76, 50, 35, "stained_hardened_clay", 12);
mapColor.addColor(76, 82, 42, "stained_hardened_clay", 13);
mapColor.addColor(142, 60, 46, "stained_hardened_clay", 14);
mapColor.addColor(37, 22, 16, "stained_hardened_clay", 15);
/**
* 在指定坐标处绘制一副像素画
* @param x
* @param y
* @param z
* @param png png图片
* @param towards 基点为图片左上角,确定朝向
*/
const mapColorConvert = (x, y, z, png, towards) => {
const result = [];
const colorArray = mapColor.fitPicture(png);
for (let i = 0; i < colorArray.length; i++) {
for (let j = 0; j < colorArray[0].length; j++) {
const color = colorArray[i][j];
let position = [];
if (towards === "south") {
position = [x - j, y, z - i];
}
else if (towards === "west") {
position = [x + i, y, z - j];
}
else if (towards === "east") {
position = [x - i, y, z + j];
}
else {
position = [x + j, y, z + i];
}
if (color.id === "air") {
continue;
}
if (color.id === "water") {
position[1]--;
result.push(`fill ${position.join(" ")} ${position.join(" ")} stone`);
position[1]++;
}
result.push(`fill ${position.join(" ")} ${position.join(" ")} ${color.id} ${color.data}`);
}
}
return result;
};
exports.mapColorConvert = mapColorConvert;
+5
-5
{
"name": "mc-command-patch",
"version": "0.1.1",
"description": "",
"main": "index.ts",
"version": "0.1.2",
"description": "This package provides extra commands in minecraft.",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc"
},

@@ -16,3 +16,3 @@ "repository": {

],
"author": "",
"author": "chienmy",
"license": "ISC",

@@ -19,0 +19,0 @@ "bugs": {

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="TypeScriptCompiler">
<option name="nodeInterpreterTextField" value="$USER_HOME$/.nvm/versions/node/v15.14.0/bin/node" />
</component>
</project>

Sorry, the diff of this file is not supported yet

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mc-command-patch.iml" filepath="$PROJECT_DIR$/.idea/mc-command-patch.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>