This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Lapis256/beta/1.18.20
Beta/1.18.20
- Loading branch information
Showing
20 changed files
with
287 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*export { Event } from "./event.js"; | ||
export { GameRule } from "./gamerule.js"; | ||
export { Command } from "./command.js"; | ||
export { World } from "./world.js"; | ||
export { Tick } from "./tick.js"; | ||
export { Tag } from "./tag.js"; | ||
export { Player } from "./player.js"; | ||
export { Scoreboard } from "./scoreboard.js"; | ||
export { EventEmitter } from "./eventEmitter.js";*/ | ||
|
||
import "./src/commandInitializer.js"; | ||
|
||
export * from "./src/utils/index.js"; | ||
export * from "./src/debug/index.js"; | ||
export { Tick } from "./src/tick.js"; | ||
export { Command } from "./src/command.js"; | ||
export { Dimension } from "./src/dimension.js"; | ||
export { RawTextBuilder } from "./src/rawTextBuilder/index.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { world } from "mojang-minecraft"; | ||
|
||
void function() { | ||
const func = (ev) => { | ||
ev.player.runCommand("list"); | ||
world.events.playerJoin.unsubscribe(func); | ||
} | ||
world.events.playerJoin.subscribe(func); | ||
}(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { print, pprint, p, pp } from "./print.js"; | ||
export { default as toJson } from "./toJson.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { world } from "mojang-minecraft"; | ||
|
||
import toJson from "./toJson.js"; | ||
import { RawTextBuilder } from "../rawTextBuilder/index.js"; | ||
|
||
|
||
export function print(...obj) { | ||
const rawtext = new RawTextBuilder().addText(obj.map(String).join(" ")); | ||
const dimension = world.getDimension("overworld"); | ||
dimension.runCommand("tellraw @a " + rawtext.buildJson()); | ||
} | ||
|
||
|
||
export function pprint(...obj) { | ||
print(...obj.map(o => toJson(o, 4))); | ||
} | ||
|
||
|
||
export function p(obj) { | ||
print(obj); | ||
return obj; | ||
} | ||
|
||
|
||
export function pp(obj) { | ||
pprint(obj); | ||
return obj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
function isClass(obj) { | ||
return obj.toString().startsWith("class "); | ||
} | ||
|
||
function isGenerator(obj) { | ||
return obj[Symbol.iterator] && | ||
obj[Symbol.iterator].name === "[Symbol.iterator]" && | ||
typeof obj.next === "function"; | ||
} | ||
|
||
export function toJson(data, indent = 4) { | ||
return JSON.stringify(data, (key, value) => { | ||
switch(typeof value) { | ||
case "function": | ||
if(isClass(value)) { | ||
return `[class ${value.name || key}]`; | ||
} | ||
return `[function ${value.name || key}]`; | ||
|
||
case "object": | ||
if(isGenerator(value)) { | ||
return `[generator ${key || "Generator"}]`; | ||
} | ||
if(Array.isArray(value)) { | ||
return value; | ||
} | ||
let obj = {}; | ||
for(const i in value) { | ||
obj[i] = value[i]; | ||
} | ||
return obj; | ||
|
||
case "undefined": | ||
return null; | ||
|
||
default: | ||
return value; | ||
} | ||
}, indent); | ||
} | ||
function isClass(obj) { | ||
return obj.toString().startsWith("class "); | ||
} | ||
|
||
function isGenerator(obj) { | ||
return obj[Symbol.iterator] && | ||
obj[Symbol.iterator].name === "[Symbol.iterator]" && | ||
typeof obj.next === "function"; | ||
} | ||
|
||
export default function toJson(data, indent = 4) { | ||
return JSON.stringify(data, (key, value) => { | ||
switch(typeof value) { | ||
case "function": | ||
if(isClass(value)) { | ||
return `[class ${value.name || key}]`; | ||
} | ||
return `[function ${value.name || key}]`; | ||
|
||
case "object": | ||
if(isGenerator(value)) { | ||
return `[generator ${key || "Generator"}]`; | ||
} | ||
if(Array.isArray(value)) { | ||
return value; | ||
} | ||
let obj = {}; | ||
for(const i in value) { | ||
obj[i] = value[i]; | ||
} | ||
return obj; | ||
|
||
case "undefined": | ||
return null; | ||
|
||
default: | ||
return value; | ||
} | ||
}, indent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import { Command } from "./command.js"; | ||
import { mergeObject } from "./object.js"; | ||
|
||
|
||
export class Dimension { | ||
#dimension; | ||
|
||
constructor(dimension) { | ||
this.#dimension = dimension; | ||
mergeObject(this, dimension); | ||
} | ||
commandRun(command) { | ||
return Command.run(command, this.#dimension); | ||
} | ||
commandRunSafe(command) { | ||
return Command.runSafe(command, this.#dimension); | ||
} | ||
} | ||
import { world } from "mojang-minecraft"; | ||
|
||
|
||
const dimensions = [ | ||
"overworld", | ||
"nether", | ||
"the end" | ||
].map(name => ({ name, dim: world.getDimension(name)})); | ||
Object.freeze(dimensions); | ||
|
||
|
||
class _Dimension { | ||
getName(dimension) { | ||
const { name } = dimensions.find(({ dim }) => dim === dimension); | ||
return name; | ||
} | ||
|
||
get(dimName) { | ||
const { dim } = dimensions.find(({ name }) => name === dimName); | ||
return dim; | ||
} | ||
} | ||
|
||
export const Dimension = new _Dimension(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
export class AdvancedIterator { | ||
#iterator; | ||
|
||
constructor(iterator) { | ||
this.#iterator = iterator; | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
for(const i of this.#iterator){ | ||
yield i; | ||
} | ||
} | ||
|
||
map(func) { | ||
const iterator = this.#iterator; | ||
return new AdvancedIterator((function*() { | ||
for(const i of iterator) { | ||
yield func(i); | ||
} | ||
})()); | ||
} | ||
|
||
filter(check) { | ||
const iterator = this.#iterator; | ||
return new AdvancedIterator((function*() { | ||
for(const i of iterator) { | ||
if(!check(i)) continue; | ||
yield i; | ||
} | ||
})()); | ||
} | ||
|
||
find(check) { | ||
for(const i of this.#iterator) { | ||
if(!check(i)) continue; | ||
return i; | ||
} | ||
} | ||
} | ||
const CANCEL = Symbol("Cancel"); | ||
|
||
export class Iterator { | ||
#iterator; | ||
|
||
constructor(iterator) { | ||
this.#iterator = iterator; | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
yield* this.#iterator; | ||
} | ||
|
||
#wrapper(func) { | ||
const iterator = this.#iterator; | ||
const iter = function* () { | ||
for(const v of iterator) { | ||
const result = func(v); | ||
if(result === CANCEL) { | ||
continue; | ||
} | ||
yield result; | ||
} | ||
} | ||
this.#iterator = iter(); | ||
return this; | ||
} | ||
|
||
map(func) { | ||
return this.#wrapper(func); | ||
} | ||
|
||
filter(check) { | ||
return this.#wrapper(v => check(v) ? v : CANCEL); | ||
} | ||
|
||
find(check) { | ||
for(const i of this.#iterator) { | ||
if(check(i)) return i; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function isSequence(array) { | ||
let [ previous, ...values ] = Array.from(array); | ||
for(const value of values) { | ||
if(Math.abs(value - previous) !== 1) { | ||
return false; | ||
} | ||
previous = value; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./object.js"; | ||
export * from "./print.js"; | ||
export * from "./range.js"; | ||
export * from "./string.js"; | ||
// export * from "./object.js"; | ||
// export * from "./range.js"; | ||
export * from "./array.js"; | ||
export * from "./options.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as m from "mojang-minecraft"; | ||
|
||
|
||
function generateClass(baseClass) { | ||
return class extends baseClass { | ||
constructor(options) { | ||
super(); | ||
for(const key in options) { | ||
if(key in this) this[key] = options[key]; | ||
else throw `${key} does not exist in ${baseClass.name}`; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const BlockRaycastOptions = generateClass(m.BlockRaycastOptions); | ||
export const EntityDataDrivenTriggerEventOptions = generateClass(m.EntityDataDrivenTriggerEventOptions); | ||
export const EntityEventOptions = generateClass(m.EntityEventOptions); | ||
export const EntityQueryOptions = generateClass(m.EntityQueryOptions); | ||
export const EntityQueryScoreOptions = generateClass(m.EntityQueryScoreOptions); | ||
export const EntityRaycastOptions = generateClass(m.EntityRaycastOptions); | ||
export const ExplosionOptions = generateClass(m.ExplosionOptions); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.