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.2
to
0.2.1
+1
dist/command/music.d.ts
export declare const musicCommand: (command: string) => string[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.musicCommand = void 0;
const music_1 = require("../music");
const musicCommand = (command) => {
const option = command.split(" ")[1];
if (option == "position") {
const [, , x, y, z] = command.split(" ");
music_1.musicBuilder.setPosition(Number(x), Number(y), Number(z));
}
else if (option == "base") {
const [, , x, y, z] = command.split(" ");
music_1.musicBuilder.setNoteBlock(Number(x), Number(y), Number(z));
}
else if (option == "header") {
return music_1.musicBuilder.buildHeader();
}
else if (option == "build") {
return music_1.musicBuilder.readMusic();
}
return [];
};
exports.musicCommand = musicCommand;
export declare type BlockType = {
name: string;
data: number;
rank: number;
};
export declare type Block = {
type: BlockType;
x: number;
y: number;
z: number;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
import { Block, BlockType } from "./block";
export declare class BlockArray {
private designArray;
private blockMap;
private xMask;
private yMask;
private zMask;
constructor(table: string[][], charMap: Map<string, BlockType>);
setMask(xMask: number[], yMask: number[], zMask: number[]): void;
getBlocks(position: number[]): Block[];
toCommand(position: number[]): string[];
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockArray = void 0;
class BlockArray {
constructor(table, charMap) {
this.xMask = [1, 0, 0];
this.yMask = [0, 1, 0];
this.zMask = [0, 0, 1];
this.designArray = table;
this.blockMap = charMap;
}
setMask(xMask, yMask, zMask) {
this.xMask = xMask;
this.yMask = yMask;
this.zMask = zMask;
}
getBlocks(position) {
let blocks = [];
for (let k = 0; k < this.designArray.length; k++) {
for (let i = 0; i < this.designArray[k].length; i++) {
for (let j = 0; j < this.designArray[k][i].length; j++) {
const b = this.blockMap.get(this.designArray[k][i].charAt(j));
if (b != undefined) {
blocks.push({
type: b,
x: i,
y: j,
z: k
});
}
}
}
}
let result = [];
for (const b of blocks) {
let p = [0, 0, 0];
for (const m of [this.xMask, this.yMask, this.zMask]) {
p[0] += (b.x * m[0]);
p[1] += (b.y * m[1]);
p[2] += (b.z * m[2]);
}
result.push({
type: b.type,
x: p[0] + position[0],
y: p[1] + position[1],
z: p[2] + position[2]
});
}
return result;
}
toCommand(position) {
return this.getBlocks(position).sort((a, b) => {
return b.type.rank - a.type.rank;
}).map((b) => {
return `setblock ${b.x} ${b.y} ${b.z} ${b.type.name} ${b.type.data}`;
});
}
}
exports.BlockArray = BlockArray;
export declare class MusicBuilder {
private originalPoint;
private noteBlockPlace;
private railPosition;
private blockMap;
setPosition(x: number, y: number, z: number): void;
/**
* 初始化24音阶音符盒位置
* @param x
* @param y
* @param z
*/
setNoteBlock(x: number, y: number, z: number): void;
buildHeader(): string[];
readMusic(): string[];
private getInstrument;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MusicBuilder = void 0;
const blockArray_1 = require("./blockArray");
class MusicBuilder {
constructor() {
// 横截面设计,16音轨,4声部
// 原点为对称轴最下方的方块
// [ ][M][ ][M][ ][M][ ]
// [M][-][M][-][M][-][M]
// [-][ ][-][ ][-][ ][-]
// [ ][M][ ][ ][ ][M][ ]
// [ ][-][ ][ ][ ][-][ ]
// [M][ ][M][ ][M][ ][M]
// [-][M][-][M][-][M][-]
// [ ][-][ ][-][ ][-][ ]
this.originalPoint = [0, 0, 0];
// 24音阶音符盒位置数组
this.noteBlockPlace = [];
this.railPosition = [
[0, 0, 1], [0, 0, 3], [0, 0, 5],
[0, -1, 0], [0, -1, 2], [0, -1, 4], [0, -1, 6],
[0, -3, 1], [0, -3, 5],
[0, -5, 0], [0, -5, 2], [0, -5, 4], [0, -5, 6],
[0, -6, 1], [0, -6, 3], [0, -6, 5],
];
this.blockMap = new Map([
["G", { name: "glass", data: 0, rank: 2 }],
["R", { name: "redstone_wire", data: 0, rank: 0 }],
["1", { name: "unpowered_repeater", data: 1, rank: 1 }],
["2", { name: "unpowered_repeater", data: 5, rank: 1 }],
["3", { name: "unpowered_repeater", data: 9, rank: 1 }],
["4", { name: "unpowered_repeater", data: 13, rank: 1 }]
]);
}
setPosition(x, y, z) {
this.originalPoint = [x, y, z];
}
/**
* 初始化24音阶音符盒位置
* @param x
* @param y
* @param z
*/
setNoteBlock(x, y, z) {
for (let i = 0; i < 24; i++) {
this.noteBlockPlace.push([x + i, y, z]);
}
}
buildHeader() {
const array = [[
" ",
" ",
"R R",
"G G",
"R R",
"G G",
" ",
" "
], [
" R R R ",
"RGRGRGR",
"G G G G",
"R R",
"GGGGGGG",
"R R R R",
"GRGRGRG",
" G G G "
], [
" R R R ",
"RG1G1GR",
"G G G G",
" R R ",
" GGGGG ",
"2 3 3 2",
"GRGRGRG",
" G G G "
]
];
const blockArray = new blockArray_1.BlockArray(array, this.blockMap);
blockArray.setMask([0, -1, 0], [0, 0, 1], [1, 0, 0]);
return blockArray.toCommand(this.originalPoint);
}
readMusic() {
const test = [
{
base: 2,
rail: [3, 4, 9, 10],
series: ["5-4", "5-4", "9-4", "9-4", "10-4", "10-4", "9-4", "9-4", "8-4", "8-4", "7-4", "7-4", "6-4", "6-2", "6-1", "7-1", "5-8"]
},
{
base: -10,
rail: [6, 5, 12, 11],
series: ["3-4", "10-4", "12-4", "10-4", "13-4", "10-4", "12-4", "10-4", "11-4", "9-4", "10-4", "8-4", "6-4", "7-4", "3-8"]
}
];
let result = [];
for (let m of test) {
let record = [];
let sum = 0;
for (let s of m.series) {
const t = s.split("-");
record.push({
rail: m.rail[sum % 4],
p: Math.floor(sum / 4),
v: m.base + Number(t[0])
});
sum += Number(t[1]);
}
for (let r of m.rail) {
for (let i = 0; i <= sum / 4; i++) {
const x = this.originalPoint[0] + 4 + 2 * i + this.railPosition[i][0];
const y = this.originalPoint[1] + this.railPosition[i][1];
const z = this.originalPoint[0] + this.railPosition[i][2];
result.push(`setblock ${x} ${y - 1} ${z} stone_slab 8`);
result.push(`setblock ${x} ${y} ${z} unpowered_repeater 13`);
}
}
for (let r of record) {
const x = this.originalPoint[0] + 3 + 2 * r.p + this.railPosition[r.rail][0];
const y = this.originalPoint[1] + this.railPosition[r.rail][1];
const z = this.originalPoint[0] + this.railPosition[r.rail][2];
result.push(`setblock ${x} ${y - 1} ${z} ${this.getInstrument(r.v)[0]} 0`);
const p = this.noteBlockPlace[this.getInstrument(r.v)[1]];
result.push(`clone ${p[0]} ${p[1]} ${p[2]} ${p[0]} ${p[1]} ${p[2]} ${x} ${y} ${z}`);
}
}
return result;
}
getInstrument(value) {
if (value < -18)
return ["wood", value + 30];
else if (value < -6)
return ["wool", value + 18];
else if (value < 18)
return ["dirt", value + 6];
else if (value < 30)
return ["clay", value - 18];
else
return ["gold_block", value - 30];
}
}
exports.MusicBuilder = MusicBuilder;
import { MusicBuilder } from "./builder";
export declare const musicBuilder: MusicBuilder;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.musicBuilder = void 0;
const builder_1 = require("./builder");
exports.musicBuilder = new builder_1.MusicBuilder();
import {musicBuilder} from "../music";
export const musicCommand = (command: string): string[] => {
const option = command.split(" ")[1];
if (option == "position") {
const [, , x, y, z] = command.split(" ");
musicBuilder.setPosition(Number(x), Number(y), Number(z));
}
else if (option == "base") {
const [, , x, y, z] = command.split(" ");
musicBuilder.setNoteBlock(Number(x), Number(y), Number(z));
}
else if (option == "header") {
return musicBuilder.buildHeader();
}else if (option == "build") {
return musicBuilder.readMusic();
}
return [];
}
export type BlockType = {
name: string,
data: number,
rank: number
}
export type Block = {
type: BlockType,
x: number,
y: number,
z: number
}
import {Block, BlockType} from "./block";
export class BlockArray {
private designArray: string[][];
private blockMap: Map<string, BlockType>;
private xMask = [1, 0, 0];
private yMask = [0, 1, 0];
private zMask = [0, 0, 1];
constructor(table: string[][], charMap: Map<string, BlockType>) {
this.designArray = table;
this.blockMap = charMap;
}
public setMask(xMask: number[], yMask: number[], zMask: number[]) {
this.xMask = xMask;
this.yMask = yMask;
this.zMask = zMask;
}
public getBlocks(position: number[]): Block[] {
let blocks = [];
for (let k = 0; k < this.designArray.length; k++) {
for (let i = 0; i < this.designArray[k].length; i++) {
for (let j = 0; j < this.designArray[k][i].length; j++) {
const b = this.blockMap.get(this.designArray[k][i].charAt(j));
if (b != undefined) {
blocks.push({
type: b,
x: i,
y: j,
z: k
});
}
}
}
}
let result = [];
for (const b of blocks) {
let p = [0, 0, 0];
for (const m of [this.xMask, this.yMask, this.zMask]) {
p[0] += (b.x * m[0]);
p[1] += (b.y * m[1]);
p[2] += (b.z * m[2]);
}
result.push({
type: b.type,
x: p[0] + position[0],
y: p[1] + position[1],
z: p[2] + position[2]
});
}
return result;
}
public toCommand(position: number[]) {
return this.getBlocks(position).sort((a, b) => {
return b.type.rank - a.type.rank;
}).map((b) => {
return `setblock ${b.x} ${b.y} ${b.z} ${b.type.name} ${b.type.data}`;
});
}
}
import {Block, BlockType} from "./block";
import {BlockArray} from "./blockArray";
export class MusicBuilder {
// 横截面设计,16音轨,4声部
// 原点为对称轴最下方的方块
// [ ][M][ ][M][ ][M][ ]
// [M][-][M][-][M][-][M]
// [-][ ][-][ ][-][ ][-]
// [ ][M][ ][ ][ ][M][ ]
// [ ][-][ ][ ][ ][-][ ]
// [M][ ][M][ ][M][ ][M]
// [-][M][-][M][-][M][-]
// [ ][-][ ][-][ ][-][ ]
private originalPoint: number[] = [0, 0, 0];
// 24音阶音符盒位置数组
private noteBlockPlace: number[][] = [];
private railPosition: number[][] = [
[0, 0, 1], [0, 0, 3], [0, 0, 5],
[0, -1, 0], [0, -1, 2], [0, -1, 4], [0, -1, 6],
[0, -3, 1], [0, -3, 5],
[0, -5, 0], [0, -5, 2], [0, -5, 4], [0, -5, 6],
[0, -6, 1], [0, -6, 3], [0, -6, 5],
];
private blockMap = new Map<string, BlockType>([
["G", {name: "glass", data: 0, rank: 2}],
["R", {name: "redstone_wire", data: 0, rank: 0}],
["1", {name: "unpowered_repeater", data: 1, rank: 1}],
["2", {name: "unpowered_repeater", data: 5, rank: 1}],
["3", {name: "unpowered_repeater", data: 9, rank: 1}],
["4", {name: "unpowered_repeater", data: 13, rank: 1}]]);
public setPosition(x: number, y: number, z: number) {
this.originalPoint = [x, y, z];
}
/**
* 初始化24音阶音符盒位置
* @param x
* @param y
* @param z
*/
public setNoteBlock(x: number, y: number, z: number) {
for (let i = 0; i < 24; i++) {
this.noteBlockPlace.push([x + i, y, z]);
}
}
buildHeader() {
const array = [[
" ",
" ",
"R R",
"G G",
"R R",
"G G",
" ",
" "], [
" R R R ",
"RGRGRGR",
"G G G G",
"R R",
"GGGGGGG",
"R R R R",
"GRGRGRG",
" G G G "], [
" R R R ",
"RG1G1GR",
"G G G G",
" R R ",
" GGGGG ",
"2 3 3 2",
"GRGRGRG",
" G G G "]
];
const blockArray = new BlockArray(array, this.blockMap);
blockArray.setMask([0, -1, 0], [0, 0, 1], [1, 0, 0]);
return blockArray.toCommand(this.originalPoint);
}
public readMusic() {
const test = [
{
base: 2,
rail: [3, 4, 9, 10],
series: ["5-4", "5-4", "9-4", "9-4", "10-4", "10-4", "9-4", "9-4", "8-4", "8-4", "7-4", "7-4", "6-4", "6-2", "6-1", "7-1", "5-8"]
},
{
base: -10,
rail: [6, 5, 12, 11],
series: ["3-4", "10-4", "12-4", "10-4", "13-4", "10-4", "12-4", "10-4", "11-4", "9-4", "10-4", "8-4", "6-4", "7-4", "3-8"]
}
];
let result = [];
for (let m of test) {
let record = [];
let sum = 0;
for (let s of m.series) {
const t = s.split("-");
record.push({
rail: m.rail[sum % 4],
p: Math.floor(sum / 4),
v: m.base + Number(t[0])
});
sum += Number(t[1]);
}
for (let r of m.rail) {
for (let i = 0; i <= sum / 4; i++) {
const x = this.originalPoint[0] + 4 + 2 * i + this.railPosition[i][0];
const y = this.originalPoint[1] + this.railPosition[i][1];
const z = this.originalPoint[0] + this.railPosition[i][2];
result.push(`setblock ${x} ${y - 1} ${z} stone_slab 8`);
result.push(`setblock ${x} ${y} ${z} unpowered_repeater 13`);
}
}
for (let r of record) {
const x = this.originalPoint[0] + 3 + 2 * r.p + this.railPosition[r.rail][0];
const y = this.originalPoint[1] + this.railPosition[r.rail][1];
const z = this.originalPoint[0] + this.railPosition[r.rail][2];
result.push(`setblock ${x} ${y - 1} ${z} ${this.getInstrument(r.v)[0]} 0`);
const p = this.noteBlockPlace[this.getInstrument(r.v)[1]]
result.push(`clone ${p[0]} ${p[1]} ${p[2]} ${p[0]} ${p[1]} ${p[2]} ${x} ${y} ${z}`);
}
}
return result;
}
private getInstrument(value: number): [string, number] {
if (value < -18) return ["wood", value + 30]
else if (value < -6) return ["wool", value + 18]
else if (value < 18) return ["dirt", value + 6]
else if (value < 30) return ["clay", value - 18]
else return ["gold_block", value - 30]
}
}
import { MusicBuilder } from "./builder";
export const musicBuilder = new MusicBuilder();
+1
-0
export { drawCircle } from "./circle";
export { clean } from "./clean";
export { drawPicture } from "./draw";
export { musicCommand } from "./music";
+3
-1
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawPicture = exports.clean = exports.drawCircle = void 0;
exports.musicCommand = exports.drawPicture = exports.clean = exports.drawCircle = void 0;
var circle_1 = require("./circle");

@@ -10,1 +10,3 @@ Object.defineProperty(exports, "drawCircle", { enumerable: true, get: function () { return circle_1.drawCircle; } });

Object.defineProperty(exports, "drawPicture", { enumerable: true, get: function () { return draw_1.drawPicture; } });
var music_1 = require("./music");
Object.defineProperty(exports, "musicCommand", { enumerable: true, get: function () { return music_1.musicCommand; } });

@@ -31,2 +31,4 @@ "use strict";

commandMap.set("clean", command_1.clean);
//
commandMap.set("music", command_1.musicCommand);
/**

@@ -33,0 +35,0 @@ * 拆分命令为命令组

{
"name": "mc-command-patch",
"version": "0.1.2",
"version": "0.2.1",
"description": "This package provides extra commands in minecraft.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

export { drawCircle } from "./circle";
export { clean } from "./clean";
export { drawPicture } from "./draw";
export { musicCommand } from "./music";
// 后续考虑对命令参数进行验证
import {clean, drawCircle, drawPicture} from "./command";
import {clean, drawCircle, drawPicture, musicCommand} from "./command";

@@ -32,2 +32,4 @@ export type commandParser = (command: string) => string[] | Promise<string[]>;

commandMap.set("clean", clean);
//
commandMap.set("music", musicCommand);

@@ -34,0 +36,0 @@ /**