├── Core ├── Block │ ├── Sponge.ts │ ├── Dirt.ts │ ├── CobblestoneWall.ts │ ├── QuartzBlock.ts │ ├── Stonebrick.ts │ ├── DoublePlant.ts │ ├── Slab.ts │ ├── WoodType.ts │ ├── Stone.ts │ ├── MonsterEgg.ts │ ├── Sandstone.ts │ ├── RedFlower.ts │ ├── BlockColor.ts │ ├── SetBlockHandling.ts │ ├── BlockHandle.ts │ └── BlockMaterial.ts ├── Scoreboard │ ├── DisplaySlot.ts │ ├── Visibility.ts │ ├── ObjectiveType.ts │ ├── Team.ts │ ├── Objective.ts │ └── Score.ts ├── Output │ ├── OutputBlock.ts │ ├── OutputBlockContainer.ts │ ├── Commandblock.ts │ ├── CbjsFunction.ts │ ├── Block.ts │ ├── ValidateIntializer.ts │ ├── Sign.ts │ ├── FunctionCall.ts │ └── Manager.ts ├── Util │ ├── assert.ts │ ├── Naming.ts │ ├── Event.ts │ ├── Vector3.ts │ ├── Timer.ts │ └── Math.ts ├── Runtime │ ├── NumberSetMode.ts │ ├── Variable.ts │ ├── Number.ts │ ├── Boolean.ts │ ├── String.ts │ ├── Callback.ts │ ├── Integer.ts │ ├── Decimal.ts │ └── Fraction.ts ├── Entities │ ├── Player.ts │ ├── SelectorTarget.ts │ ├── Selector.ts │ ├── EntityType.ts │ └── SelectorArgument.ts ├── Chat │ ├── Color.ts │ ├── TellrawSelectorExtra.ts │ ├── TellrawScoreExtra.ts │ ├── Events │ │ ├── HoverEvent.ts │ │ ├── ClickEvent.ts │ │ └── CallbackClickEvent.ts │ ├── Message.ts │ └── Tellraw.ts ├── Players │ └── GameMode.ts ├── Core.csproj.user ├── MinecraftCommand.ts ├── API.ts ├── Core.csproj └── base.ts ├── Cmd ├── packages.config ├── IntVector3.cs ├── Properties │ └── AssemblyInfo.cs ├── JsScriptExecutor.cs ├── JsApi.cs ├── Cmd.csproj ├── Program.cs └── JsSchematicApi.cs ├── GUI ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── App.config ├── App.xaml ├── App.xaml.cs ├── GUI.csproj.user ├── MainWindow.xaml.cs ├── MainWindow.xaml └── GUI.csproj ├── .gitignore ├── Example ├── run_all.bat ├── run.bat ├── Fibonacci.ts ├── Blockhandles.ts ├── CircleCalculations.ts ├── TriangleCalculations.ts └── Calculator.ts ├── NodeCmd ├── run_example.bat ├── NodeCmd.csproj.user ├── NodeCmd.csproj └── main.js ├── LICENSE ├── README.md └── CommandBlocksJS.sln /Core/Block/Sponge.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Sponge 4 | { 5 | regular = 0, 6 | wet 7 | } 8 | } -------------------------------------------------------------------------------- /Core/Block/Dirt.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Dirt 4 | { 5 | regular = 0, 6 | coarse, 7 | podzol 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Block/CobblestoneWall.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum CobblestoneWall 4 | { 5 | regular = 0, 6 | mossy 7 | } 8 | } -------------------------------------------------------------------------------- /Core/Block/QuartzBlock.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum QuartzBlock 4 | { 5 | regular = 0, 6 | chiseled, 7 | pillar 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Block/Stonebrick.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Stonebrick 4 | { 5 | regular = 0, 6 | mossy, 7 | cracked, 8 | chiseled 9 | } 10 | } -------------------------------------------------------------------------------- /Core/Scoreboard/DisplaySlot.ts: -------------------------------------------------------------------------------- 1 | module Scoreboard 2 | { 3 | export enum DisplaySlot 4 | { 5 | belowName, 6 | sidebar, 7 | list 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/Output/OutputBlock.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export interface OutputBlock 6 | { 7 | place(position: Util.Vector3): void 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Scoreboard/Visibility.ts: -------------------------------------------------------------------------------- 1 | module Scoreboard 2 | { 3 | export enum Visibility 4 | { 5 | never, 6 | hideForOtherTeams, 7 | hideForOwnTeam, 8 | always 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Core/Block/DoublePlant.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum DoublePlant 4 | { 5 | sunflower = 0, 6 | lilac, 7 | double_tallgrass, 8 | large_fern, 9 | rose_bush, 10 | peony 11 | } 12 | } -------------------------------------------------------------------------------- /Core/Output/OutputBlockContainer.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export interface OutputBlockContainer extends OutputBlock 6 | { 7 | member: OutputBlock[]; 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Block/Slab.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Slab 4 | { 5 | stone = 0, 6 | sandstone, 7 | wooden, 8 | cobblestone, 9 | brick, 10 | stone_brick, 11 | nether_brick, 12 | quartz 13 | } 14 | } -------------------------------------------------------------------------------- /Core/Block/WoodType.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum WoodType 4 | { 5 | oak = 0, 6 | regular = 0, 7 | spruce, 8 | birch, 9 | jungle, 10 | acacia, 11 | dark = 5, 12 | dark_oak = 5 13 | } 14 | } -------------------------------------------------------------------------------- /Core/Block/Stone.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Stone 4 | { 5 | regular = 0, 6 | granite, 7 | polished_granite, 8 | diorite, 9 | polished_diorite, 10 | andesite, 11 | polished_andesite 12 | } 13 | } -------------------------------------------------------------------------------- /Cmd/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Core/Block/MonsterEgg.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum MonsterEgg 4 | { 5 | stone = 0, 6 | cobblestone, 7 | stone_brick, 8 | mossy_stone_brick, 9 | cracked_stone_brick, 10 | chiseled_stone_brick 11 | } 12 | } -------------------------------------------------------------------------------- /Core/Util/assert.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Util 4 | { 5 | export function assert(condition: boolean, message = "Assertion failed"): void 6 | { 7 | if (!condition) 8 | throw message; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /GUI/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Core/Block/Sandstone.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum Sandstone 4 | { 5 | regular = 0, 6 | chiseled, 7 | smooth 8 | } 9 | 10 | export enum RedSandstone 11 | { 12 | regular = 0, 13 | smooth, 14 | chiseled 15 | } 16 | } -------------------------------------------------------------------------------- /Core/Runtime/NumberSetMode.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export enum NumberSetMode 6 | { 7 | assign, //= 8 | divisionRemainder, //%= 9 | smallerOne, //< 10 | biggerOne, //> 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C# output directories 2 | bin/ 3 | obj/ 4 | 5 | # nuget directory 6 | packages/ 7 | 8 | # unimportant / private / generated files 9 | Core/**/*.js.map 10 | Core/**/*.js 11 | Core/**/*.d.ts 12 | Example/*.js 13 | NodeCmd/out 14 | *.suo 15 | -------------------------------------------------------------------------------- /Core/Block/RedFlower.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum RedFlower 4 | { 5 | poppy = 0, 6 | blue_orchid, 7 | allium, 8 | azure_bluet, 9 | red_tulip, 10 | orange_tulip, 11 | white_tulip, 12 | pink_tulip, 13 | oxeye_daisy 14 | } 15 | } -------------------------------------------------------------------------------- /GUI/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Core/Runtime/Variable.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export interface Variable 6 | { 7 | set(value: T): void; 8 | isExact(value: T, callback?: Function): MinecraftCommand; 9 | toTellrawExtra(): Chat.Message; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Core/Block/BlockColor.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export enum BlockColor 4 | { 5 | white = 0, 6 | orange, 7 | magenta, 8 | light_blue, 9 | yellow, 10 | lime, 11 | pink, 12 | gray, 13 | light_gray, 14 | cyan, 15 | purple, 16 | blue, 17 | brown, 18 | green, 19 | red, 20 | black 21 | } 22 | } -------------------------------------------------------------------------------- /Cmd/IntVector3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CommandBlocksJS.Cmd 4 | { 5 | public struct IntVector3 6 | { 7 | public IntVector3(int x, int y, int z) 8 | { 9 | this.x = x; 10 | this.y = y; 11 | this.z = z; 12 | } 13 | 14 | public int x; 15 | public int y; 16 | public int z; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/run_all.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | call run.bat TriangleCalculations 4 | echo. 5 | echo. 6 | echo. 7 | call run.bat Calculator 8 | echo. 9 | echo. 10 | echo. 11 | call run.bat CircleCalculations 12 | echo. 13 | echo. 14 | echo. 15 | call run.bat Fibonacci 16 | echo. 17 | echo. 18 | echo. 19 | call run.bat Blockhandles 20 | 21 | pause -------------------------------------------------------------------------------- /GUI/App.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Core/Entities/Player.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Entities 4 | { 5 | 6 | export class Player extends Selector 7 | { 8 | name: string; 9 | 10 | constructor(name: string) 11 | { 12 | super(); 13 | 14 | this.name = name; 15 | } 16 | 17 | toString(): string 18 | { 19 | return this.name; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Chat/Color.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export enum Color 6 | { 7 | black, 8 | dark_blue, 9 | dark_green, 10 | dark_aqua, 11 | dark_red, 12 | dark_purple, 13 | gold, 14 | gray, 15 | dark_gray, 16 | blue, 17 | green, 18 | aqua, 19 | red, 20 | light_purple, 21 | yellow, 22 | white 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Core/Chat/TellrawSelectorExtra.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class TellrawSelectorExtra extends Message 6 | { 7 | private selector: string; 8 | 9 | constructor(selector: Entities.Selector) 10 | { 11 | super(); 12 | 13 | this.selector = selector.toString(); 14 | 15 | delete this.text; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Core/Output/Commandblock.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class Commandblock implements OutputBlock 6 | { 7 | cmd: string; 8 | constructor(cmd: string) 9 | { 10 | this.cmd = cmd; 11 | } 12 | 13 | place(position: Util.Vector3): void 14 | { 15 | api.placeCommandBlock(this.cmd, position.x, position.y, position.z); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /GUI/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace CommandBlocksJS.GUI 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Output/CbjsFunction.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class CbjsFunction implements OutputBlockContainer 6 | { 7 | member: OutputBlock[] = []; 8 | 9 | place(position: Util.Vector3) 10 | { 11 | for (var i = 0; i < this.member.length; i++) 12 | { 13 | 14 | this.member[i].place(Manager.position); 15 | Manager.moveNext(); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/Block/SetBlockHandling.ts: -------------------------------------------------------------------------------- 1 | module Block 2 | { 3 | export class SetBlockHandling 4 | { 5 | static Replace: SetBlockHandling = new SetBlockHandling("replace"); 6 | static Destroy: SetBlockHandling = new SetBlockHandling("destroy"); 7 | static Keep: SetBlockHandling = new SetBlockHandling("keep"); 8 | 9 | constructor(public str: string) 10 | { 11 | } 12 | 13 | toString(): string 14 | { 15 | return this.str; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Core/Output/Block.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class Block implements OutputBlock 6 | { 7 | id: number; 8 | data: number; 9 | 10 | constructor(id: number, data: number = 0) 11 | { 12 | this.id = id; 13 | this.data = data; 14 | } 15 | 16 | place(position: Util.Vector3): void 17 | { 18 | api.placeBlock(this.id, this.data, position.x, position.y, position.z); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Core/Chat/TellrawScoreExtra.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class TellrawScoreExtra extends Message 6 | { 7 | private score: { [index: string]: string }; 8 | 9 | constructor(objective: Scoreboard.Objective, player: Entities.Selector) 10 | { 11 | super(); 12 | 13 | this.score = {}; 14 | this.score["objective"] = objective.name; 15 | this.score["name"] = player.toString(); 16 | 17 | delete this.text; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Util/Naming.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Util 4 | { 5 | export class Naming 6 | { 7 | static names: { [index: string]: number } = {}; 8 | 9 | /** 10 | * Generates unique names with 'name' as prefix. Will start at zero when giving a new name. 11 | * @param name Prefix for unique name. 12 | */ 13 | static next(name: string): string 14 | { 15 | this.names[name] = this.names[name] || 0; 16 | this.names[name]++; 17 | return name + this.names[name]; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NodeCmd/run_example.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | color 0A 3 | cd .\out 4 | 5 | call "C:\Program Files (x86)\nodejs\nodevars.bat" 6 | 7 | echo. 8 | 9 | set /p example=What example would you like to run? 10 | echo Compiling %example%... 11 | tsc -t ES5 .\..\..\Example\%example%.ts 12 | 13 | echo. 14 | 15 | echo Copying files... 16 | copy ".\..\..\Core\core.js" ".\core.js" 17 | copy ".\..\main.js" ".\main.js" 18 | copy ".\..\..\Example\%example%.js" ".\script.js" 19 | 20 | echo. 21 | 22 | node main.js --script script.js --ip 127.0.0.1 --port 25575 -x 0 -y 4 -z 0 23 | 24 | echo. 25 | pause -------------------------------------------------------------------------------- /Example/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Compiling %1%... 4 | tsc -t ES5 %1%.ts 5 | echo Done 6 | echo. 7 | 8 | cd ".\..\Cmd\bin\Release" 9 | 10 | echo Copying template world and libraries... 11 | xcopy ".\..\..\..\Core\core.js" ".\core.js" /Y /E /Q 12 | xcopy ".\..\..\..\Example\%1%.js" ".\example.js" /Y /E /Q 13 | xcopy "%appdata%\.minecraft\saves\egal" ".\world" /I /Y /E /Q 14 | echo Done 15 | echo. 16 | 17 | echo Running %1%... 18 | Cmd.exe -s example.js -w ./world -x 0 -y 4 -z 0 19 | xcopy ".\world" "%appdata%\.minecraft\saves\cbjs-%1%" /I /Y /E /Q 20 | cd ".\..\..\..\Example" 21 | echo Done 22 | -------------------------------------------------------------------------------- /Core/Util/Event.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Util 4 | { 5 | export class Event 6 | { 7 | private callback: Runtime.Callback; 8 | 9 | constructor() 10 | { 11 | this.callback = new Runtime.Callback(); 12 | } 13 | 14 | addListener(listener: Function): void 15 | { 16 | this.callback.add(listener); 17 | } 18 | 19 | removeListener(listener?: Function): void 20 | { 21 | if (typeof listener == 'undefined') 22 | this.callback.removeAll(); 23 | else 24 | this.callback.remove(listener); 25 | } 26 | 27 | emit(): void 28 | { 29 | this.callback.emit(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Example/Fibonacci.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var first = new Runtime.Integer(1); 4 | var second = new Runtime.Integer(1); 5 | var backup = new Runtime.Integer(); 6 | 7 | var count = new Runtime.Integer(0); 8 | 9 | var timer = new Util.Timer(calculateFibonacci, 20); 10 | timer.start(); 11 | 12 | function calculateFibonacci() 13 | { 14 | Chat.Tellraw.create( 15 | "Fibonacci after ", 16 | count.toTellrawExtra(), 17 | "-months: ", 18 | first.toTellrawExtra() 19 | ).tell(new Entities.Player("@a")); 20 | 21 | backup.set(first); 22 | first.add(second); 23 | second.set(backup); 24 | 25 | count.add(1); 26 | } 27 | -------------------------------------------------------------------------------- /Core/Output/ValidateIntializer.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class ValidateIntializer implements OutputBlock 6 | { 7 | static position: Util.Vector3; 8 | 9 | place(_position: Util.Vector3): void 10 | { 11 | if (typeof ValidateIntializer.position != 'undefined') 12 | throw "Cannot intialize validate armorstand twice"; 13 | 14 | ValidateIntializer.position = _position.clone(); 15 | ValidateIntializer.position.y++; 16 | 17 | api.placeCommandBlock("summon ArmorStand ~ ~1 ~ {NoGravity:1,CustomName:validate}", _position.x, _position.y, _position.z); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Chat/Events/HoverEvent.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class HoverEvent 6 | { 7 | static showText(text: string) { return new HoverEvent("show_text", text); } 8 | static showItem(item: string) { return new HoverEvent("show_item", item); } 9 | static showAchievement(name: string) { return new HoverEvent("show_achievement", name); } 10 | static showEntity(entity: string) { return new HoverEvent("show_entity", entity); } 11 | 12 | action: string; 13 | value: string; 14 | 15 | constructor(action: string, value: string) 16 | { 17 | this.action = action; 18 | this.value = value; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Core/Chat/Events/ClickEvent.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class ClickEvent 6 | { 7 | static runCommand(cmd: string) { return new ClickEvent("run_command", cmd); } 8 | static openUrl(url: string) { return new ClickEvent("open_url", url); } 9 | static changePage(page: number) { return new ClickEvent("change_page", page.toString()); } 10 | static suggestCommand(cmd: string) { return new ClickEvent("suggest_command", cmd); } 11 | 12 | action: string; 13 | value: string; 14 | 15 | constructor(action: string, value: string) 16 | { 17 | this.action = action; 18 | this.value = value; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /GUI/GUI.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | publish\ 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | 14 | false 15 | 16 | -------------------------------------------------------------------------------- /Core/Players/GameMode.ts: -------------------------------------------------------------------------------- 1 | module Players 2 | { 3 | export class GameMode 4 | { 5 | static Survival: GameMode = new GameMode(0, "s", "survival"); 6 | static Creative: GameMode = new GameMode(1, "c", "creative"); 7 | static Adventure: GameMode = new GameMode(2, "a", "adventure"); 8 | static Spectator: GameMode = new GameMode(3, "sp", "spectator"); 9 | 10 | constructor(public id: number, public shortStr: string, public longStr: string) 11 | { 12 | } 13 | 14 | toNumber(): number 15 | { 16 | return this.id; 17 | } 18 | 19 | toString(): string 20 | { 21 | return this.shortStr; 22 | } 23 | 24 | toLongString(): string 25 | { 26 | return this.longStr; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Core/Entities/SelectorTarget.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Entities 4 | { 5 | export class SelectorTarget 6 | { 7 | static a = new SelectorTarget("a"); 8 | static e = new SelectorTarget("e"); 9 | static p = new SelectorTarget("p"); 10 | static r = new SelectorTarget("r"); 11 | 12 | static AllPlayer = SelectorTarget.a; 13 | static Entities = SelectorTarget.e; 14 | static NearestPlayer = SelectorTarget.p; 15 | static RandomPlayer = SelectorTarget.r; 16 | 17 | identifier: string; 18 | 19 | constructor(identifier: string) 20 | { 21 | Util.assert(["a", "e", "p", "r"].indexOf(identifier) != -1, "Invalid identifier!"); 22 | this.identifier = identifier; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Core/Output/Sign.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class Sign implements OutputBlock 6 | { 7 | text1: string; 8 | text2: string; 9 | text3: string; 10 | text4: string; 11 | 12 | orientation: number; 13 | 14 | constructor(text1: string, text2: string, text3: string, text4: string, orientation: number) 15 | { 16 | this.text1 = text1; 17 | this.text2 = text2; 18 | this.text3 = text3; 19 | this.text4 = text4; 20 | 21 | this.orientation = orientation; 22 | } 23 | 24 | place(position: Util.Vector3): void 25 | { 26 | var texts = [this.text1, this.text2, this.text3, this.text4]; 27 | api.placeSign(texts, this.orientation, position.x, position.y, position.z); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Core/Runtime/Number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export interface Number extends Variable 6 | { 7 | set(value: number, mode?: NumberSetMode): void; 8 | set(value: Number, mode?: NumberSetMode): void; 9 | 10 | add(other: number): void; 11 | add(other: Number): void; 12 | 13 | remove(other: number): void; 14 | remove(other: Number): void; 15 | 16 | multiplicate(other: number): void; 17 | multiplicate(other: Number): void; 18 | 19 | divide(other: number): void; 20 | divide(other: Number): void; 21 | 22 | swap(other: Number): void; 23 | 24 | clone(cloneName?: string): Number; 25 | 26 | isBetween(min: number, max: number, callback?: Function): MinecraftCommand 27 | 28 | toInteger(): Integer; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Core/Util/Vector3.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Util 4 | { 5 | export class Vector3 6 | { 7 | x: number = 0; 8 | y: number = 0; 9 | z: number = 0; 10 | 11 | constructor(x: number = 0, y: number = 0, z: number = 0) 12 | { 13 | this.x = x; 14 | this.y = y; 15 | this.z = z; 16 | } 17 | 18 | toString(separator: string = ' '): string 19 | { 20 | return this.x + separator + this.y + separator + this.z; 21 | } 22 | 23 | add(b: Vector3): Vector3 24 | { 25 | this.x += b.x; 26 | this.y += b.y; 27 | this.z += b.z; 28 | 29 | return this; 30 | } 31 | 32 | subtract(b: Vector3): Vector3 33 | { 34 | this.x -= b.x; 35 | this.y -= b.y; 36 | this.z -= b.z; 37 | 38 | return this; 39 | } 40 | 41 | clone(): Vector3 42 | { 43 | return new Vector3(this.x, this.y, this.z); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Core/Scoreboard/ObjectiveType.ts: -------------------------------------------------------------------------------- 1 | module Scoreboard 2 | { 3 | export class ObjectiveType 4 | { 5 | static dummy = new ObjectiveType("dummy"); 6 | static trigger = new ObjectiveType("trigger"); 7 | static deathCount = new ObjectiveType("deathCount"); 8 | static playerKillCount = new ObjectiveType("playerKillCount"); 9 | static totalKillCount = new ObjectiveType("totalKillCount"); 10 | static health = new ObjectiveType("health"); 11 | 12 | static killEntity(entity: Entities.EntityType): ObjectiveType 13 | { 14 | return new ObjectiveType("stat.killEntity." + entity.name); 15 | } 16 | static entityKilledBy(entity: Entities.EntityType): ObjectiveType 17 | { 18 | return new ObjectiveType("stat.entityKilledBy." + entity.name); 19 | } 20 | //TODO add all 21 | 22 | value: string; 23 | constructor(value: string) 24 | { 25 | this.value = value; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Core/Chat/Events/CallbackClickEvent.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class CallbackClickEvent 6 | { 7 | static score: Scoreboard.Objective = new Scoreboard.Objective(Scoreboard.ObjectiveType.trigger, "callbackClick", undefined, false); 8 | static clickEventCallbacks: number[] = []; 9 | 10 | callback: Function; 11 | action: string; 12 | value: string; 13 | 14 | constructor(callback: Function) 15 | { 16 | usedLibs["callbackClickEvent"] = true; 17 | usedLibs["setTimeout"] = true; 18 | 19 | this.callback = callback; 20 | } 21 | 22 | intialize(): void 23 | { 24 | var id = outputHandler.addFunction(this.callback); 25 | this.action = "run_command"; 26 | this.value = "/trigger callbackClick set {0}".format(id); 27 | 28 | command("kill @e[type=ArmorStand,name=function{0}]".format(id)); 29 | 30 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.timeoutCommand.format(id))); 31 | 32 | CallbackClickEvent.clickEventCallbacks.push(id); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Cmd/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | [assembly: AssemblyTitle("Cmd")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("")] 11 | [assembly: AssemblyCopyright("Agent J")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 15 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 16 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 17 | [assembly: AssemblyVersion("1.0.*")] 18 | // The following attributes are used to specify the signing key for the assembly, 19 | // if desired. See the Mono documentation for more information about signing. 20 | //[assembly: AssemblyDelaySign(false)] 21 | //[assembly: AssemblyKeyFile("")] 22 | 23 | -------------------------------------------------------------------------------- /Example/Blockhandles.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var handle = new Block.BlockHandle(new Util.Vector3(0, 8, 0), "wool", 0); 4 | 5 | function fill(x, y, w, h, color) 6 | { 7 | handle.data = color; 8 | handle.fill(x, 8 + y, 0, x + w - 1, 8 + y + h - 1, 0); 9 | } 10 | 11 | // pretty ugly code but the output looks nice: 12 | // http://i.imgur.com/bJkpFjW.png 13 | 14 | fill(0, 0, 16, 9, Block.BlockColor.cyan); 15 | 16 | fill(0, 2, 2, 1, Block.BlockColor.green); 17 | fill(1, 3, 7, 1, Block.BlockColor.green); 18 | fill(7, 2, 4, 1, Block.BlockColor.green); 19 | fill(10, 1, 6, 1, Block.BlockColor.green); 20 | fill(2, 6, 3, 2, Block.BlockColor.green); 21 | fill(9, 5, 3, 2, Block.BlockColor.green); 22 | fill(3, 8, 1, 1, Block.BlockColor.green); 23 | fill(10, 7, 1, 1, Block.BlockColor.green); 24 | 25 | fill(0, 0, 16, 1, Block.BlockColor.brown); 26 | fill(0, 1, 10, 1, Block.BlockColor.brown); 27 | fill(2, 2, 5, 1, Block.BlockColor.brown); 28 | fill(3, 4, 1, 2, Block.BlockColor.brown); 29 | fill(10, 3, 1, 2, Block.BlockColor.brown); 30 | 31 | fill(14, 6, 2, 1, Block.BlockColor.yellow); 32 | fill(13, 7, 3, 2, Block.BlockColor.yellow); -------------------------------------------------------------------------------- /Core/Core.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | CurrentPage 10 | True 11 | False 12 | False 13 | False 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | True 23 | True 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NodeCmd/NodeCmd.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | CurrentPage 10 | True 11 | False 12 | False 13 | False 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | True 23 | True 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/CircleCalculations.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //start at radius 4 | var startRadius = 1; 5 | //stop at radius 6 | var stopRadius = 20; 7 | //step 8 | var step = 1; 9 | 10 | var radius = new Runtime.Decimal(startRadius); 11 | 12 | call(calculate); 13 | 14 | function calculate() 15 | { 16 | var circumference = new Runtime.Decimal(); 17 | var area = new Runtime.Decimal(); 18 | 19 | var pi = Runtime.Decimal.Pi; 20 | 21 | // C = 2 * pi * r 22 | circumference.set(radius); 23 | circumference.multiplicate(pi); 24 | circumference.multiplicate(2); 25 | 26 | // A = r * r * pi 27 | area.set(radius); 28 | area.multiplicate(area); 29 | area.multiplicate(pi); 30 | 31 | // output current values 32 | Chat.Tellraw.create( 33 | "r = ", 34 | radius.toTellrawExtra(), 35 | ", C = ", 36 | circumference.toExactTellrawExtra(), 37 | ", A = ", 38 | area.toExactTellrawExtra() 39 | ).tell(new Entities.Player("@a")); 40 | 41 | //add step to radius 42 | radius.add(step); 43 | 44 | //if radius is between startRadius and stopRadius call calculate 45 | radius.isBetween(startRadius, stopRadius, calculate); 46 | } 47 | -------------------------------------------------------------------------------- /Core/Chat/Message.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class Message 6 | { 7 | text: string; 8 | bold: boolean; 9 | italic: boolean; 10 | obfuscated: boolean; 11 | underlined: boolean; 12 | strikethrough: boolean; 13 | 14 | private color: string; 15 | 16 | set Color(value: Color) 17 | { 18 | this.color = Color[value]; 19 | } 20 | get Color(): Color 21 | { 22 | return Color[this.color]; 23 | } 24 | 25 | clickEvent: ClickEvent; 26 | hoverEvent: HoverEvent; 27 | 28 | constructor(text: string = "", 29 | color: Color = Color.white, 30 | bold: boolean = false, 31 | italic: boolean = false, 32 | obfuscated: boolean = false, 33 | underlined: boolean = false, 34 | strikethrough: boolean = false, 35 | clickEvent?: ClickEvent, 36 | hoverEvent?: HoverEvent 37 | ) 38 | { 39 | this.text = text; 40 | this.Color = color; 41 | this.bold = bold; 42 | this.italic = italic; 43 | this.obfuscated = obfuscated; 44 | this.underlined = underlined; 45 | this.strikethrough = strikethrough; 46 | 47 | this.clickEvent = clickEvent; 48 | this.hoverEvent = hoverEvent; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /GUI/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.18444 5 | // 6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 | // der Code erneut generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CommandBlocksJS.GUI.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/Runtime/Boolean.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class Boolean implements Variable 6 | { 7 | static trueValue = 1; 8 | static falseValue = 0; 9 | 10 | base: Integer; 11 | 12 | constructor(startValue?: boolean, name?: string) 13 | constructor(startValue?: boolean, selector?: Entities.Selector) 14 | constructor(startValue: boolean = false, selector: any = Util.Naming.next("bool")) 15 | { 16 | var value = startValue ? 1 : 0; 17 | this.base = new Integer(value, selector); 18 | } 19 | 20 | set(value: boolean): void 21 | { 22 | if(value) 23 | this.base.set(1); 24 | else 25 | this.base.set(0); 26 | } 27 | 28 | isExact(value: boolean, callback?: Function): MinecraftCommand 29 | { 30 | if (value) 31 | return this.base.isExact(1, callback); 32 | else 33 | return this.base.isExact(0, callback); 34 | } 35 | 36 | isTrue(callback?: Function): MinecraftCommand 37 | { 38 | return this.isExact(true, callback); 39 | } 40 | isFalse(callback?: Function): MinecraftCommand 41 | { 42 | return this.isExact(false, callback); 43 | } 44 | 45 | toTellrawExtra(): Chat.TellrawScoreExtra 46 | { 47 | return this.base.toTellrawExtra(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Core/Util/Timer.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Util 4 | { 5 | export class Timer 6 | { 7 | public delay: Runtime.Integer; 8 | private timerFunc: Function; 9 | 10 | private isRunning: Runtime.Integer; 11 | public get IsRunning(): MinecraftCommand 12 | { 13 | return this.isRunning.isBetween(1); 14 | } 15 | 16 | constructor(callback: Function, delay: number = 20, start: boolean = false) 17 | { 18 | var name = Naming.next("timer"); 19 | this.delay = new Runtime.Integer(delay, name); 20 | this.isRunning = new Runtime.Integer(0, name + "Running"); 21 | 22 | var that = this; 23 | this.timerFunc = function () 24 | { 25 | callback(); 26 | 27 | that.isRunning.isBetween(1, undefined, function () 28 | { 29 | setTimeout(that.timerFunc, that.delay); 30 | }); 31 | } 32 | 33 | if (start) 34 | this.start(); 35 | } 36 | 37 | start() 38 | { 39 | this.isRunning.set(1); 40 | this.IsRunning.validate(this.timerFunc); 41 | } 42 | 43 | stop() 44 | { 45 | this.isRunning.set(0); 46 | } 47 | 48 | setDelay(value: number): void 49 | setDelay(value: Number): void 50 | setDelay(value: any): void 51 | { 52 | this.delay.set(value); 53 | } 54 | 55 | getDelay(): Runtime.Integer 56 | { 57 | return this.delay.clone(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Core/Chat/Tellraw.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Chat 4 | { 5 | export class Tellraw extends Message 6 | { 7 | static create(...args: any[]): Tellraw 8 | { 9 | var tellraw = new Tellraw(); 10 | function addToTellraw(obj: any) 11 | { 12 | if (obj instanceof Array) 13 | for (var i = 0; i < obj.length; i++) 14 | addToTellraw(obj[i]); 15 | else if (typeof obj == 'string' || typeof obj == 'number' || typeof obj == 'boolean') 16 | tellraw.extra.push(new Chat.Message(obj.toString())); 17 | else if (obj instanceof Chat.Message) 18 | tellraw.extra.push(obj); 19 | else 20 | throw "Tellraw.create only accepts Chat.Message, primitives and arrays not '" + obj.constructor.name + "'"; 21 | } 22 | 23 | addToTellraw(args); 24 | return tellraw; 25 | } 26 | 27 | extra: Message[] = []; 28 | 29 | tell(selector: Entities.Selector) 30 | { 31 | this.generate(selector).run(); 32 | } 33 | generate(target: Entities.Selector): MinecraftCommand 34 | { 35 | var cmd = "tellraw " + target.toString(); 36 | 37 | var src = JSON.stringify(this, (key, value) => 38 | { 39 | if (value instanceof CallbackClickEvent) 40 | (value).intialize(); 41 | 42 | if (value instanceof Entities.Selector) 43 | return value.toString(); 44 | else 45 | return value; 46 | }); 47 | 48 | return new MinecraftCommand(cmd + " " + src); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Example/TriangleCalculations.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // uncomment if u want to get eye cancer :3 4 | // Runtime.Integer.score.setDisplay(Scoreboard.DisplaySlot.sidebar); 5 | 6 | //try -3.12 as start value 7 | var sinValue = new Runtime.Decimal(0); 8 | 9 | var pythValue = new Runtime.Integer(1); 10 | 11 | call(calculateSinus); 12 | 13 | function calculateSinus() 14 | { 15 | var result = new Runtime.Decimal(); 16 | 17 | Util.Math.sin(sinValue, result, function () 18 | { 19 | Chat.Tellraw.create("Sinus of ", sinValue.toExactTellrawExtra(), " is ", result.toExactTellrawExtra()).tell(Entities.Selector.AllPlayer); 20 | 21 | sinValue.add(0.39); 22 | 23 | // from infinite to 3 24 | // when finished start pythagoras calculation 25 | sinValue.isBetween(undefined, 3).validate(calculateSinus, calculatePythagoras); 26 | }); 27 | } 28 | 29 | function calculatePythagoras() 30 | { 31 | var result = new Runtime.Integer(); 32 | 33 | var value = new Runtime.Integer(0); 34 | value.add(pythValue); 35 | value.multiplicate(pythValue); 36 | value.add(value); 37 | 38 | Util.Math.sqrt(value, result, function () 39 | { 40 | Chat.Tellraw.create("Pythagoras: a = b = ", pythValue.toTellrawExtra(), " => c = ", result.toTellrawExtra()).tell(Entities.Selector.AllPlayer); 41 | 42 | //step 5 43 | pythValue.add(5); 44 | 45 | // from infinite to 30 46 | pythValue.isBetween(undefined, 30, calculatePythagoras); 47 | }); 48 | } 49 | 50 | // TODO cos ... 51 | 52 | -------------------------------------------------------------------------------- /Core/MinecraftCommand.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | class MinecraftCommand 4 | { 5 | cmd: string; 6 | 7 | constructor(cmd: string) 8 | { 9 | this.cmd = cmd; 10 | } 11 | 12 | run(): void 13 | { 14 | command(this.cmd); 15 | } 16 | 17 | validate(callback?: Function, otherwise?: Function, useSetblock: boolean = false): void 18 | { 19 | usedLibs["integer"] = true; 20 | usedLibs["validate"] = true; 21 | 22 | if (!useSetblock) 23 | usedLibs["setTimeout"] = true; 24 | 25 | command("execute @e[name=validate] ~ ~ ~ " + this.cmd); 26 | 27 | if (typeof callback != 'undefined') 28 | { 29 | var id = outputHandler.addFunction(callback); 30 | 31 | if (useSetblock) 32 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.setblockCallCommand, "@e[name=validate,score_stdInteger_min=1]")); 33 | else 34 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.armorstandCallCommand, "@e[name=validate,score_stdInteger_min=1]")); 35 | } 36 | if (typeof otherwise != 'undefined') 37 | { 38 | var id = outputHandler.addFunction(otherwise); 39 | if (useSetblock) 40 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.setblockCallCommand, "@e[name=validate,score_stdInteger=0]")); 41 | else 42 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.armorstandCallCommand, "@e[name=validate,score_stdInteger=0]")); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Core/Output/FunctionCall.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Output 4 | { 5 | export class FunctionCall implements OutputBlock 6 | { 7 | static timeoutCommand = 'execute %selector ~ ~ ~ summon ArmorStand ~%X ~%Y ~%Z {CustomName:"function{0}",NoGravity:true,Invincible:true,PersistenceRequired:true}'; 8 | static armorstandCallCommand = 'execute %selector ~ ~ ~ summon ArmorStand ~%X ~%Y ~%Z {CustomName:"call",NoGravity:true,Invincible:true,PersistenceRequired:true}'; 9 | static setblockCallCommand = 'execute %selector ~ ~ ~ setblock ~%X ~%Y ~%Z minecraft:redstone_block 0 replace'; 10 | 11 | id: number 12 | cmd: string; 13 | selector: string; 14 | 15 | constructor(id: number, cmd: string = FunctionCall.setblockCallCommand, validateSelector: string = "@e[name=validate]") 16 | { 17 | this.id = id; 18 | this.cmd = cmd; 19 | this.selector = validateSelector; 20 | } 21 | 22 | place(position: Util.Vector3): void 23 | { 24 | var ePosition = Manager.functionPositions[this.id]; 25 | var pos = ValidateIntializer.position; 26 | 27 | var offX = ePosition.x - pos.x; 28 | var offY = ePosition.y - pos.y - 1; 29 | var offZ = ePosition.z - pos.z; 30 | 31 | var _cmd = this.cmd.replace(/%X/g, offX.toString()); 32 | _cmd = _cmd.replace(/%Y/g, offY.toString()); 33 | _cmd = _cmd.replace(/%Z/g, offZ.toString()); 34 | _cmd = _cmd.replace(/%selector/g, this.selector); 35 | 36 | api.placeCommandBlock(_cmd, position.x, position.y, position.z); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Core/Scoreboard/Team.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Scoreboard 4 | { 5 | export class Team 6 | { 7 | name: string; 8 | 9 | constructor(name: string = Util.Naming.next("team"), displayName: string = "") 10 | { 11 | this.name = name; 12 | command("scoreboard teams add " + name + " " + displayName); 13 | } 14 | 15 | empty() 16 | { 17 | command("scoreboard teams empty " + this.name); 18 | } 19 | 20 | join(selector: Selector) 21 | { 22 | command("scoreboard teams join " + this.name + " " + selector); 23 | } 24 | 25 | static leave(selector: Selector) 26 | { 27 | command("scoreboard teams leave " + selector); 28 | } 29 | leave(selector: Selector) 30 | { 31 | command("scoreboard teams leave " + this.name + " " + selector); 32 | } 33 | 34 | set firendlyFire(value: boolean) 35 | { 36 | command("scoreboard teams option " + this.name + " friendlyFire " + value); 37 | } 38 | set seeFriendlyInvisibles(value: boolean) 39 | { 40 | command("scoreboard teams option " + this.name + " seeFriendlyInvisibles " + value); 41 | } 42 | 43 | set color(value: Chat.Color) 44 | { 45 | command("scoreboard teams option " + this.name + " color " + Chat.Color[value]); 46 | } 47 | 48 | set nametagVisibility(value: Visibility) 49 | { 50 | command("scoreboard teams option " + this.name + " nametagVisibility " + Visibility[value]); 51 | } 52 | set deathMessageVisibility(value: Visibility) 53 | { 54 | command("scoreboard teams option " + this.name + " deathMessageVisibility " + Visibility[value]); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Core/Runtime/String.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class String implements Variable 6 | { 7 | static score: Scoreboard.Objective = new Scoreboard.Objective(Scoreboard.ObjectiveType.dummy, "stdStrings", "RuntimeString", false); 8 | private static lastIndex: number = 1; 9 | 10 | index: number; 11 | selector: Entities.Selector; 12 | 13 | constructor(value: string = Util.Naming.next("string")) 14 | { 15 | usedLibs["string"] = true; 16 | 17 | this.index = String.lastIndex; 18 | 19 | this.selector = Entities.Selector.parse("@e[score_stdStrings_min=" + this.index + ",score_stdStrings=" + this.index + "]"); 20 | 21 | command('kill ' + this.selector.toString()); 22 | command('summon ArmorStand ~ ~1 ~ {CustomName:"' + value + '",NoGravity:true,Invincible:true,PersistenceRequired:true}'); 23 | 24 | var sel = Entities.Selector.parse('@e[type=ArmorStand,name=' + value + ',r=5]'); 25 | String.score.set(sel, String.lastIndex); 26 | String.lastIndex++; 27 | } 28 | 29 | set(value: string): void 30 | { 31 | command('entitydata ' + this.selector + ' {CustomName:"' + value + '"}'); 32 | } 33 | 34 | isExact(value: string, callback?: Function): MinecraftCommand 35 | { 36 | var sel = Entities.Selector.parse('@e[type=ArmorStand,name=' + value + ']'); 37 | var cmd = String.score.test(sel, this.index, this.index); 38 | 39 | if (typeof callback == 'function') 40 | cmd.validate(callback); 41 | 42 | return cmd; 43 | } 44 | 45 | toTellrawExtra(): Chat.TellrawSelectorExtra 46 | { 47 | return new Chat.TellrawSelectorExtra(this.selector); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Jakob Löw 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 3. All advertising materials mentioning features or use of this software 12 | must display the following acknowledgement: 13 | "This product includes software developed by Jakob Löw (M4GNV5)." 14 | 4. The name of the contributor may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY Jakob Löw (M4GNV5) ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL Jakob Löw (M4GNV5) BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /Cmd/JsScriptExecutor.cs: -------------------------------------------------------------------------------- 1 | using CommandblocksJS.Cmd; 2 | using Noesis.Javascript; 3 | using System; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace CommandBlocksJS.Cmd 8 | { 9 | public class JsScriptExecutor 10 | { 11 | public void Run(string coreJsPath, string scriptPath, string worldDirectory, IntVector3 position, bool isSchematic) 12 | { 13 | string coreCode = File.ReadAllText(coreJsPath); 14 | string usercode = File.ReadAllText(scriptPath); 15 | JavascriptContext jsContext = new JavascriptContext(); 16 | 17 | if (!isSchematic) 18 | jsContext.SetParameter("api", new JsApi(worldDirectory)); 19 | else 20 | jsContext.SetParameter("api", new JsSchematicApi(worldDirectory)); 21 | #if DEBUG 22 | jsContext.Run(coreCode); 23 | jsContext.Run("var startPosition = new Util.Vector3(" + position.x + ", " + position.y + ", " + position.z + ");"); 24 | #else 25 | try 26 | { 27 | jsContext.Run(coreCode); 28 | jsContext.Run(string.Format("var startPosition = new Util.Vector3({0}, {1}, {2});", position.x, position.y, position.z)); 29 | } 30 | catch (JavascriptException e) 31 | { 32 | string error = string.Format("Javascripterror: '{0}' at Line {1} Column {2} to {3}", e.Message, e.Line, e.StartColumn, e.EndColumn); 33 | throw new SystemException("Error in CommandblockJS Core Javascript code! Please make sure you are using the latest build!\n\n" + error); 34 | } 35 | #endif 36 | 37 | #if DEBUG 38 | jsContext.Run(usercode + "\n cbjsWorker();"); 39 | #else 40 | try 41 | { 42 | jsContext.Run(usercode + "\n cbjsWorker();"); 43 | } 44 | catch(JavascriptException e) 45 | { 46 | string message = string.Format("Javascripterror: '{0}' at Line {1} Column {2} to {3}", e.Message, e.Line, e.StartColumn, e.EndColumn); 47 | throw new ApplicationException(message); 48 | } 49 | #endif 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Core/Block/BlockHandle.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Block 4 | { 5 | export class BlockHandle 6 | { 7 | x: number; 8 | y: number; 9 | z: number; 10 | material: BlockMaterial; 11 | data: number; 12 | 13 | constructor(positionOrX, materialOrY, dataOrZ, material?, data?) 14 | { 15 | if (positionOrX instanceof Util.Vector3) 16 | { 17 | var position = positionOrX; 18 | this.x = position.x; 19 | this.y = position.y; 20 | this.z = position.z; 21 | this.material = materialOrY; 22 | this.data = dataOrZ; 23 | } 24 | else 25 | { 26 | this.x = positionOrX; 27 | this.y = materialOrY; 28 | this.z = dataOrZ; 29 | this.material = material; 30 | this.data = data; 31 | } 32 | } 33 | 34 | /** 35 | * Checks if the block equals what this instance saved at compiletime. Use equals for runtime instead. 36 | */ 37 | assumeEqual(material: BlockMaterial, data: number = 0): boolean 38 | { 39 | return this.material.toString() == material.toString() && this.data == data; 40 | } 41 | 42 | /** 43 | * Checks if the block equals material at runtime. Use assumeEqual for compiletime instead. 44 | */ 45 | equals(material: BlockMaterial, data: number = 0): MinecraftCommand 46 | { 47 | return new MinecraftCommand("tesforblock {0} {1} {2} {3} {4}".format(this.x, this.y, this.z, material.toString(), data)); 48 | } 49 | 50 | place(oldHandling: SetBlockHandling = SetBlockHandling.Replace): void 51 | { 52 | command("setblock {0} {1} {2} {3} {4} {5}".format(this.x, this.y, this.z, this.material.toString(), this.data, oldHandling.toString())); 53 | } 54 | 55 | fill(x: number, y: number, z: number, x2: number, y2: number, z2: number, oldHandling: SetBlockHandling = SetBlockHandling.Replace): void 56 | { 57 | command("fill {0} {1} {2} {3} {4} {5} {6} {7} {8}".format(x, y, z, x2, y2, z2, this.material.toString(), this.data, oldHandling.toString())); 58 | } 59 | 60 | replace(material: BlockMaterial, data: number = 0, oldHandling: SetBlockHandling = SetBlockHandling.Replace): void 61 | { 62 | this.material = material; 63 | this.data = data; 64 | this.place(oldHandling); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Core/Runtime/Callback.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class Callback implements Variable 6 | { 7 | private static score: Scoreboard.Objective; 8 | private static lastValue: number = 1; 9 | 10 | private identifierValue: number; 11 | 12 | constructor() 13 | { 14 | if (typeof Callback.score == 'undefined') 15 | Callback.score = new Scoreboard.Objective(Scoreboard.ObjectiveType.dummy, "callback"); 16 | 17 | this.identifierValue = Callback.lastValue; 18 | Callback.lastValue++; 19 | } 20 | 21 | set(value: Function): void 22 | { 23 | this.removeAll(); 24 | this.add(value); 25 | } 26 | add(func: Function): void 27 | { 28 | var id = outputHandler.addFunction(func); 29 | outputHandler.addToCurrent(new Output.FunctionCall(id, Output.FunctionCall.timeoutCommand.format(id))); 30 | 31 | var sel = Entities.Selector.parse("@e[name=function{0}]".format(id)); 32 | Callback.score.set(sel, this.identifierValue); 33 | } 34 | 35 | remove(func: Function): void 36 | { 37 | var id = outputHandler.addFunction(func); 38 | command("kill @e[score_callback_min={0},score_callback={0},name=function{1}]".format(this.identifierValue, id)); 39 | } 40 | removeAll(): void 41 | { 42 | command("kill @e[score_callback_min={0},score_callback={0}]".format(this.identifierValue)); 43 | } 44 | 45 | emit(): void 46 | { 47 | command("execute @e[score_callback_min={0},score_callback={0}] ~ ~ ~ setblock ~ ~ ~ minecraft:redstone_block 0 replace".format(this.identifierValue)); 48 | } 49 | 50 | isExact(value: Function, callback?: Function): MinecraftCommand 51 | { 52 | return this.hasListener(value, callback); 53 | } 54 | hasListener(value: Function, callback?: Function): MinecraftCommand 55 | { 56 | var id = outputHandler.addFunction(value); 57 | var cmd = new MinecraftCommand("testfor @e[score_callback_min={0},score_callback={0},name=function{1}]".format(this.identifierValue, id)); 58 | 59 | if (typeof callback == 'function') 60 | cmd.validate(callback); 61 | 62 | return cmd; 63 | } 64 | 65 | toTellrawExtra(): Chat.TellrawSelectorExtra 66 | { 67 | var sel = Entities.Selector.parse("@e[score_callback_min={0},score_callback={0}]".format(this.identifierValue)); 68 | return new Chat.TellrawSelectorExtra(sel); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Cmd/JsApi.cs: -------------------------------------------------------------------------------- 1 | using Substrate; 2 | using Substrate.Core; 3 | using Substrate.TileEntities; 4 | using System; 5 | using System.IO; 6 | 7 | namespace CommandBlocksJS.Cmd 8 | { 9 | public class JsApi 10 | { 11 | private NbtWorld world; 12 | private IBlockManager blockManager; 13 | 14 | public JsApi(string worldDirectory) 15 | { 16 | if (!Directory.Exists(worldDirectory)) 17 | Directory.CreateDirectory(worldDirectory); 18 | 19 | this.world = AnvilWorld.Create(worldDirectory); 20 | this.blockManager = this.world.GetBlockManager(); 21 | } 22 | 23 | public void log(string message) 24 | { 25 | Console.WriteLine(message); 26 | } 27 | 28 | public void disco(int wait = 1, int count = 1) 29 | {//this is defnitly not an easter egg 30 | for (int i = 0; i < count; i++) 31 | { 32 | Console.Beep(); 33 | System.Threading.Thread.Sleep(wait); 34 | } 35 | } 36 | 37 | public void placeBlock(int id, int data, int x, int y, int z) 38 | { 39 | int blockBelow = blockManager.GetID(x, y - 1, z); 40 | 41 | if (blockBelow == BlockType.AIR 42 | || blockBelow == BlockType.WATER 43 | || blockBelow == BlockType.STATIONARY_WATER 44 | || blockBelow == BlockType.LAVA 45 | || blockBelow == BlockType.STATIONARY_LAVA) 46 | { 47 | blockManager.SetID(x, y - 1, z, BlockType.STONE); 48 | blockManager.SetData(x, y - 1, z, 0); 49 | } 50 | 51 | blockManager.SetID(x, y, z, id); 52 | blockManager.SetData(x, y, z, data); 53 | } 54 | 55 | public void placeCommandBlock(string command, int x, int y, int z) 56 | { 57 | AlphaBlock cblock = new AlphaBlock(BlockType.COMMAND_BLOCK); 58 | TileEntityControl te = cblock.GetTileEntity() as TileEntityControl; //unsafe 59 | te.Command = command; 60 | blockManager.SetBlock(x, y, z, cblock); 61 | } 62 | 63 | public void placeSign(string[] text, int direction, int x, int y, int z) 64 | { 65 | AlphaBlock sign = new AlphaBlock(BlockType.SIGN_POST); 66 | TileEntitySign te = sign.GetTileEntity() as TileEntitySign; 67 | sign.Data = direction; 68 | 69 | if (text.Length > 0) 70 | te.Text1 = text[0]; 71 | if (text.Length > 1) 72 | te.Text2 = text[1]; 73 | if (text.Length > 2) 74 | te.Text3 = text[2]; 75 | if (text.Length > 3) 76 | te.Text4 = text[3]; 77 | } 78 | 79 | public void save() 80 | { 81 | world.Save(); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Core/Output/Manager.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare var startPosition: Util.Vector3; 4 | 5 | module Output 6 | { 7 | export class Manager 8 | { 9 | static position: Util.Vector3; 10 | static currentFunction: number; 11 | 12 | static direction: number = 1; 13 | static functionPositions: Util.Vector3[] = []; 14 | static functions: Output.CbjsFunction[] = []; 15 | 16 | static start(): void 17 | { 18 | this.position = startPosition; 19 | 20 | var maxLength = 0; 21 | for (var i = 0; i < this.functions.length; i++) 22 | { 23 | if (this.functions[i].member.length > maxLength) 24 | { 25 | maxLength = this.functions[i].member.length; 26 | } 27 | } 28 | 29 | var usedFuncs: CbjsFunction[] = []; 30 | for (var i = 0; i < this.functions.length; i++) 31 | { 32 | if (usedFuncs.indexOf(this.functions[i]) !== -1) 33 | continue; 34 | 35 | this.functionPositions[i] = this.position.clone(); 36 | var length: number = this.functions[i].member.length; 37 | usedFuncs.push(this.functions[i]); 38 | 39 | if (length + 1 < maxLength) 40 | { 41 | for (var ii = 0; ii < this.functions.length; ii++) 42 | { 43 | var otherLength = this.functions[ii].member.length; 44 | 45 | if (length + otherLength + 1 < maxLength && usedFuncs.indexOf(this.functions[ii]) === -1) 46 | { 47 | usedFuncs.push(this.functions[ii]); 48 | 49 | this.functionPositions[ii] = this.position.clone(); 50 | this.functionPositions[ii].x += length + 1; 51 | 52 | length += otherLength + 1; 53 | } 54 | } 55 | } 56 | 57 | this.position.z += 2; 58 | } 59 | 60 | for (var i = 0; i < this.functions.length; i++) 61 | { 62 | this.currentFunction = i; 63 | this.position = this.functionPositions[i].clone(); 64 | this.functions[i].place(this.position); 65 | } 66 | 67 | api.save(); 68 | } 69 | 70 | static moveNext() 71 | { 72 | this.position.x++; 73 | } 74 | 75 | static updatePosition(xMinus: Function, xPlus: Function, zMinus: Function, zPlus: Function): void 76 | { 77 | switch (Manager.direction) 78 | { 79 | case 0: 80 | zMinus(); 81 | break; 82 | case 1: 83 | xPlus(); 84 | break; 85 | case 2: 86 | zPlus(); 87 | break; 88 | case 3: 89 | xMinus(); 90 | break; 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /GUI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("Cmd.GUI")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("Cmd.GUI")] 15 | [assembly: AssemblyCopyright("Copyright © 2014")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /Core/Scoreboard/Objective.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import Selector = Entities.Selector; 4 | 5 | module Scoreboard 6 | { 7 | export class Objective 8 | { 9 | type: ObjectiveType; 10 | criteria: string; 11 | name: string; 12 | displayName: string; 13 | 14 | constructor(criteria: ObjectiveType = ObjectiveType.dummy, name: string = Util.Naming.next("score"), displayName: string = name, addObjective: boolean = true) 15 | { 16 | this.name = name; 17 | this.displayName = displayName; 18 | 19 | this.criteria = criteria.value; 20 | 21 | if(addObjective) 22 | command("scoreboard objectives add " + this.name + " " + this.criteria + " " + this.displayName); 23 | } 24 | 25 | set(selector: Selector, value: number): void 26 | { 27 | command("scoreboard players set " + selector + " " + this.name + " " + Math.floor(value)); 28 | } 29 | add(selector: Selector, value: number): void 30 | { 31 | command("scoreboard players add " + selector + " " + this.name + " " + Math.floor(value)); 32 | } 33 | remove(selector: Selector, value: number): void 34 | { 35 | command("scoreboard players remove " + selector + " " + this.name + " " + Math.floor(value)); 36 | } 37 | 38 | static reset(selector: Selector): void 39 | { 40 | command("scoreboard players reset " + selector); 41 | } 42 | reset(selector: Selector): void 43 | { 44 | command("scoreboard players reset " + selector + " " + this.name); 45 | } 46 | 47 | static clearDisplay(slot: DisplaySlot): void 48 | { 49 | command("scoreboard objectives setdisplay " + slot); 50 | } 51 | setDisplay(slot: DisplaySlot): void 52 | { 53 | command("scoreboard objectives setdisplay " + DisplaySlot[slot] + " " + this.name); 54 | } 55 | 56 | test(selector: Selector, valueMin: number = -2147483648, valueMax: number = 2147483647): MinecraftCommand 57 | { 58 | return new MinecraftCommand("scoreboard players test " + selector + " " + this.name + " " + Math.floor(valueMin) + " " + Math.floor(valueMax)); 59 | } 60 | operation(selector: Selector, otherObjective: Objective = this, otherPlayer: Selector = selector, operation: string = "=") 61 | { 62 | command("scoreboard players operation " + selector + " " + this.name + " " + operation + " " + otherPlayer + " " + otherObjective.name); 63 | } 64 | enableTrigger(selector: Selector): void 65 | { 66 | command("scoreboard players enable " + selector + " " + this.name); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Cmd/Cmd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {99187E44-6CFD-4E68-9D13-8C3633DE275A} 7 | Exe 8 | CommandblocksJS.Cmd 9 | Cmd 10 | 11 | 12 | true 13 | full 14 | false 15 | bin\Debug 16 | DEBUG; 17 | prompt 18 | 4 19 | x86 20 | true 21 | 22 | 23 | full 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | x86 29 | true 30 | 31 | 32 | 33 | ..\..\Noesis.Javascript.dll 34 | 35 | 36 | 37 | bin\Debug\Substrate.dll 38 | 39 | 40 | ..\..\CommandLine.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##This repository isnt maintained anymore please take a look at [Mooncraft](https://github.com/M4GNV5/MoonCraft) instead 2 | 3 | #CommandBlocksJS 4 | CommandBlocksJS allows you to program commandblocks logic in typescript/javascript. The major benefit in using CommandBlocksJS instead of building the blocks yourself is that you can create complex logic a lot faster that than you could in minecraft. Furthermore you can 'build' stuff like countdown timers in 4 lines of code where you would need ~10 minutes to write all the commands ingame. 5 | 6 | ##Documentation 7 | **cooming soon** 8 | 9 | ###Legacy Documentation (<2.0) 10 | [Here](https://github.com/M4GV5/CommandBlocksJS/wiki) 11 | There also is a [Quick Start](https://github.com/M4GV5/CommandBlocksJS/wiki/Quick-Start) page for those who cant wait to write their first script (with version 1.3) 12 | 13 | ##Examples 14 | 15 | ```javascript 16 | // 17 | //https://github.com/M4GNV5/CommandBlocksJS/blob/master/Example/CircleCalculations.ts 18 | // 19 | 20 | /// 21 | 22 | //start at radius 23 | var startRadius = 1; 24 | //stop at radius 25 | var stopRadius = 20; 26 | 27 | var radius = new Runtime.Integer(startRadius); 28 | 29 | call(calculateNext); 30 | 31 | function calculateNext() 32 | { 33 | var circumference = new Runtime.Decimal(); 34 | var area = new Runtime.Decimal(); 35 | 36 | var pi = Runtime.Decimal.Pi; 37 | 38 | // C = 2 * pi * r 39 | circumference.set(radius); 40 | circumference.multiplicate(pi); 41 | circumference.multiplicate(2); 42 | 43 | // A = r * r * pi 44 | area.set(radius); 45 | area.multiplicate(area); 46 | area.multiplicate(pi); 47 | 48 | // output current values 49 | Chat.Tellraw.create( 50 | "r = ", 51 | radius.toTellrawExtra(), 52 | ", C = ", 53 | circumference.toExactTellrawExtra(), 54 | ", A = ", 55 | area.toExactTellrawExtra() 56 | ).tell(new Entities.Player("@a")); 57 | 58 | //add one to radius 59 | radius.add(1); 60 | 61 | radius.isBetween(startRadius, stopRadius, calculateNext); 62 | } 63 | ``` 64 | ###Output 65 | [![Cmd](http://i.imgur.com/lloEG6U.png)]() 66 | 67 | 68 | ##Used Libraries 69 | - [CommandlineParser](https://commandline.codeplex.com/) for parsing the commandline arguments 70 | - [Substrate](https://github.com/jaquadro/Substrate) for editing the minecraft worlds 71 | - [Javascript.NET](http://javascriptdotnet.codeplex.com/) for executing the Javascript code 72 | 73 | 74 | 75 | ##License 76 | CommandBlocksJS is published under the 4 clause BSD license what means you can use source and binary for everything but your project needs to include the following clause: "This product includes software developed by Jakob Löw (M4GNV5)." 77 | -------------------------------------------------------------------------------- /Cmd/Program.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using CommandLine.Text; 3 | using System; 4 | using System.IO; 5 | 6 | namespace CommandBlocksJS.Cmd 7 | { 8 | public class MainClass 9 | { 10 | private sealed class Options 11 | { 12 | [Option('s', "script", MetaValue = "FILE", Required = true, HelpText = "Script file that will be processed to commandblocks.")] 13 | public string ScriptFile { get; set; } 14 | 15 | [Option('w', "world", Required = true, HelpText = "The Directory of the world the commandblocks will be built in.")] 16 | public string WorldDirectory { get; set; } 17 | 18 | [Option('e', "schematic", Required = false, HelpText = "Export schematic true/false.")] 19 | public bool IsSchematic { get; set; } 20 | 21 | [Option('x', "posx", Required = false, HelpText = "The X-start-position where to build the commandblocks.")] 22 | public int PositionX { get; set; } 23 | 24 | [Option('y', "posy", Required = false, HelpText = "The Y-start-position where to build the commandblocks.")] 25 | public int PositionY { get; set; } 26 | 27 | [Option('z', "posz", Required = false, HelpText = "The Z-start-position where to build the commandblocks.")] 28 | public int PositionZ { get; set; } 29 | 30 | [Option('l', "lib", DefaultValue = "core.js", HelpText = "Javascript file (.js) that contains CommandblocksJS core Javascript code")] 31 | public string LibPath { get; set; } 32 | 33 | [Option("output", DefaultValue = true, HelpText = "Write Script to World true/false.")] 34 | public bool Output { get; set; } 35 | } 36 | 37 | public static int Main(string[] args) 38 | { 39 | #if DEBUG 40 | args = "-s example.js -w ./world -x 0 -y 4 -z 0".Split(' '); 41 | #endif 42 | 43 | #if !DEBUG 44 | try 45 | { 46 | #endif 47 | Options options = new Options(); 48 | Parser cmdParser = new Parser(); 49 | 50 | if (!cmdParser.ParseArguments(args, options)) 51 | throw new ArgumentException("Invalid Commandline parameter!"); 52 | 53 | IntVector3 position = default(IntVector3); 54 | if (options.Output) 55 | { 56 | if (options.PositionY != 0) 57 | { 58 | position = new IntVector3(); 59 | position.x = options.PositionX; 60 | position.y = options.PositionY; 61 | position.z = options.PositionZ; 62 | } 63 | } 64 | 65 | JsScriptExecutor executor = new JsScriptExecutor(); 66 | executor.Run(options.LibPath, options.ScriptFile, options.WorldDirectory, position, options.IsSchematic); 67 | #if !DEBUG 68 | } 69 | catch (Exception e) 70 | { 71 | Console.WriteLine("An Error of type {0} occured!", e.GetType()); 72 | Console.WriteLine("Error Message: {0}", e.Message); 73 | return 1; 74 | } 75 | #endif 76 | return 0; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Core/API.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | 11 | /// 12 | /// 13 | /// 14 | 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | 27 | /// 28 | 29 | /// 30 | 31 | /// 32 | /// 33 | /// 34 | /// 35 | /// 36 | 37 | /// 38 | 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | 49 | /// 50 | /// 51 | /// 52 | 53 | /// 54 | /// 55 | /// 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | 70 | /// 71 | /// 72 | -------------------------------------------------------------------------------- /Core/Entities/Selector.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Entities 4 | { 5 | export class Selector 6 | { 7 | static get AllPlayer() 8 | { 9 | return new Entities.Selector(SelectorTarget.AllPlayer); 10 | } 11 | static get NearestPlayer() 12 | { 13 | return new Entities.Selector(SelectorTarget.NearestPlayer); 14 | } 15 | static get RandomEntity() 16 | { 17 | return new Entities.Selector(SelectorTarget.RandomPlayer); 18 | } 19 | static get Entity() 20 | { 21 | return new Entities.Selector(SelectorTarget.Entities); 22 | } 23 | 24 | 25 | 26 | char: SelectorTarget; 27 | private arguments: { [identifier: string]: SelectorArgument } = {}; 28 | 29 | constructor(char: SelectorTarget = SelectorTarget.AllPlayer) 30 | { 31 | this.char = char; 32 | } 33 | 34 | setArgument(argument: SelectorArgument): void 35 | { 36 | this.arguments[argument.identifier] = argument; 37 | } 38 | 39 | getArgument(argument: SelectorArgument): SelectorArgument 40 | { 41 | return this.arguments[argument.identifier]; 42 | } 43 | 44 | getArguments(): { [identifier: string]: SelectorArgument } 45 | { 46 | return this.arguments; 47 | } 48 | 49 | merge(other: Selector, ignoreConflicts: boolean = true): void 50 | { 51 | var otherArgs = other.getArguments(); 52 | for (var arg in otherArgs) 53 | { 54 | if (this.getArgument(otherArgs[arg]) != null) 55 | { 56 | if (ignoreConflicts) 57 | continue; 58 | else 59 | throw "Cannot combine selectors! Both define argument '" + otherArgs[arg].identifier+"'"; 60 | } 61 | this.setArgument(otherArgs[arg].clone()); 62 | } 63 | } 64 | 65 | clone(): Selector 66 | { 67 | var other = new Selector(this.char); 68 | other.merge(this); 69 | return other; 70 | } 71 | 72 | static parse(selector: string): Selector 73 | { 74 | selector = selector.trim(); 75 | Util.assert(selector[0] == "@", "Selector '" + selector + "' does not start with @"); 76 | 77 | var selectorChar = new SelectorTarget(selector[1]); 78 | var sel = new Selector(selectorChar); 79 | 80 | if (selector.length > 2) 81 | { 82 | var argumentString = selector.substring(3, selector.length - 1); 83 | var argumentArray = argumentString.split(','); 84 | 85 | for (var i = 0; i < argumentArray.length; i++) 86 | { 87 | var argumentSplit = argumentArray[i].split('='); 88 | var arg = SelectorArgument.parse(argumentSplit[0]); 89 | arg.setRaw(argumentSplit[1]); 90 | sel.setArgument(arg); 91 | } 92 | } 93 | 94 | return sel; 95 | } 96 | 97 | toString(): string 98 | { 99 | var sel = "@"; 100 | sel += this.char.identifier; 101 | if (Object.keys(this.arguments).length > 0) 102 | { 103 | sel += "["; 104 | for (var name in this.arguments) 105 | { 106 | sel += name + "=" + this.arguments[name].stringValue + ","; 107 | } 108 | sel = sel.substr(0, sel.length - 1); 109 | sel += "]"; 110 | } 111 | 112 | return sel; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /GUI/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.18444 5 | // 6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 | // der Code erneut generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CommandBlocksJS.GUI.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. 17 | /// 18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert 19 | // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. 20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 21 | // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CommandBlocksJS.GUI.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle 51 | /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /NodeCmd/NodeCmd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | {F25C5129-2793-47A6-9783-127B5573C1DD} 7 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 8 | Library 9 | bin 10 | v4.5 11 | full 12 | true 13 | 1.0 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 12.0 25 | 26 | 27 | NodeCmd 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | True 36 | True 37 | 49560 38 | / 39 | http://localhost:49560/ 40 | False 41 | False 42 | 43 | 44 | False 45 | 46 | 47 | 48 | 49 | 50 | false 51 | true 52 | 53 | 54 | true 55 | false 56 | 57 | 58 | -------------------------------------------------------------------------------- /Core/Util/Math.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var jsMath = Math; 4 | 5 | module Util 6 | { 7 | export class Math 8 | { 9 | private static knownCallbacks = []; 10 | 11 | static pow(base: Runtime.Number, exponent: Runtime.Number, result: Runtime.Number, callback?: Function): void 12 | { 13 | result.set(1); 14 | var _exponent = exponent.clone(Util.Naming.next("mathPow")); 15 | var repeat = function () 16 | { 17 | result.multiplicate(base); 18 | 19 | _exponent.remove(1); 20 | 21 | _exponent.isBetween(undefined, 0).validate(callback, repeat); 22 | }; 23 | _exponent.isBetween(undefined, 0).validate(callback, repeat); 24 | } 25 | 26 | static sqrt(value: Runtime.Number, result: Runtime.Number, callback?: Function): void 27 | { 28 | var step = new Runtime.Integer(32768, Util.Naming.next("mathSqrt0-")); 29 | result.set(step); 30 | 31 | var repeat = function () 32 | { 33 | var square = new Runtime.Integer(1, Util.Naming.next("mathSqrt1-")); 34 | 35 | square.multiplicate(result); 36 | square.multiplicate(result); 37 | 38 | square.remove(value); 39 | 40 | step.divide(2); 41 | 42 | var _repeat = function () 43 | { 44 | step.isExact(0).validate(callback, repeat); 45 | } 46 | 47 | square.isBetween(undefined, -1, function () 48 | { 49 | result.add(step); 50 | call(_repeat); 51 | }); 52 | square.isBetween(1, undefined, function () 53 | { 54 | result.remove(step); 55 | call(_repeat); 56 | }); 57 | } 58 | call(repeat, true); 59 | } 60 | 61 | static sin(value: Runtime.Number, result: Runtime.Number, callback?: Function): void 62 | { 63 | // http://upload.wikimedia.org/math/a/3/b/a3b692cd234b734e121ef24621f3635b.png 64 | 65 | call(function () 66 | { 67 | result.set(value); 68 | var numerator = new Runtime.Decimal(0, Util.Naming.next("mathSin0-")); 69 | var fraction = new Runtime.Decimal(0, Util.Naming.next("mathSin1-")); 70 | 71 | numerator.set(value); 72 | 73 | numerator.multiplicate(value); 74 | numerator.multiplicate(value); 75 | fraction.set(numerator); 76 | fraction.divide(6); //3! 77 | result.remove(fraction); 78 | 79 | numerator.multiplicate(value); 80 | numerator.multiplicate(value) 81 | fraction.set(numerator); 82 | fraction.divide(120); //5! 83 | result.add(fraction); 84 | 85 | numerator.multiplicate(value); 86 | numerator.multiplicate(value); 87 | fraction.set(numerator); 88 | fraction.divide(5040); //7! 89 | result.remove(fraction); 90 | 91 | numerator.multiplicate(value); 92 | numerator.multiplicate(value); 93 | fraction.set(numerator); 94 | fraction.divide(362880); //9! 95 | result.add(fraction); 96 | 97 | call(callback); 98 | }); 99 | } 100 | 101 | static factorial(value: Runtime.Number, result: Runtime.Number, callback?: Function): void 102 | { 103 | var current = value.clone(Util.Naming.next("mathFactorial")); 104 | result.set(1); 105 | var repeat = function () 106 | { 107 | result.multiplicate(current); 108 | current.remove(1); 109 | 110 | current.isBetween(undefined, 0).validate(callback, repeat); 111 | }; 112 | current.isBetween(undefined, 0).validate(callback, repeat); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /NodeCmd/main.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var args = process.argv.slice(2); 4 | var options = 5 | { 6 | x: 0, 7 | y: 4, 8 | z: 0, 9 | script: "./example.js", 10 | ip: "127.0.0.1", 11 | port: 25575, 12 | password: "password", 13 | clearArea: true 14 | }; 15 | 16 | for (var i = 0; i < args.length; i++) 17 | { 18 | for (var key in options) 19 | { 20 | var _key = key.length > 1 ? "--" : "-"; 21 | _key += key; 22 | if (_key == args[i]) 23 | { 24 | i++; 25 | if (typeof options[key] == 'number') 26 | options[key] = parseInt(args[i]); 27 | else 28 | options[key] = args[i].toString(); 29 | } 30 | } 31 | } 32 | 33 | var rcon = require("rcon"); 34 | var commands = []; 35 | var connection = new rcon(options.ip, options.port, options.password, { tcp: true, challenge: false }); 36 | 37 | var minPos = { x: options.x, y: options.y, z: options.z }; 38 | var maxPos = { x: options.x, y: options.y, z: options.z }; 39 | 40 | function NodeApi() 41 | { 42 | function checkClearArea(x, y, z) 43 | { 44 | minPos.x = x < minPos.x ? x : minPos.x; 45 | minPos.y = y < minPos.y ? y : minPos.y; 46 | minPos.z = z < minPos.z ? z : minPos.z; 47 | 48 | maxPos.x = x > maxPos.x ? x : maxPos.x; 49 | maxPos.y = y > maxPos.y ? y : maxPos.y; 50 | maxPos.z = z > maxPos.z ? z : maxPos.z; 51 | } 52 | 53 | this.log = function(message) 54 | { 55 | console.log(message); 56 | } 57 | 58 | this.disco = function(wait, count) 59 | { 60 | for (var i = 0; i < count; i++) 61 | { 62 | process.stdout.write('\x07'); 63 | console.log("Wait for " + wait + "ms? Pfff were in node here"); 64 | } 65 | } 66 | 67 | this.placeBlock = function(id, data, x, y, z) 68 | { 69 | console.log("placeBlock not implemented"); 70 | } 71 | 72 | this.placeCommandBlock = function(command, x, y, z) 73 | { 74 | checkClearArea(x, y, z); 75 | 76 | command = command.replace(/\\/g, "\\"); 77 | command = command.replace(/\"/g, "\\\""); 78 | commands.push("setblock " + x + " " + y + " " + z + " minecraft:command_block 0 replace {Command:\"" + command + "\"}"); 79 | } 80 | 81 | this.placeSign = function(text, direction, x, y, z) 82 | { 83 | checkClearArea(x, y, z); 84 | 85 | var data = { Text1: text[0], Text2: text[1], Text3: text[2], Text4: text[3], }; 86 | commands.push("setblock " + x + " " + y + " " + z + " minecraft:standing_sign " + direction + " replace " + JSON.stringify(data)); 87 | } 88 | 89 | this.save = function() 90 | { 91 | connection.on("auth", function () 92 | { 93 | if (options.clearArea) 94 | { 95 | connection.send("fill " + minPos.x + " " + minPos.y + " " + minPos.z + " " + maxPos.x + " " + maxPos.y + " " + maxPos.z + " air 0 replace"); 96 | } 97 | 98 | for (var i = 0; i < commands.length; i++) 99 | { 100 | (function (i) 101 | { 102 | setTimeout(function () { connection.send(commands[i]); }, i * 100); 103 | })(i); 104 | } 105 | }); 106 | connection.connect(); 107 | } 108 | } 109 | 110 | var vm = require("vm"); 111 | var fs = require("fs"); 112 | 113 | var context = { "api": new NodeApi() }; 114 | context = vm.createContext(context); 115 | 116 | connection.on("error", function (err) { throw err; }); 117 | 118 | fs.readFile("./core.js", function (err, data) 119 | { 120 | if (err) 121 | throw err; 122 | 123 | vm.runInContext(data, context); 124 | vm.runInContext("var startPosition = new Util.Vector3(" + options.x + ", " + options.y + ", " + options.z + ");", context); 125 | 126 | fs.readFile(options.script, function (err, scriptData) 127 | { 128 | if (err) 129 | throw err; 130 | 131 | vm.runInContext(scriptData, context); 132 | 133 | vm.runInContext("cbjsWorker();", context); 134 | }); 135 | }); -------------------------------------------------------------------------------- /GUI/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Documents; 13 | using System.Windows.Input; 14 | using System.Windows.Media; 15 | using System.Windows.Media.Imaging; 16 | using System.Windows.Navigation; 17 | using System.Windows.Shapes; 18 | using CommandBlocksJS.Cmd; 19 | 20 | namespace CommandBlocksJS.GUI 21 | { 22 | public class TextBoxStreamWriter : TextWriter 23 | { 24 | private TextBox output = null; 25 | private TextWriter defaultWriter = null; 26 | private StreamWriter file = null; 27 | 28 | public TextBoxStreamWriter(TextBox output, TextWriter defaultWriter) 29 | { 30 | this.output = output; 31 | this.defaultWriter = defaultWriter; 32 | this.file = File.CreateText("Log/log-" + DateTime.Now.ToString("s").Replace(':', '-') + ".txt"); 33 | } 34 | 35 | public override void Write(char value) 36 | { 37 | base.Write(value); 38 | this.defaultWriter.Write(value); 39 | this.output.AppendText(value.ToString()); 40 | this.file.Write(value); 41 | } 42 | 43 | public void Save() 44 | { 45 | this.file.Flush(); 46 | } 47 | 48 | public override void Close() 49 | { 50 | this.file.Close(); 51 | base.Close(); 52 | } 53 | 54 | public override Encoding Encoding 55 | { 56 | get { return System.Text.Encoding.UTF8; } 57 | } 58 | } 59 | 60 | public partial class MainWindow : Window 61 | { 62 | private TextWriter cout = Console.Out; 63 | 64 | public MainWindow() 65 | { 66 | InitializeComponent(); 67 | } 68 | 69 | private void onBrowseFileClick(object sender, RoutedEventArgs e) 70 | { 71 | OpenFileDialog ofd = new OpenFileDialog(); 72 | ofd.Filter = "CommandBlocksJS files|*.js|All files|*"; 73 | if (ofd.ShowDialog() == true) 74 | { 75 | if (!File.Exists(ofd.FileName)) 76 | { 77 | MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); 78 | } 79 | else 80 | { 81 | tbFileName.Text = ofd.FileName; 82 | tbConsole.Text = File.ReadAllText(ofd.FileName); 83 | } 84 | } 85 | } 86 | 87 | private void onGenerateButtonClick(object sender, RoutedEventArgs ev) 88 | { 89 | tbConsole.Clear(); 90 | if (!Directory.Exists("Log/")) 91 | Directory.CreateDirectory("Log/"); 92 | 93 | var tb = new TextBoxStreamWriter(tbConsole, cout); 94 | 95 | Console.SetOut(tb); 96 | 97 | Console.WriteLine("Running CommandBlockJS"); 98 | 99 | Thread.Sleep(1000); 100 | 101 | string world = cbWorldFolder.Text; 102 | 103 | IntVector3 pos = new IntVector3(); 104 | 105 | int.TryParse(tbPosX.Text, out pos.x); 106 | int.TryParse(tbPosY.Text, out pos.y); 107 | int.TryParse(tbPosZ.Text, out pos.z); 108 | 109 | var js = new CommandBlocksJS.Cmd.JsScriptExecutor(); 110 | try 111 | { 112 | js.Run("core.js", tbFileName.Text, world, pos, IsSchematic.IsChecked == true); 113 | 114 | Console.WriteLine("Generation finished successfully"); 115 | tb.Save(); 116 | if (cbClose.IsChecked == true) 117 | Close(); 118 | } 119 | catch (Exception e) 120 | { 121 | Console.WriteLine(e); 122 | Console.WriteLine("Generation failed"); 123 | tb.Save(); 124 | } 125 | } 126 | 127 | private void cbWorldFolder_KeyUp(object sender, KeyEventArgs e) 128 | { 129 | if (cbWorldFolder.Text.EndsWith(".schematic")) 130 | IsSchematic.IsChecked = true; 131 | else if (cbWorldFolder.Text.EndsWith("/")) 132 | IsWorld.IsChecked = true; 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /Cmd/JsSchematicApi.cs: -------------------------------------------------------------------------------- 1 | using CommandBlocksJS.Cmd; 2 | using Substrate; 3 | using Substrate.ImportExport; 4 | using Substrate.Nbt; 5 | using Substrate.TileEntities; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IO; 9 | 10 | namespace CommandblocksJS.Cmd 11 | { 12 | public class JsSchematicApi 13 | { 14 | private Dictionary blocks; 15 | private string path; 16 | 17 | public JsSchematicApi(string path) 18 | { 19 | this.blocks = new Dictionary(); 20 | this.path = path; 21 | } 22 | 23 | public void log(string message) 24 | { 25 | Console.WriteLine(message); 26 | } 27 | 28 | public void disco(int wait = 1, int count = 1) 29 | {//this is defnitly not an easter egg 30 | for (int i = 0; i < count; i++) 31 | { 32 | Console.Beep(); 33 | System.Threading.Thread.Sleep(wait); 34 | } 35 | } 36 | 37 | public void placeBlock(int id, int data, int x, int y, int z) 38 | { 39 | if (blocks.ContainsKey(new IntVector3(x, y - 1, z))) 40 | { 41 | blocks.Remove(new IntVector3(x, y - 1, z)); 42 | } 43 | blocks.Add(new IntVector3(x, y - 1, z), new AlphaBlock(BlockType.STONE, 0)); 44 | 45 | if (blocks.ContainsKey(new IntVector3(x, y, z))) 46 | { 47 | blocks.Remove(new IntVector3(x, y, z)); 48 | } 49 | blocks.Add(new IntVector3(x, y, z), new AlphaBlock(id, data)); 50 | } 51 | 52 | public void placeCommandBlock(string command, int x, int y, int z) 53 | { 54 | AlphaBlock cblock = new AlphaBlock(BlockType.COMMAND_BLOCK); 55 | TileEntityControl te = cblock.GetTileEntity() as TileEntityControl; //unsafe 56 | te.Command = command; 57 | if (blocks.ContainsKey(new IntVector3(x, y, z))) 58 | { 59 | blocks.Remove(new IntVector3(x, y, z)); 60 | } 61 | blocks.Add(new IntVector3(x, y, z), cblock); 62 | } 63 | 64 | public void placeSign(string[] text, int direction, int x, int y, int z) 65 | { 66 | AlphaBlock sign = new AlphaBlock(BlockType.SIGN_POST); 67 | TileEntitySign te = sign.GetTileEntity() as TileEntitySign; 68 | sign.Data = direction; 69 | 70 | if (text.Length > 0) 71 | te.Text1 = text[0]; 72 | if (text.Length > 1) 73 | te.Text2 = text[1]; 74 | if (text.Length > 2) 75 | te.Text3 = text[2]; 76 | if (text.Length > 3) 77 | te.Text4 = text[3]; 78 | 79 | if (blocks.ContainsKey(new IntVector3(x, y, z))) 80 | { 81 | blocks.Remove(new IntVector3(x, y, z)); 82 | } 83 | blocks.Add(new IntVector3(x, y, z), sign); 84 | } 85 | 86 | public void save() 87 | { 88 | int maxX, maxY, maxZ; 89 | maxX = maxY = maxZ = 0; 90 | 91 | foreach (var block in blocks) 92 | { 93 | maxX = Math.Max(maxX, block.Key.x); 94 | maxY = Math.Max(maxY, block.Key.y); 95 | maxZ = Math.Max(maxZ, block.Key.z); 96 | } 97 | AlphaBlockCollection schematicBlocks = new AlphaBlockCollection(maxX + 1, maxY + 1, maxZ + 1); 98 | EntityCollection schematicEntities = new EntityCollection(new TagNodeList(TagType.TAG_COMPOUND)); 99 | foreach (var block in blocks) 100 | { 101 | if (block.Key.x > maxX) 102 | throw new IndexOutOfRangeException(); 103 | if (block.Key.y > maxY) 104 | throw new IndexOutOfRangeException(); 105 | if (block.Key.z > maxZ) 106 | throw new IndexOutOfRangeException(); 107 | 108 | if (block.Key.x < 0) 109 | throw new IndexOutOfRangeException(); 110 | if (block.Key.y < 0) 111 | throw new IndexOutOfRangeException(); 112 | if (block.Key.z < 0) 113 | throw new IndexOutOfRangeException(); 114 | 115 | schematicBlocks.SetBlock(block.Key.x, block.Key.y, block.Key.z, block.Value); 116 | } 117 | 118 | Schematic schematic = new Schematic(schematicBlocks, schematicEntities); 119 | schematic.Export(path); 120 | } 121 | } 122 | } -------------------------------------------------------------------------------- /Core/Scoreboard/Score.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Scoreboard 4 | { 5 | export class Score implements Runtime.Number 6 | { 7 | private objective: Scoreboard.Objective; 8 | private selector: Entities.Selector; 9 | private name: string; 10 | 11 | get Selector(): Entities.Selector 12 | { 13 | return this.selector; 14 | } 15 | 16 | constructor(objective: Scoreboard.Objective, selector: Entities.Selector, startValue: number = 0, intialize: boolean = true) 17 | { 18 | this.selector = selector; 19 | this.objective = objective; 20 | this.name = Util.Naming.next("score"); 21 | 22 | if (intialize) 23 | this.set(startValue); 24 | } 25 | 26 | set(value: number, mode?: Runtime.NumberSetMode): void; 27 | set(value: Runtime.Number, mode?: Runtime.NumberSetMode): void; 28 | set(value: any, mode: Runtime.NumberSetMode = Runtime.NumberSetMode.assign): void 29 | { 30 | if (typeof value == 'number' && mode == Runtime.NumberSetMode.assign) 31 | this.objective.set(this.selector, value); 32 | else if (mode == Runtime.NumberSetMode.assign) 33 | this.operation("=", value); 34 | else if (mode == Runtime.NumberSetMode.divisionRemainder) 35 | this.operation("%=", value); 36 | else if (mode == Runtime.NumberSetMode.smallerOne) 37 | this.operation("<", value); 38 | else if (mode == Runtime.NumberSetMode.biggerOne) 39 | this.operation(">", value); 40 | } 41 | 42 | add(value: number): void; 43 | add(value: Runtime.Number): void; 44 | add(value: any): void 45 | { 46 | if (typeof value == 'number') 47 | this.objective.add(this.selector, value); 48 | else 49 | this.operation("+=", value); 50 | } 51 | 52 | remove(value: number): void; 53 | remove(value: Runtime.Number): void; 54 | remove(value: any): void 55 | { 56 | if (typeof value == 'number') 57 | this.objective.remove(this.selector, value); 58 | else 59 | this.operation("-=", value); 60 | } 61 | 62 | multiplicate(value: number): void; 63 | multiplicate(value: Runtime.Number): void; 64 | multiplicate(value: any): void 65 | { 66 | this.operation("*=", value); 67 | } 68 | 69 | divide(value: number): void; 70 | divide(value: Runtime.Number): void; 71 | divide(value: any): void 72 | { 73 | this.operation("/=", value); 74 | } 75 | 76 | swap(other: Runtime.Number): void 77 | { 78 | this.operation("><", other); 79 | } 80 | 81 | reset(): void 82 | { 83 | this.objective.reset(this.selector); 84 | } 85 | 86 | clone(cloneName?: string): Runtime.Integer 87 | { 88 | var clone = new Runtime.Integer(0, cloneName, false); 89 | Runtime.Integer.score.operation(clone.Selector, this.objective, this.selector, "="); 90 | return clone; 91 | } 92 | 93 | operation(operation: string, other: number) 94 | operation(operation: string, other: Runtime.Number) 95 | operation(operation: string, other: any) 96 | { 97 | var _other: Runtime.Integer; 98 | if (typeof other == 'number') 99 | _other = new Runtime.Integer(other, "const" + other); 100 | else 101 | _other = (other).toInteger(); 102 | 103 | this.objective.operation(this.selector, Runtime.Integer.score, _other.Selector, operation); 104 | } 105 | 106 | isExact(value: number, callback?: Function): MinecraftCommand 107 | { 108 | return this.isBetween(value, value, callback); 109 | } 110 | 111 | isBetween(min: number = -2147483648, max: number = 2147483647, callback?: Function): MinecraftCommand 112 | { 113 | var cmd = this.objective.test(this.selector, min, max); 114 | 115 | if (typeof callback == 'function') 116 | cmd.validate(callback); 117 | 118 | return cmd; 119 | } 120 | 121 | toInteger(): Runtime.Integer 122 | { 123 | return this.clone(this.name); 124 | } 125 | 126 | toTellrawExtra(): Chat.TellrawScoreExtra 127 | { 128 | var clone = this.clone(this.name); 129 | return clone.toTellrawExtra(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Core/Runtime/Integer.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class Integer implements Number 6 | { 7 | public static get MaxValue() 8 | { 9 | return new Integer(-2147483647); 10 | } 11 | public static get MinValue() 12 | { 13 | return new Integer(2147483647); 14 | } 15 | 16 | static score: Scoreboard.Objective = new Scoreboard.Objective(Scoreboard.ObjectiveType.dummy, "stdInteger", "RuntimeInteger", false); 17 | 18 | private selector: Entities.Selector; 19 | 20 | get Selector(): Entities.Selector 21 | { 22 | return this.selector; 23 | } 24 | 25 | constructor(value?: number, name?: string, intialize?: boolean) 26 | constructor(value?: number, selector?: Entities.Selector, intialize?: boolean) 27 | constructor(value: number = 0, selector: any = Util.Naming.next("int"), intialize: boolean = true) 28 | { 29 | usedLibs["integer"] = true; 30 | 31 | if (selector instanceof Entities.Selector) 32 | this.selector = selector; 33 | else 34 | this.selector = new Entities.Player(selector.toString()); 35 | 36 | if(intialize) 37 | this.set(value); 38 | } 39 | 40 | set(value: number, mode?: NumberSetMode): void; 41 | set(value: Number, mode?: NumberSetMode): void; 42 | set(value: any, mode: NumberSetMode = NumberSetMode.assign): void 43 | { 44 | if (typeof value == 'number' && mode == NumberSetMode.assign) 45 | Integer.score.set(this.selector, value); 46 | else if (mode == NumberSetMode.assign) 47 | this.operation("=", value); 48 | else if (mode == NumberSetMode.divisionRemainder) 49 | this.operation("%=", value); 50 | else if (mode == NumberSetMode.smallerOne) 51 | this.operation("<", value); 52 | else if (mode == NumberSetMode.biggerOne) 53 | this.operation(">", value); 54 | } 55 | 56 | add(value: number): void; 57 | add(value: Number): void; 58 | add(value: any): void 59 | { 60 | if (typeof value == 'number') 61 | Integer.score.add(this.selector, value); 62 | else 63 | this.operation("+=", value); 64 | } 65 | 66 | remove(value: number): void; 67 | remove(value: Number): void; 68 | remove(value: any): void 69 | { 70 | if (typeof value == 'number') 71 | Integer.score.remove(this.selector, value); 72 | else 73 | this.operation("-=", value); 74 | } 75 | 76 | multiplicate(value: number): void; 77 | multiplicate(value: Number): void; 78 | multiplicate(value: any): void 79 | { 80 | this.operation("*=", value); 81 | } 82 | 83 | divide(value: number): void; 84 | divide(value: Number): void; 85 | divide(value: any): void 86 | { 87 | this.operation("/=", value); 88 | } 89 | 90 | swap(other: Number): void 91 | { 92 | this.operation("><", other); 93 | } 94 | 95 | reset(): void 96 | { 97 | Integer.score.reset(this.selector); 98 | } 99 | 100 | clone(cloneName?: string): Integer 101 | { 102 | var clone = new Integer(0, cloneName, false); 103 | clone.set(this); 104 | return clone; 105 | } 106 | 107 | operation(operation: string, other: number) 108 | operation(operation: string, other: Number) 109 | operation(operation: string, other: any) 110 | { 111 | var _other: Integer; 112 | if (typeof other == 'number') 113 | _other = new Integer(other, "const"+other); 114 | else 115 | _other = (other).toInteger(); 116 | 117 | Integer.score.operation(this.selector, Integer.score, _other.Selector, operation); 118 | } 119 | 120 | isExact(value: number, callback?: Function): MinecraftCommand 121 | { 122 | return this.isBetween(value, value, callback); 123 | } 124 | 125 | isBetween(min: number = -2147483648, max: number = 2147483647, callback?: Function): MinecraftCommand 126 | { 127 | var cmd = Integer.score.test(this.selector, min, max); 128 | 129 | if (typeof callback == 'function') 130 | cmd.validate(callback); 131 | 132 | return cmd; 133 | } 134 | 135 | toInteger(): Integer 136 | { 137 | return this; 138 | } 139 | 140 | toTellrawExtra(): Chat.TellrawScoreExtra 141 | { 142 | return new Chat.TellrawScoreExtra(Integer.score, this.selector); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Core/Entities/EntityType.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Entities 4 | { 5 | export class EntityType 6 | { 7 | static DroppedItem = new EntityType("Item"); 8 | static ExperienceOrb = new EntityType("XPOrb"); 9 | 10 | static Leash = new EntityType("LeashKnot"); 11 | static Painting = new EntityType("Painting"); 12 | static ItemFrame = new EntityType("ItemFrame"); 13 | static ArmorStand = new EntityType("ArmorStand"); 14 | static EnderCrystal = new EntityType("EnderCrystal"); 15 | 16 | static Arrow = new EntityType("Arrow"); 17 | static Snowball = new EntityType("Snowball"); 18 | static FireballGhast = new EntityType("Fireball"); 19 | static FireballBlaze = new EntityType("SmallFireball"); 20 | static EnderPearl = new EntityType("ThrownEnderpearl"); 21 | static EnderEye = new EntityType("EyeOfEnderSignal"); 22 | static Potion = new EntityType("ThrownPotion"); 23 | static ExperienceBottle = new EntityType("ThrownExpBottle"); 24 | static WitherSkull = new EntityType("WitherSkull"); 25 | static Firework = new EntityType("FireworksRocketEntity"); 26 | 27 | static TNT = new EntityType("PrimedTnt"); 28 | static FallingBlock = new EntityType("FallingSand"); 29 | 30 | static Boat = new EntityType("FallingSand"); 31 | static Minecart = new EntityType("MinecartRideable"); 32 | static MinecartChest = new EntityType("MinecartChest"); 33 | static MinecartFurnace = new EntityType("MinecartFurnace"); 34 | static MinecartTNT = new EntityType("MinecartTNT"); 35 | static MinecartCommandBlock = new EntityType("MinecartCommandBlock"); 36 | static MinecartHopper = new EntityType("MinecartHopper"); 37 | static MinecartWithSpawner = new EntityType("MinecartSpawner"); 38 | 39 | static Mob = new EntityType("Mob"); 40 | static Player = new EntityType("Player"); 41 | 42 | static Creeper = new EntityType("Creeper"); 43 | static Skeleton = new EntityType("Skeleton"); 44 | static Spider = new EntityType("Spider"); 45 | static Giant = new EntityType("Giant"); 46 | static Zombie = new EntityType("Zombie"); 47 | static Slime = new EntityType("Slime"); 48 | static Ghast = new EntityType("Ghast"); 49 | static ZombiePigman = new EntityType("PigZombie"); 50 | static Enderman = new EntityType("Enderman"); 51 | static CaveSpider = new EntityType("CaveSpider"); 52 | static Silverfish = new EntityType("Silverfish"); 53 | static Blaze = new EntityType("Blaze"); 54 | static MagmaCube = new EntityType("LavaSlime"); 55 | static EnderDragon = new EntityType("EnderDragon"); 56 | static Wither = new EntityType("WitherBoss"); 57 | static Witch = new EntityType("Witch"); 58 | static Endermite = new EntityType("Endermite"); 59 | static Guardian = new EntityType("Guardian"); 60 | 61 | static Bat = new EntityType("Bat"); 62 | static Pig = new EntityType("Pig"); 63 | static Sheep = new EntityType("Sheep"); 64 | static Cow = new EntityType("Cow"); 65 | static Chicken = new EntityType("Chicken"); 66 | static Squid = new EntityType("Squid"); 67 | static Wolf = new EntityType("Wolf"); 68 | static MushroomCow = new EntityType("MushroomCow"); 69 | static SnowMan = new EntityType("SnowMan"); 70 | static Ocelot = new EntityType("Ocelot"); 71 | static IronGolem = new EntityType("VillagerGolem"); 72 | static Horse = new EntityType("EntityHorse"); 73 | static Rabbit = new EntityType("Rabbit"); 74 | 75 | static Villager = new EntityType("Villager"); 76 | 77 | static LightningBolt = new EntityType("LightningBolt"); 78 | 79 | name: string; 80 | constructor(name: string) 81 | { 82 | Util.assert(["Item", "XPOrb", "LeashKnot", "Painting", "ItemFrame", "ArmorStand", "EnderCrystal", "Arrow", "Snowball", "Fireball", "SmallFireball", "ThrownEnderpearl", "EyeOfEnderSignal", "ThrownPotion", "ThrownExpBottle", "ThrownExpBottle", "WitherSkull", "FireworksRocketEntity", "PrimedTnt", "FallingSand", "FallingSand", "MinecartRideable", "MinecartChest", "MinecartFurnace", "MinecartTNT", "MinecartCommandBlock", "MinecartHopper", "MinecartSpawner", "Mob", "Player", "Creeper", "Skeleton", "Spider", "Giant", "Zombie", "Slime", "Ghast", "PigZombie", "Enderman", "CaveSpider", "Silverfish", "Blaze", "LavaSlime", "EnderDragon", "WitherBoss", "Witch", "Endermite", "Guardian", "Bat", "Pig", "Sheep", "Cow", "Chicken", "Squid", "Wolf", "MushroomCow", "SnowMan", "SnowMan", "Ocelot", "Ozelot", "VillagerGolem", "EntityHorse", "Rabbit", "Villager", "LightningBolt"] 83 | .indexOf(name) != -1, "Unknown EntityType: " + name); 84 | this.name = name; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Example/Calculator.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | command("gamerule sendCommandFeedback false"); 4 | 5 | var current = new Runtime.Integer(); 6 | var operator = new Runtime.String("X"); 7 | var operatorLabel = new Runtime.String(); 8 | var first = new Runtime.Integer(); 9 | 10 | function createNumButton(i: number): Chat.Message 11 | { 12 | var button = new Chat.Message(i.toString(), Chat.Color.yellow); 13 | button.clickEvent = new Chat.CallbackClickEvent(function () 14 | { 15 | current.multiplicate(10); 16 | current.add(i); 17 | 18 | call(drawCalculator); 19 | }); 20 | return button; 21 | } 22 | 23 | var numButtons: Chat.Message[] = []; 24 | for (var i = 0; i < 10; i++) 25 | { 26 | numButtons[i] = createNumButton(i); 27 | } 28 | 29 | 30 | 31 | function createOperatorButton(op: string, label: string): Chat.Message 32 | { 33 | var button = new Chat.Message(label, Chat.Color.green); 34 | button.clickEvent = new Chat.CallbackClickEvent(function () 35 | { 36 | operator.set(op); 37 | operatorLabel.set(label); 38 | first.set(current); 39 | current.set(0); 40 | 41 | call(drawCalculator); 42 | }); 43 | return button; 44 | } 45 | 46 | var operatorButtons: { [index: string]: Chat.Message } = {}; 47 | operatorButtons["+"] = createOperatorButton("add", "+"); 48 | operatorButtons["-"] = createOperatorButton("remove", "-"); 49 | operatorButtons["*"] = createOperatorButton("multiplicate", "*"); 50 | operatorButtons["/"] = createOperatorButton("divide", "/"); 51 | operatorButtons["%"] = createOperatorButton("remainder", "%"); 52 | operatorButtons["^"] = createOperatorButton("pow", "^"); 53 | 54 | 55 | 56 | var specialButtons: { [index: string]: Chat.Message } = {}; 57 | 58 | specialButtons["C"] = new Chat.Message("C", Chat.Color.red); 59 | specialButtons["C"].clickEvent = new Chat.CallbackClickEvent(function () 60 | { 61 | current.set(0); 62 | operator.set("X"); 63 | first.set(0); 64 | 65 | call(drawCalculator); 66 | }); 67 | 68 | specialButtons["CE"] = new Chat.Message("CE", Chat.Color.red); 69 | specialButtons["CE"].clickEvent = new Chat.CallbackClickEvent(function () 70 | { 71 | current.set(0); 72 | 73 | call(drawCalculator); 74 | }); 75 | 76 | specialButtons["="] = new Chat.Message("=", Chat.Color.red); 77 | specialButtons["="].clickEvent = new Chat.CallbackClickEvent(function () 78 | { 79 | function applyOperator(op: string) 80 | { 81 | first[op](current); 82 | current.set(first); 83 | operator.set("X"); 84 | first.set(0); 85 | 86 | call(drawCalculator); 87 | } 88 | 89 | operator.isExact("add", function () { applyOperator("add"); }); 90 | operator.isExact("remove", function () { applyOperator("remove"); }); 91 | operator.isExact("multiplicate", function () { applyOperator("multiplicate"); }); 92 | operator.isExact("divide", function () { applyOperator("divide"); }); 93 | 94 | operator.isExact("remainder", function () 95 | { 96 | first.set(current, Runtime.NumberSetMode.divisionRemainder); 97 | current.set(first); 98 | operator.set("X"); 99 | first.set(0); 100 | 101 | call(drawCalculator); 102 | }); 103 | 104 | operator.isExact("pow", function () 105 | { 106 | Chat.Tellraw.create("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCalculating please wait...").tell(Entities.Selector.AllPlayer); 107 | 108 | var result = new Runtime.Integer(); 109 | Util.Math.pow(first, current, result, function() 110 | { 111 | current.set(result); 112 | first.set(0); 113 | operator.set("X"); 114 | 115 | call(drawCalculator); 116 | }); 117 | }); 118 | }); 119 | 120 | function drawCalculator() 121 | { 122 | var body = [ 123 | specialButtons["CE"], " ", specialButtons["C"], " ", operatorButtons["/"], "\n", 124 | numButtons[7], " ", numButtons[8], " ", numButtons[9], " ", operatorButtons["*"], "\n", 125 | numButtons[4], " ", numButtons[5], " ", numButtons[6], " ", operatorButtons["+"], "\n", 126 | numButtons[1], " ", numButtons[2], " ", numButtons[3], " ", operatorButtons["-"], "\n", 127 | numButtons[0], " ", operatorButtons["^"], " ", operatorButtons["%"], " ", specialButtons["="] 128 | ]; 129 | 130 | operator.isExact("X").validate(function () 131 | { 132 | Chat.Tellraw.create( 133 | "Calculator in vanilla Minecraft written in Typescript compiled with CommandblocksJS\n\n\n\n\n\n\n\n\n\n\n\n\n", 134 | current.toTellrawExtra(), "\n", 135 | body 136 | ).tell(Entities.Selector.AllPlayer); 137 | }, function () 138 | { 139 | Chat.Tellraw.create( 140 | "Calculator in vanilla Minecraft written in Typescript compiled with CommandblocksJS\n\n\n\n\n\n\n\n\n\n\n\n\n", 141 | first.toTellrawExtra(), " ", operatorLabel.toTellrawExtra(), " ", current.toTellrawExtra(), "\n", 142 | body 143 | ).tell(Entities.Selector.AllPlayer); 144 | }); 145 | } 146 | 147 | call(drawCalculator); 148 | -------------------------------------------------------------------------------- /Core/Runtime/Decimal.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class Decimal implements Number 6 | { 7 | public static get Pi() 8 | { 9 | return new Decimal(3.14, Util.Naming.next("pi")); 10 | } 11 | public static get Euler() 12 | { 13 | return new Decimal(2.72, Util.Naming.next("euler")); 14 | } 15 | 16 | static compileTimeAccuracy: number = 100; 17 | static accuracy: Integer = new Runtime.Integer(0, "decimalAccuracy", false); 18 | 19 | private value: Integer; 20 | 21 | private name: string; 22 | 23 | constructor(startValue?: Integer, name?: string) 24 | constructor(startValue?: number, name?: string, intialize?: boolean) 25 | constructor(startValue: any = 0, name: string = Util.Naming.next("decimal"), intialize: boolean = true) 26 | { 27 | usedLibs["decimal"] = true; 28 | 29 | if (typeof startValue == 'number') 30 | { 31 | this.value = new Integer(startValue * Decimal.compileTimeAccuracy, name, intialize); 32 | } 33 | else 34 | { 35 | this.value = startValue; 36 | this.value.multiplicate(Decimal.accuracy); 37 | } 38 | this.name = name; 39 | } 40 | 41 | set(value: number, mode?: NumberSetMode): void; 42 | set(value: Number, mode?: NumberSetMode): void; 43 | set(value: any, mode: NumberSetMode = NumberSetMode.assign): void 44 | { 45 | if (typeof value == 'number' && mode == NumberSetMode.assign) 46 | { 47 | this.value.set(value * Decimal.compileTimeAccuracy); 48 | } 49 | else if (value instanceof Decimal) 50 | { 51 | this.value.set((value).value, mode); 52 | } 53 | else if (typeof value == 'number') 54 | { 55 | this.value.set(value * Decimal.compileTimeAccuracy, mode); 56 | } 57 | else 58 | { 59 | var cp = (value).clone().toInteger(); 60 | cp.multiplicate(Decimal.accuracy); 61 | this.value.set(cp, mode); 62 | } 63 | } 64 | 65 | add(value: number): void; 66 | add(value: Number): void; 67 | add(value: any): void 68 | { 69 | if (typeof value == 'number') 70 | this.value.add(value * Decimal.compileTimeAccuracy); 71 | else if(value instanceof Decimal) 72 | this.value.operation("+=", (value).value); 73 | else 74 | this.value.operation("+=", value); 75 | } 76 | 77 | remove(value: number): void; 78 | remove(value: Number): void; 79 | remove(value: any): void 80 | { 81 | if (typeof value == 'number') 82 | this.value.remove(value * Decimal.compileTimeAccuracy); 83 | else if (value instanceof Decimal) 84 | this.value.operation("-=", (value).value); 85 | else 86 | this.value.operation("-=", value); 87 | } 88 | 89 | multiplicate(value: number): void; 90 | multiplicate(value: Number): void; 91 | multiplicate(value: any): void 92 | { 93 | if (value instanceof Decimal) 94 | { 95 | this.value.operation("*=", (value).value); 96 | this.value.operation("/=", Decimal.accuracy); 97 | } 98 | else 99 | { 100 | this.value.operation("*=", value); 101 | } 102 | } 103 | 104 | divide(value: number): void; 105 | divide(value: Number): void; 106 | divide(value: any): void 107 | { 108 | if (value instanceof Decimal) 109 | { 110 | this.value.operation("*=", (value).value); 111 | this.value.operation("/=", Decimal.accuracy); 112 | } 113 | else 114 | { 115 | this.value.operation("/=", value); 116 | } 117 | } 118 | 119 | swap(other: Number): void 120 | { 121 | this.value.swap(other); 122 | 123 | if (!(other instanceof Decimal)) 124 | { 125 | other.divide(Decimal.accuracy); 126 | this.value.multiplicate(Decimal.accuracy); 127 | } 128 | } 129 | 130 | clone(cloneName?: string): Decimal 131 | { 132 | var copy = new Decimal(0, cloneName); 133 | copy.value.set(this.value); 134 | return copy; 135 | } 136 | 137 | isExact(value: number, callback?: Function): MinecraftCommand 138 | { 139 | return this.isBetween(value, value, callback); 140 | } 141 | 142 | isBetween(min: number = -21474836.48, max: number = 21474836.47, callback?: Function): MinecraftCommand 143 | { 144 | min *= Decimal.compileTimeAccuracy; 145 | if (typeof max != 'undefined') 146 | max *= Decimal.compileTimeAccuracy; 147 | 148 | return this.value.isBetween(min, max, callback); 149 | } 150 | 151 | toInteger(): Integer 152 | { 153 | var out = new Integer(0, this.name + "O", false); 154 | out.set(this.value); 155 | out.divide(Decimal.accuracy); 156 | return out; 157 | } 158 | 159 | toTellrawExtra(): Chat.TellrawScoreExtra 160 | { 161 | return this.toInteger().toTellrawExtra(); 162 | } 163 | toExactTellrawExtra(): Chat.Message[] 164 | { 165 | var cp = this.value.clone(this.name + "O2"); 166 | cp.set(Decimal.accuracy, NumberSetMode.divisionRemainder); 167 | 168 | var messages = []; 169 | messages[0] = this.toTellrawExtra(); 170 | messages[1] = new Chat.Message("."); 171 | messages[2] = cp.toTellrawExtra(); 172 | 173 | return messages; 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /Core/Runtime/Fraction.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Runtime 4 | { 5 | export class Fraction implements Number 6 | { 7 | public static get Pi() 8 | { 9 | var numerator = new Integer(355); 10 | var denominator = new Integer(113); 11 | return new Fraction(numerator, denominator, Util.Naming.next("pi")); 12 | } 13 | public static get Euler() 14 | { 15 | var numerator = new Integer(27182); 16 | var denominator = new Integer(10000); 17 | return new Fraction(numerator, denominator, Util.Naming.next("euler")); 18 | } 19 | 20 | numerator: Number; 21 | denominator: Number; 22 | 23 | name: string; 24 | 25 | private get copyName() 26 | { 27 | return this.name + "C"; 28 | } 29 | 30 | constructor(numerator: Number = new Integer(0), denominator: Number = new Integer(1), name: string = Util.Naming.next("fraction")) 31 | { 32 | this.numerator = numerator; 33 | this.denominator = denominator; 34 | 35 | this.name = name; 36 | } 37 | 38 | set(value: number, mode?: NumberSetMode): void; 39 | set(value: Number, mode?: NumberSetMode): void; 40 | set(value: any, mode: NumberSetMode = NumberSetMode.assign): void 41 | { 42 | if (value instanceof Fraction && mode == NumberSetMode.assign) 43 | { 44 | var frac = value; 45 | this.numerator.set(frac.numerator); 46 | this.denominator.set(frac.denominator); 47 | } 48 | else 49 | { 50 | this.numerator.set(value, mode); 51 | this.denominator.set(1); 52 | } 53 | } 54 | 55 | add(value: number, reduceToLowest?: boolean): void; 56 | add(value: Number, reduceToLowest?: boolean): void; 57 | add(value: any, reduceToLowest: boolean = true): void 58 | { 59 | if (value instanceof Fraction) 60 | { 61 | var copy = (value).clone(this.copyName); 62 | copy.numerator.multiplicate(this.denominator); 63 | this.numerator.multiplicate(copy.denominator); 64 | this.numerator.add(copy.numerator); 65 | } 66 | else 67 | { 68 | var numCopy: Number = value.clone(this.copyName); 69 | numCopy.multiplicate(this.denominator); 70 | this.numerator.add(numCopy); 71 | } 72 | 73 | if (reduceToLowest) 74 | this.reduceToLowest(); 75 | } 76 | 77 | remove(value: number, reduceToLowest?: boolean): void; 78 | remove(value: Number, reduceToLowest?: boolean): void; 79 | remove(value: any, reduceToLowest: boolean = true): void 80 | { 81 | if (value instanceof Fraction) 82 | { 83 | var copy = (value).clone(this.copyName); 84 | copy.numerator.multiplicate(this.denominator); 85 | this.numerator.multiplicate(copy.denominator); 86 | this.numerator.remove(copy.numerator); 87 | } 88 | else 89 | { 90 | var numCopy: Number = value.clone(this.copyName); 91 | numCopy.multiplicate(this.denominator); 92 | this.numerator.remove(numCopy); 93 | } 94 | 95 | if (reduceToLowest) 96 | this.reduceToLowest(); 97 | } 98 | 99 | multiplicate(value: number): void; 100 | multiplicate(value: Number): void; 101 | multiplicate(value: any): void 102 | { 103 | if (value instanceof Fraction) 104 | { 105 | var val = value; 106 | this.numerator.multiplicate(val.numerator); 107 | this.denominator.multiplicate(val.denominator); 108 | } 109 | else 110 | { 111 | this.numerator.multiplicate(value); 112 | } 113 | } 114 | 115 | divide(value: number): void; 116 | divide(value: Number): void; 117 | divide(value: any): void 118 | { 119 | if (value instanceof Fraction) 120 | { 121 | var val = value; 122 | this.denominator.multiplicate(val.numerator); 123 | this.numerator.multiplicate(val.denominator); 124 | } 125 | else 126 | { 127 | this.denominator.multiplicate(value); 128 | } 129 | } 130 | 131 | swap(other: Number): void 132 | { 133 | var copy = other.clone(this.copyName); 134 | other.set(this); 135 | this.set(copy); 136 | } 137 | 138 | clone(cloneName?: string): Fraction 139 | { 140 | return new Fraction(this.numerator.clone(), this.denominator.clone(), cloneName); 141 | } 142 | 143 | reduceToLowest(accuracy: number = 2): void 144 | { 145 | accuracy = Math.pow(10, accuracy); 146 | this.numerator.multiplicate(accuracy); 147 | this.numerator.divide(this.denominator); 148 | this.denominator.set(accuracy); 149 | } 150 | 151 | isExact(value: number, callback?: Function): MinecraftCommand 152 | { 153 | return this.isBetween(value, value, callback); 154 | } 155 | 156 | isBetween(min?: number, max?: number, callback?: Function): MinecraftCommand 157 | { 158 | return this.toInteger().isBetween(min, max, callback); 159 | } 160 | 161 | toInteger(): Integer 162 | { 163 | var out = new Integer(0, this.name, false); 164 | out.set(this.numerator); 165 | out.divide(this.denominator); 166 | return out; 167 | } 168 | 169 | toTellrawExtra(): Chat.TellrawScoreExtra 170 | { 171 | return this.toInteger().toTellrawExtra(); 172 | } 173 | toExactTellrawExtra(): Chat.Message[] 174 | { 175 | var messages = []; 176 | messages[0] = this.numerator.toTellrawExtra(); 177 | messages[1] = new Chat.Message("/"); 178 | messages[2] = this.denominator.toTellrawExtra(); 179 | 180 | return messages; 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /CommandBlocksJS.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd", "Cmd\Cmd.csproj", "{99187E44-6CFD-4E68-9D13-8C3633DE275A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUI", "GUI\GUI.csproj", "{FCDB301D-B8E9-486D-BB14-95EE8D0776ED}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{F14C26CD-536A-44C4-879A-2ECCD9FBC47D}" 11 | ProjectSection(SolutionItems) = preProject 12 | Example\Blockhandles.ts = Example\Blockhandles.ts 13 | Example\Calculator.ts = Example\Calculator.ts 14 | Example\CircleCalculations.ts = Example\CircleCalculations.ts 15 | Example\Fibonacci.ts = Example\Fibonacci.ts 16 | Example\Paint.ts = Example\Paint.ts 17 | Example\TriangleCalculations.ts = Example\TriangleCalculations.ts 18 | EndProjectSection 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{2AAF7F56-EE73-4559-A4C4-3E5968E38F13}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeCmd", "NodeCmd\NodeCmd.csproj", "{F25C5129-2793-47A6-9783-127B5573C1DD}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Debug|Mixed Platforms = Debug|Mixed Platforms 28 | Debug|x86 = Debug|x86 29 | Release|Any CPU = Release|Any CPU 30 | Release|Mixed Platforms = Release|Mixed Platforms 31 | Release|x86 = Release|x86 32 | EndGlobalSection 33 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 34 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Debug|Any CPU.ActiveCfg = Debug|x86 35 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 36 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Debug|Mixed Platforms.Build.0 = Debug|x86 37 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Debug|x86.ActiveCfg = Debug|x86 38 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Debug|x86.Build.0 = Debug|x86 39 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Release|Any CPU.ActiveCfg = Release|x86 40 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Release|Mixed Platforms.ActiveCfg = Release|x86 41 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Release|Mixed Platforms.Build.0 = Release|x86 42 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Release|x86.ActiveCfg = Release|x86 43 | {99187E44-6CFD-4E68-9D13-8C3633DE275A}.Release|x86.Build.0 = Release|x86 44 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 47 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 48 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Debug|x86.ActiveCfg = Debug|Any CPU 49 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 52 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Release|Mixed Platforms.Build.0 = Release|Any CPU 53 | {FCDB301D-B8E9-486D-BB14-95EE8D0776ED}.Release|x86.ActiveCfg = Release|Any CPU 54 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 57 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 58 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Debug|x86.ActiveCfg = Debug|Any CPU 59 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Release|Any CPU.ActiveCfg = Release|Any CPU 60 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Release|Any CPU.Build.0 = Release|Any CPU 61 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 62 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Release|Mixed Platforms.Build.0 = Release|Any CPU 63 | {2AAF7F56-EE73-4559-A4C4-3E5968E38F13}.Release|x86.ActiveCfg = Release|Any CPU 64 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 65 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Debug|Any CPU.Build.0 = Debug|Any CPU 66 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 67 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 68 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Debug|x86.ActiveCfg = Debug|Any CPU 69 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Release|Any CPU.ActiveCfg = Release|Any CPU 70 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Release|Any CPU.Build.0 = Release|Any CPU 71 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 72 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Release|Mixed Platforms.Build.0 = Release|Any CPU 73 | {F25C5129-2793-47A6-9783-127B5573C1DD}.Release|x86.ActiveCfg = Release|Any CPU 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(MonoDevelopProperties) = preSolution 79 | StartupItem = ServerWrapper\ServerWrapper.csproj 80 | EndGlobalSection 81 | EndGlobal 82 | -------------------------------------------------------------------------------- /Core/Entities/SelectorArgument.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | module Entities 4 | { 5 | export class SelectorArgument 6 | { 7 | identifier: string; 8 | stringValue: string; 9 | value: any; 10 | 11 | private type: string; 12 | private typeConverter: (any) => string; 13 | 14 | constructor(identifier: string, type: string = "string", typeConverter: (any) => string = (a) => { return a; }) 15 | { 16 | this.identifier = identifier; 17 | this.type = type; 18 | this.typeConverter = typeConverter; 19 | } 20 | 21 | setValue(value: any, invert: boolean = false) 22 | { 23 | Util.assert(typeof value == this.type); 24 | Util.assert((!invert) || (["team", "name", "type"].indexOf(this.identifier) != -1)); 25 | this.stringValue = (invert ? "!" : "") + this.typeConverter(value); 26 | this.value = value; 27 | } 28 | 29 | setRaw(value: string) 30 | { 31 | this.stringValue = value; 32 | this.value = value; 33 | } 34 | 35 | clone(): SelectorArgument 36 | { 37 | var other = new SelectorArgument(this.identifier, this.type, this.typeConverter); 38 | other.setRaw(this.stringValue); 39 | return other; 40 | } 41 | 42 | static positionX() { return new SelectorArgument("x", "number", (x) => { return x.toString(); }); } 43 | static positionY() { return new SelectorArgument("y", "number", (y) => { return y.toString(); }); } 44 | static positionZ() { return new SelectorArgument("z", "number", (z) => { return z.toString(); }); } 45 | 46 | static radiusMax() { return new SelectorArgument("r", "number", (r) => { return r.toString(); }); } 47 | static radiusMin() { return new SelectorArgument("rm", "number", (rm) => { return rm.toString(); }); } 48 | 49 | static gamemode() { return new SelectorArgument("m", "object", (m) => { Util.assert(m instanceof Players.GameMode); return (m).toNumber().toString(); }); } 50 | 51 | static count() { return new SelectorArgument("c", "number", (c) => { return c.toString(); }); } 52 | 53 | static levelMax() { return new SelectorArgument("l", "number", (l) => { return l.toString(); }); } 54 | static levelMin() { return new SelectorArgument("lm", "number", (lm) => { return lm.toString(); }); } 55 | 56 | static team() { return new SelectorArgument("team", "object", (team) => { Util.assert(team instanceof Scoreboard.Team); return (team).name; }); } 57 | 58 | static playerName() { return new SelectorArgument("name", "string"); } //funtion.name is reserved 59 | 60 | static diameterX() { return new SelectorArgument("dx", "number", (dx) => { return dx.toString(); }); } 61 | static diameterY() { return new SelectorArgument("dy", "number", (dy) => { return dy.toString(); }); } 62 | static diameterZ() { return new SelectorArgument("dz", "number", (dz) => { return dz.toString(); }); } 63 | 64 | static rotationXMax() { return new SelectorArgument("rx", "number", (rx) => { return rx.toString(); }); } 65 | static rotationXMin() { return new SelectorArgument("rxm", "number", (rxm) => { return rxm.toString(); }); } 66 | 67 | static rotationYMax() { return new SelectorArgument("ry", "number", (ry) => { return ry.toString(); }); } 68 | static rotationYMin() { return new SelectorArgument("rym", "number", (rym) => { return rym.toString(); }); } 69 | 70 | static entityType() { return new SelectorArgument("type", "object", (type) => { Util.assert(type instanceof EntityType); return (type).name; }); } 71 | 72 | static scoreMin(objective: Scoreboard.Objective) { return new SelectorArgument("score_" + objective.name + "_min", "number", (dx) => { return dx.toString(); }); } 73 | 74 | static scoreMax(objective: Scoreboard.Objective) { return new SelectorArgument("score_" + objective.name, "number", (dx) => { return dx.toString(); }); } 75 | 76 | static parse(name: string): SelectorArgument 77 | { 78 | switch (name) 79 | { 80 | case "x": return SelectorArgument.positionX(); 81 | case "y": return SelectorArgument.positionY(); 82 | case "z": return SelectorArgument.positionZ(); 83 | 84 | case "r": return SelectorArgument.radiusMax(); 85 | case "rm": return SelectorArgument.radiusMin(); 86 | 87 | case "m": return SelectorArgument.gamemode(); 88 | 89 | case "c": return SelectorArgument.count(); 90 | 91 | case "l": return SelectorArgument.levelMax(); 92 | case "lm": return SelectorArgument.levelMin(); 93 | 94 | case "team": return SelectorArgument.team(); 95 | 96 | case "name": return SelectorArgument.playerName(); 97 | 98 | case "dx": return SelectorArgument.diameterX(); 99 | case "dy": return SelectorArgument.diameterY(); 100 | case "dz": return SelectorArgument.diameterZ(); 101 | 102 | case "rx": return SelectorArgument.rotationXMax(); 103 | case "rxm": return SelectorArgument.rotationXMin(); 104 | 105 | case "ry": return SelectorArgument.rotationYMax(); 106 | case "rym": return SelectorArgument.rotationYMin(); 107 | 108 | case "type": return SelectorArgument.entityType(); 109 | default: 110 | if (name.indexOf("score_") == 0) 111 | { 112 | if (name.indexOf("_min") != -1) 113 | { 114 | return new SelectorArgument(name, "number", (dx) => { return dx.toString(); }); 115 | } 116 | else 117 | { 118 | return new SelectorArgument(name, "number", (dx) => { return dx.toString(); }); 119 | } 120 | } 121 | Util.assert(false, "Unknown Selector name: " + name); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /GUI/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 32 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |