├── .atom-build.json ├── .gitignore ├── .jshintrc ├── LICENSE ├── README.md ├── examples ├── circle.lua ├── sinAndSqrt.lua ├── tests.lua └── train.lua ├── src ├── compiler.js ├── lib │ ├── Scope.js │ ├── base.js │ ├── baselib.js │ ├── export.js │ ├── naming.js │ ├── optimize.js │ └── types.js ├── luaparse.js ├── main.js ├── output │ ├── itemIds.json │ ├── rcon.js │ └── schematic.js ├── package.json └── types │ ├── Boolean.js │ ├── Float.js │ ├── Integer.js │ ├── Score.js │ ├── String.js │ └── Table.js └── stdlib ├── chat.js ├── debug.js ├── debug.lua ├── math.lua ├── query.js ├── random.js ├── random.lua ├── time.lua └── title.js /.atom-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmd": "node", 3 | "args": [ 4 | "{PROJECT_PATH}/src/main.js", 5 | "{PROJECT_PATH}/examples/tests.lua" 6 | ], 7 | "cwd": "{PROJECT_PATH}/src" 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #node modules 2 | /src/node_modules/ 3 | /src/config.json 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "shadow": true, 3 | "sub": true, 4 | "eqeqeq": false 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | "THE BEER-WARE LICENSE": 2 | 3 | Jakob Löw wrote this code. As long as you retain this notice you 4 | can do whatever you want with this stuff. If we meet some day, and you think 5 | this stuff is worth it, you can buy me a beer in return. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MoonCraft 2 | 3 | Lua to commandblock compiler 4 | 5 | ## [Try it in your browser](http://m4gnv5.github.io/MoonCraft-Demo/) 6 | 7 | ## Example 8 | 9 | ```lua 10 | import("chat") 11 | 12 | radius = 1 13 | pi = 3.14 14 | 15 | tellraw("Circle circumference and area for radius 1 to 19") 16 | for radius = 1, 19 do 17 | area = pi * radius * radius 18 | circumference = pi * 2 * radius 19 | 20 | tellraw("r = ", radius, " C = ", circumference, " A = ", area) 21 | end 22 | ``` 23 | 24 | ![screenshot](http://i.imgur.com/UbzM9CW.png) 25 | -------------------------------------------------------------------------------- /examples/circle.lua: -------------------------------------------------------------------------------- 1 | import("chat") 2 | 3 | radius = 1 4 | pi = 3.14 5 | 6 | tellraw("Circle circumference and area for radius 1 to 19") 7 | for radius = 1, 19 do 8 | area = pi * radius * radius 9 | circumference = pi * 2 * radius 10 | 11 | tellraw("r = ", radius, " C = ", circumference, " A = ", area) 12 | end 13 | -------------------------------------------------------------------------------- /examples/sinAndSqrt.lua: -------------------------------------------------------------------------------- 1 | import("chat") 2 | import("math") 3 | import("random") 4 | 5 | function testSin() 6 | for value = 0.0, 6.28, 3.14 / 4 do 7 | tellraw("sin of ", value, " is ", sin(value)) 8 | end 9 | end 10 | 11 | function testRandomAbsedSqrt() 12 | for i = 0, 10 do 13 | local value = abs(rand_fast() % 401) 14 | local result = sqrt(value) 15 | tellraw("sqrt of ", value, " is ", result) 16 | end 17 | end 18 | 19 | testSin() 20 | testRandomAbsedSqrt() 21 | -------------------------------------------------------------------------------- /examples/tests.lua: -------------------------------------------------------------------------------- 1 | import("debug") 2 | import("chat") 3 | 4 | local myint = 42 5 | local myfloat = 13.37 6 | local mybool = true 7 | local mystr = "hi" 8 | local mytable = {42, 666, 3112} 9 | 10 | local i = 0 11 | 12 | function foo() 13 | i = i + 1 14 | if i == 3 then 15 | bar() 16 | else 17 | foo() 18 | end 19 | end 20 | 21 | function bar() 22 | i = i + 1 23 | if i == 6 then 24 | foobar() 25 | else 26 | bar() 27 | end 28 | end 29 | 30 | function foobar() 31 | i = i + 1 32 | if i == 9 then 33 | debug() 34 | else 35 | foobar() 36 | end 37 | 38 | end 39 | 40 | foo() 41 | -------------------------------------------------------------------------------- /examples/train.lua: -------------------------------------------------------------------------------- 1 | import("chat") 2 | 3 | --average speed 4 | speed = 8 --m/s 5 | 6 | working = true 7 | direction = 0 -- 0=z+ 1=x- 2=z- 3=x+ 8 | rail = -1 9 | totalCount = 0 10 | 11 | 12 | command("give @p minecraft:armor_stand 1 0 {EntityTag:{CustomName:train}}") 13 | 14 | tellraw("Please place the armorstand at the beginning of the track") 15 | repeat 16 | --wait 17 | until "testfor @e[type=ArmorStand,name=train]" 18 | 19 | 20 | 21 | waitTime = 20 22 | repeat 23 | waitTime = waitTime - 1 24 | until waitTime == 0 25 | 26 | 27 | tellraw("Please wait, detection in progress...") 28 | command("execute @e[type=ArmorStand,name=train] ~ ~ ~ summon ArmorStand ~ ~ ~ {CustomName:\"track\",Invisible:1b}") 29 | 30 | while working do 31 | 32 | totalCount = totalCount + 1 33 | 34 | if "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 0" then 35 | rail = 0 36 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 1" then 37 | rail = 1 38 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:golden_rail 0" then 39 | rail = 0 40 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:golden_rail 1" then 41 | rail = 1 42 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:golden_rail 8" then 43 | rail = 0 --powered straight rail 44 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:golden_rail 9" then 45 | rail = 1 --powered straight rail 46 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 6" then 47 | rail = 6 48 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 7" then 49 | rail = 7 50 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 8" then 51 | rail = 8 52 | elseif "execute @e[type=ArmorStand,name=train] ~ ~ ~ testforblock ~ ~ ~ minecraft:rail 9" then 53 | rail = 9 54 | else 55 | working = false 56 | direction = -1 57 | end 58 | 59 | if direction == 1 and rail == 6 or direction == 3 and rail == 7 then 60 | direction = 0 61 | elseif direction == 2 and rail == 7 or direction == 0 and rail == 8 then 62 | direction = 1 63 | elseif direction == 3 and rail == 8 or direction == 1 and rail == 9 then 64 | direction = 2 65 | elseif direction == 0 and rail == 9 or direction == 2 and rail == 6 then 66 | direction = 3 67 | end 68 | 69 | if direction == 0 then 70 | command("tp @e[type=ArmorStand,name=train] ~ ~ ~1") 71 | elseif direction == 1 then 72 | command("tp @e[type=ArmorStand,name=train] ~-1 ~ ~") 73 | elseif direction == 2 then 74 | command("tp @e[type=ArmorStand,name=train] ~ ~ ~-1") 75 | elseif direction == 3 then 76 | command("tp @e[type=ArmorStand,name=train] ~1 ~ ~") 77 | end 78 | 79 | end 80 | 81 | command("kill @e[type=ArmorStand,name=train]") 82 | travelTime = float(totalCount - 1) / speed 83 | tellraw("Detection done, estimated travel time: ", travelTime, " seconds") 84 | 85 | 86 | 87 | while true do 88 | repeat 89 | -- body... 90 | until "execute @e[type=ArmorStand,name=track] ~ ~ ~ testfor @p[r=0]" 91 | 92 | title_times(0, 99999, 0) 93 | title("") 94 | 95 | _travelTime = travelTime 96 | while _travelTime > 0 do 97 | _travelTime = _travelTime - 0.05 98 | subtitle("remaining time: ", _travelTime) 99 | end 100 | title_clear() 101 | end 102 | -------------------------------------------------------------------------------- /src/compiler.js: -------------------------------------------------------------------------------- 1 | var base = require("./lib/base.js"); 2 | var types = require("./lib/types.js"); 3 | var nextName = require("./lib/naming.js"); 4 | var optimize = require("./lib/optimize.js"); 5 | var scope = require("./lib/Scope.js"); 6 | 7 | var currRet = []; 8 | var breakLabel; 9 | 10 | var compile = function(ast, path, isMain) 11 | { 12 | for(var i = 0; i < ast.body.length; i++) 13 | { 14 | compileStatement(ast.body[i]); 15 | } 16 | 17 | optimize.garbageCollect(); 18 | }; 19 | compile.scope = scope; 20 | module.exports = compile; 21 | 22 | function throwError(message, loc) 23 | { 24 | var locStr = " at line "; 25 | if(loc.start.line == loc.end.line) 26 | locStr += loc.start.line + " column " + loc.start.column + " in " + compile.file; 27 | else 28 | locStr += loc.start.line + " column " + loc.start.column + " to line " + loc.end.line + " column " + loc.end.column + " in " + compile.file; 29 | 30 | throw message + locStr; 31 | } 32 | 33 | function compileBody(body, end, label, bodyScope) 34 | { 35 | label = label || nextName("body"); 36 | base.addFunction(label, function() 37 | { 38 | var _body = optimize.removeDeadEnds(body); 39 | 40 | scope.increase(bodyScope); 41 | compileStatementList(_body); 42 | optimize.garbageCollect(); 43 | scope.decrease(); 44 | 45 | if(end && body == _body) 46 | end(); 47 | }); 48 | return label; 49 | } 50 | 51 | function compileStatementList(stmts) 52 | { 53 | stmts = optimize.removeDeadEnds(stmts); 54 | for(var i = 0; i < stmts.length; i++) 55 | { 56 | compileStatement(stmts[i]); 57 | } 58 | } 59 | 60 | function compileStatement(stmt) 61 | { 62 | var type = stmt.type; 63 | 64 | if(!statements.hasOwnProperty(type)) 65 | throwError("unknown statement type " + type, stmt.loc); 66 | 67 | return statements[type](stmt); 68 | } 69 | 70 | function compileExpression(expr, supportArrays) 71 | { 72 | var type = expr.type; 73 | 74 | if(!expressions.hasOwnProperty(type)) 75 | throwError("unknown expression type " + type, expr.loc); 76 | 77 | var val = expressions[type](expr); 78 | 79 | if(!supportArrays && val instanceof Array) 80 | return val[0]; 81 | else 82 | return val; 83 | } 84 | 85 | function checkTypeMismatch(left, right, loc) 86 | { 87 | if(!typeMatch(left, right)) 88 | throwError("Incompatible types " + left.constructor.name + " and " + right.constructor.name, loc); 89 | } 90 | 91 | function typeMatch(left, right) 92 | { 93 | var compatibleTypes = [ 94 | [types.Integer, types.Float, types.Score, (0).constructor, types.Boolean, (true).constructor], //int, float 95 | [types.Table, Array], //table, array 96 | [types.String, ("").constructor] //string 97 | ]; 98 | 99 | if(left.constructor == right.constructor) 100 | return true; 101 | 102 | for(var i = 0; i < compatibleTypes.length; i++) 103 | { 104 | if(compatibleTypes[i].indexOf(left.constructor) != -1 && compatibleTypes[i].indexOf(right.constructor) != -1) 105 | { 106 | return true; 107 | } 108 | } 109 | 110 | return false; 111 | } 112 | 113 | function checkOperator(val, op, opLabel, loc) 114 | { 115 | if(typeof val[op] != "function") 116 | throwError("Type " + val.constructor.name + " does not support operator " + opLabel, loc); 117 | } 118 | 119 | function trueify(val, loc) 120 | { 121 | return boolify(val, true, loc); 122 | } 123 | function falseify(val, loc) 124 | { 125 | return boolify(val, false, loc); 126 | } 127 | 128 | function boolify(val, type, loc) 129 | { 130 | var label = nextName("trueify"); 131 | if(typeof val == "string") 132 | { 133 | if(type) 134 | { 135 | return val; 136 | } 137 | else 138 | { 139 | base.addLabel(label); 140 | command(val); 141 | return "testforblock %" + label + ":diff% minecraft:chain_command_block -1 {SuccessCount:0}"; 142 | } 143 | } 144 | else if(typeof val != "object") 145 | { 146 | val = !val; 147 | if(type) 148 | val = !val; 149 | return val ? "testfor @e" : "falsy: " + val.toString(); 150 | } 151 | else if(val instanceof types.Boolean) 152 | { 153 | return val.isExact(type); 154 | } 155 | else if(val instanceof types.String) 156 | { 157 | var cmd = val.isExact(""); 158 | 159 | if(type) 160 | { 161 | base.addLabel(label); 162 | base.command(cmd); 163 | return "testforblock %" + label + ":diff% minecraft:chain_command_block -1 {SuccessCount:0}"; 164 | } 165 | else 166 | { 167 | return cmd; 168 | } 169 | } 170 | else if(val.toInteger) 171 | { 172 | var fn = val.isExact ? val.isExact : val.toInteger().isExact; 173 | var cmd = fn.call(val, 0); 174 | 175 | if(type) 176 | { 177 | base.addLabel(label); 178 | base.command(cmd); 179 | return "testforblock %" + label + ":diff% minecraft:chain_command_block -1 {SuccessCount:0}"; 180 | } 181 | else 182 | { 183 | return cmd; 184 | } 185 | } 186 | else 187 | { 188 | throwError("cannot boolify " + val.constructor.name, loc); 189 | } 190 | } 191 | 192 | function createRuntimeVar(val, name) 193 | { 194 | if(typeof val == "boolean" || val.constructor == types.Boolean) 195 | return new types.Boolean(val, name); 196 | else if((typeof val == "number" && Math.round(val) == val) || val.constructor == types.Integer) 197 | return new types.Integer(val, name); 198 | else if(typeof val == "number" || val.constructor == types.Float) 199 | return new types.Float(val, name); 200 | else if(typeof val == "string" && val[0] == "/") 201 | return commandToBool(val, name); 202 | else if(typeof val == "string" || val.constructor == types.String) 203 | return new types.String(val, name); 204 | else if(val instanceof types.Score) 205 | return val; 206 | else if(val instanceof Array || val instanceof types.Table) 207 | return new types.Table(val, name); 208 | } 209 | 210 | function commandToBool(cmd, name) 211 | { 212 | var val = new types.Boolean(false, name); 213 | command(cmd); 214 | val.set(true, true); 215 | return val; 216 | } 217 | 218 | function assignStatement(stmt, scopeGet, scopeSet) 219 | { 220 | function assign(left, newVal, optimized) 221 | { 222 | var key; 223 | var oldVal; 224 | if(left.type == "Identifier") 225 | { 226 | key = left.name; 227 | oldVal = scopeGet(key); 228 | } 229 | else if(left.type == "IndexExpression") 230 | { 231 | var index = compileExpression(left.index); 232 | var base = compileExpression(left.base); 233 | 234 | base.setAt(index, newVal); 235 | return; 236 | } 237 | else 238 | { 239 | oldVal = compileExpression(left); 240 | } 241 | 242 | if(!oldVal && key) 243 | { 244 | var name = nextName(key); 245 | oldVal = createRuntimeVar(newVal, name); 246 | scopeSet(key, oldVal); 247 | } 248 | else if(optimized) 249 | { 250 | var ops = { 251 | "+": "add", 252 | "-": "remove", 253 | "*": "multiplicate", 254 | "/": "divide", 255 | "%": "mod" 256 | }; 257 | oldVal[ops[optimized.operator]](newVal); 258 | } 259 | else if(oldVal) 260 | { 261 | checkTypeMismatch(oldVal, newVal, stmt.loc); 262 | oldVal.set(newVal); 263 | } 264 | else 265 | { 266 | throwError("Invalid assign statement", stmt.loc); 267 | } 268 | } 269 | 270 | 271 | var rest; 272 | for(var i = 0; i < stmt.variables.length && i < stmt.init.length; i++) 273 | { 274 | var left = stmt.variables[i]; 275 | var right = stmt.init[i]; 276 | 277 | var optimized = optimize.selfAssign(left, right); 278 | 279 | var rightExpr = optimized ? optimized.argument : right; 280 | var newVal = compileExpression(rightExpr, true); 281 | 282 | if(newVal instanceof Array) 283 | { 284 | rest = newVal.slice(1); 285 | newVal = newVal[0]; 286 | } 287 | else 288 | { 289 | rest = []; 290 | } 291 | 292 | assign(left, newVal, optimized); 293 | } 294 | 295 | for(var i = 0; i < rest.length; i++) 296 | { 297 | var left = stmt.variables[i + stmt.init.length]; 298 | if(!left) 299 | return; 300 | 301 | var newVal = rest[i]; 302 | 303 | assign(left, newVal); 304 | } 305 | } 306 | 307 | function resolveType(name, loc) 308 | { 309 | var alias = { 310 | "Boolean": ["bool", "boolean"], 311 | "Integer": ["int", "i32", "integer", "number"], 312 | "Float": ["float"], 313 | "String": ["string"], 314 | "Table": ["table", "array"] 315 | }; 316 | 317 | name = name.toLowerCase(); 318 | for(var key in alias) 319 | { 320 | if(alias[key].indexOf(name) != -1) 321 | return types[key]; 322 | } 323 | 324 | throwError("Unknown type " + name, loc); 325 | } 326 | 327 | var statements = {}; 328 | var expressions = {}; 329 | 330 | statements["AssignmentStatement"] = function(stmt) 331 | { 332 | assignStatement(stmt, scope.get.bind(scope), scope.setGlobal.bind(scope)); 333 | }; 334 | 335 | statements["LocalStatement"] = function(stmt) 336 | { 337 | assignStatement(stmt, function(key) 338 | { 339 | return scope.current()[key]; 340 | }, scope.set.bind(scope)); 341 | }; 342 | 343 | statements["FunctionDeclaration"] = function(stmt) 344 | { 345 | var funcName = stmt.identifier.name; 346 | var bodyName; 347 | 348 | scope.increase(); 349 | var funcStack = scope.save(); 350 | scope.decrease(); 351 | 352 | var typeSignature = []; 353 | var returnSignature = false; 354 | var argNames = []; 355 | 356 | var func = function() 357 | { 358 | if(stmt.parameters.length != arguments.length) 359 | { 360 | throwError("function {0} requires {1} arguments not {2}" 361 | .format(funcName, stmt.parameters.length, arguments.length), stmt.loc); 362 | } 363 | 364 | var _stack = scope.save(); 365 | scope.load(funcStack); 366 | for(var i = 0; i < stmt.parameters.length; i++) 367 | { 368 | var name; 369 | if(stmt.parameters[i].type == "TypedIdentifier") 370 | name = stmt.parameters[i].identifier.name; 371 | else 372 | name = stmt.parameters[i].name; 373 | 374 | var val = arguments[i]; 375 | 376 | if(typeSignature[i] && !typeMatch(typeSignature[i], val)) 377 | { 378 | throwError("function {0} requires argument {1} to be {2} not {3}" 379 | .format(funcName, i, typeSignature[i].constructor.name, val.constructor.name), stmt.loc); 380 | } 381 | 382 | if(!typeSignature[i]) 383 | { 384 | argNames[i] = nextName(name); 385 | val = createRuntimeVar(val, argNames[i]) 386 | typeSignature[i] = val; 387 | scope.set(name, val); 388 | } 389 | else 390 | { 391 | scope.get(name).set(val); 392 | } 393 | } 394 | scope.load(_stack); 395 | 396 | if(!bodyName) 397 | { 398 | bodyName = funcName; 399 | 400 | var _currRet = currRet; 401 | 402 | currRet = returnSignature; 403 | scope.load(funcStack); 404 | compileBody(stmt.body, base.ret, funcName); 405 | scope.load(_stack); 406 | returnSignature = currRet; 407 | 408 | 409 | currRet = _currRet; 410 | 411 | func.funcName = funcName; 412 | func.typeSignature = typeSignature; 413 | func.returnSignature = returnSignature; 414 | } 415 | 416 | 417 | base.rjump(bodyName); 418 | 419 | return returnSignature; 420 | }; 421 | 422 | var _stack = scope.save(); 423 | scope.load(funcStack); 424 | 425 | var allTyped = true; 426 | for(var i = 0; i < stmt.parameters.length; i++) 427 | { 428 | var param = stmt.parameters[i]; 429 | if(param.type == "TypedIdentifier") 430 | { 431 | var name = param.identifier.name; 432 | var ctor = resolveType(param.varType.name, param.varType.loc); 433 | 434 | typeSignature[i] = new ctor(0, nextName(name), true); 435 | scope.set(name, typeSignature[i]); 436 | } 437 | else 438 | { 439 | allTyped = false; 440 | continue; 441 | } 442 | } 443 | if(allTyped) 444 | func.typeSignature = typeSignature; 445 | 446 | if(stmt.returnTypes.length == 1 && stmt.returnTypes[0].name == "void") 447 | { 448 | returnSignature = []; 449 | func.returnSignature = returnSignature; 450 | } 451 | else if(stmt.returnTypes.length > 0) 452 | { 453 | returnSignature = []; 454 | for(var i = 0; i < stmt.returnTypes.length; i++) 455 | { 456 | var typeName = stmt.returnTypes[i].name; 457 | var ctor = resolveType(typeName, stmt.returnTypes[i].loc); 458 | 459 | var name = nextName("ret" + i + typeName); 460 | returnSignature[i] = new ctor(0, name, true); 461 | } 462 | func.returnSignature = returnSignature; 463 | } 464 | else 465 | { 466 | allTyped = false; 467 | } 468 | 469 | if(allTyped) 470 | { 471 | bodyName = funcName; 472 | 473 | var _currRet = currRet; 474 | 475 | currRet = returnSignature; 476 | compileBody(stmt.body, base.ret, funcName); 477 | currRet = _currRet; 478 | 479 | func.funcName = funcName; 480 | } 481 | 482 | scope.load(_stack); 483 | 484 | if(stmt.isLocal) 485 | scope.set(funcName, func); 486 | else 487 | scope.setGlobal(funcName, func); 488 | }; 489 | 490 | statements["ReturnStatement"] = function(stmt) 491 | { 492 | var args = []; 493 | for(var i = 0; i < stmt.arguments.length; i++) 494 | { 495 | args[i] = compileExpression(stmt.arguments[i]); 496 | } 497 | 498 | if(currRet) 499 | { 500 | if(stmt.arguments.length != currRet.length) 501 | throwError("cannot return a different count of arguments than before", stmt.loc); 502 | 503 | for(var i = 0; i < currRet.length && i < args.length; i++) 504 | { 505 | if(!typeMatch(currRet[i], args[i])) 506 | throwError("cannot return a different type signature than before", stmt.arguments[i].loc); 507 | 508 | currRet[i].set(args[i]); 509 | } 510 | } 511 | else 512 | { 513 | currRet = []; 514 | for(var i = 0; i < args.length; i++) 515 | { 516 | var name = nextName("ret" + i + args[i].constructor.name); 517 | currRet[i] = createRuntimeVar(args[i], name); 518 | } 519 | } 520 | 521 | base.ret(); 522 | block(options.splitterBlock); 523 | }; 524 | 525 | statements["BreakStatement"] = function(stmt) 526 | { 527 | if(!breakLabel) 528 | throwError("Invalid break statement", stmt.loc); 529 | 530 | base.jump(breakLabel); 531 | block(options.splitterBlock); 532 | }; 533 | 534 | statements["CallStatement"] = function(stmt) 535 | { 536 | compileExpression(stmt.expression); 537 | }; 538 | 539 | statements["IfStatement"] = function(stmt) 540 | { 541 | var clauses = stmt.clauses; 542 | 543 | var endLabel = nextName("ifend"); 544 | 545 | var hasSucess = new types.Boolean(false, nextName("ifsuccess")); 546 | 547 | var hasElse = false; 548 | 549 | for(var i = 0; i < clauses.length; i++) 550 | { 551 | var type = clauses[i].type; 552 | 553 | if(type == "IfClause") 554 | { 555 | var expr = compileExpression(clauses[i].condition); 556 | var bodyLabel = compileBody(clauses[i].body, base.jump.bind(base, endLabel)); 557 | 558 | command(trueify(expr, clauses[i].condition.loc)); 559 | 560 | base.jump(bodyLabel, true); 561 | hasSucess.set(true, true); 562 | } 563 | else if(type == "ElseifClause") 564 | { 565 | var expr = compileExpression(clauses[i].condition); 566 | var bodyLabel = compileBody(clauses[i].body, base.jump.bind(base, endLabel)); 567 | 568 | var cmd = trueify(expr, clauses[i].condition.loc); 569 | 570 | command(hasSucess.isExact(false)); 571 | command(cmd, true); 572 | 573 | base.jump(bodyLabel, true); 574 | hasSucess.set(true, true); 575 | } 576 | else if(type == "ElseClause") 577 | { 578 | var bodyLabel = compileBody(clauses[i].body, base.jump.bind(base, endLabel)); 579 | 580 | command(hasSucess.isExact(false)); 581 | base.jump(bodyLabel, true); 582 | 583 | hasElse = true; 584 | } 585 | else 586 | { 587 | throwError("unsupported clause " + clauses[i].type, stmt.loc); 588 | } 589 | } 590 | 591 | if(!hasElse) 592 | { 593 | command(hasSucess.isExact(false)); 594 | base.jump(endLabel, true); 595 | } 596 | 597 | block(options.splitterBlock); 598 | base.addLabel(endLabel); 599 | }; 600 | 601 | statements["ForNumericStatement"] = function(stmt) 602 | { 603 | var iteratorName = stmt.variable.name; 604 | var start = compileExpression(stmt.start); 605 | var end = compileExpression(stmt.end); 606 | 607 | var iterator = createRuntimeVar(start, nextName(iteratorName)); 608 | var step = stmt.step ? compileExpression(stmt.step) : 1; 609 | 610 | var checkCondition; 611 | if(typeof step == "number" && typeof end == "number") 612 | { 613 | checkCondition = function() 614 | { 615 | if(step > 0) 616 | return iterator.isBetween(undefined, end); 617 | else if(step <= 0) 618 | return iterator.isBetween(end, undefined); 619 | }; 620 | } 621 | else if(typeof step == "number" && typeof end == "object") 622 | { 623 | checkCondition = function() 624 | { 625 | checkOperator(end, "clone", "clone", stmt.end.loc); 626 | var clone = end.clone(); 627 | clone.remove(iterator); 628 | if(step > 0) 629 | return clone.isBetween(0, undefined); 630 | else if(step <= 0) 631 | return clone.isBetween(undefined, 0); 632 | }; 633 | } 634 | else if(typeof step == "object" && typeof end == "number") 635 | { 636 | checkCondition = function() 637 | { 638 | var success = new types.Boolean(false, "forsuccess"); 639 | 640 | command(step.isBetweenEx(0, undefined)); 641 | command(iterator.isBetween(undefined, end), true); 642 | success.set(true, true); 643 | 644 | command(step.isBetween(undefined, 0)); 645 | command(iterator.isBetween(end, undefined), true); 646 | success.set(true, true); 647 | 648 | return success.isExact(true); 649 | }; 650 | } 651 | else if(typeof step == "object" && typeof end == "object") 652 | { 653 | checkCondition = function() 654 | { 655 | var success = new types.Boolean(false, "forsuccess"); 656 | 657 | checkOperator(end, "clone", "clone", stmt.end.loc); 658 | var clone = end.clone(); 659 | clone.remove(iterator); 660 | 661 | command(step.isBetweenEx(0, undefined)); 662 | command(clone.isBetween(0, undefined), true); 663 | success.set(true, true); 664 | 665 | command(step.isBetween(undefined, 0)); 666 | command(clone.isBetween(undefined, 0), true); 667 | success.set(true, true); 668 | 669 | return success.isExact(true); 670 | }; 671 | } 672 | 673 | scope.increase(); 674 | scope.set(iteratorName, iterator); 675 | var forScope = scope.decrease(); 676 | 677 | var bodyLabel = nextName("for"); 678 | var checkLabel = bodyLabel + "check"; 679 | var endLabel = bodyLabel + "end"; 680 | 681 | var _breakLabel = breakLabel; 682 | breakLabel = endLabel; 683 | 684 | base.jump(checkLabel); 685 | block(options.splitterBlock); 686 | 687 | base.addFunction(bodyLabel, function() 688 | { 689 | scope.increase(forScope); 690 | 691 | compileStatementList(stmt.body); 692 | 693 | if(typeof step == "object") 694 | iterator.add(step); 695 | else if(step < 0) 696 | iterator.remove(-step); 697 | else if(step > 0) 698 | iterator.add(step); 699 | 700 | base.addLabel(checkLabel); 701 | command(checkCondition()); 702 | base.jump(bodyLabel, true); 703 | command("testforblock %-2:diff% minecraft:chain_command_block -1 {SuccessCount:0}"); 704 | base.jump(endLabel, true); 705 | 706 | scope.decrease(); 707 | }); 708 | 709 | base.addLabel(endLabel); 710 | scope.increase(forScope); 711 | optimize.garbageCollect(); 712 | scope.decrease(); 713 | 714 | breakLabel = _breakLabel; 715 | }; 716 | 717 | statements["DoStatement"] = function(stmt) 718 | { 719 | scope.increase(); 720 | compileStatementList(stmt.body); 721 | optimize.garbageCollect(); 722 | scope.decrease(); 723 | }; 724 | 725 | statements["WhileStatement"] = function(stmt) 726 | { 727 | var bodyLabel = nextName("while"); 728 | var checkLabel = bodyLabel + "check"; 729 | var endLabel = bodyLabel + "end"; 730 | 731 | var _breakLabel = breakLabel; 732 | breakLabel = endLabel; 733 | 734 | base.jump(checkLabel); 735 | block(options.splitterBlock); 736 | 737 | scope.increase(); 738 | var whileScope = scope.decrease(); 739 | 740 | base.addFunction(bodyLabel, function() 741 | { 742 | scope.increase(whileScope); 743 | 744 | compileStatementList(stmt.body); 745 | 746 | base.addLabel(checkLabel); 747 | var condition = compileExpression(stmt.condition); 748 | command(trueify(condition, stmt.condition.loc)); 749 | base.jump(bodyLabel, true); 750 | 751 | command("testforblock %-2:diff% minecraft:chain_command_block -1 {SuccessCount:0}"); 752 | base.jump(endLabel, true); 753 | 754 | scope.decrease(); 755 | }); 756 | 757 | base.addLabel(endLabel); 758 | scope.increase(whileScope); 759 | optimize.garbageCollect(); 760 | scope.decrease(); 761 | 762 | breakLabel = _breakLabel; 763 | }; 764 | 765 | statements["RepeatStatement"] = function(stmt) 766 | { 767 | var bodyLabel = nextName("repeat"); 768 | var endLabel = bodyLabel + "end"; 769 | 770 | var _breakLabel = breakLabel; 771 | breakLabel = endLabel; 772 | 773 | base.addLabel(bodyLabel); 774 | 775 | scope.increase(); 776 | compileStatementList(stmt.body); 777 | 778 | var condition = compileExpression(stmt.condition); 779 | command(falseify(condition, stmt.condition.loc)); 780 | base.jump(bodyLabel, true); 781 | 782 | command("testforblock %-2:diff% minecraft:chain_command_block -1 {SuccessCount:0}"); 783 | base.jump(endLabel, true); 784 | 785 | block(options.splitterBlock); 786 | base.addLabel(endLabel); 787 | optimize.garbageCollect(); 788 | scope.decrease(); 789 | 790 | breakLabel = _breakLabel; 791 | }; 792 | 793 | expressions["TableConstructorExpression"] = function(expr) 794 | { 795 | var args = []; 796 | for(var i = 0; i < expr.fields.length; i++) 797 | { 798 | if(expr.fields[i].type != "TableValue") 799 | throwError("Unsupported table field type", field.loc); 800 | 801 | args[i] = compileExpression(expr.fields[i].value); 802 | } 803 | 804 | return [args]; 805 | } 806 | 807 | expressions["IndexExpression"] = function(expr) 808 | { 809 | var base = compileExpression(expr.base); 810 | 811 | checkOperator(base, "get", "[index]", expr.base.loc); 812 | 813 | var index = compileExpression(expr.index); 814 | 815 | return base.get(index); 816 | } 817 | 818 | function valueLiteral(expr) 819 | { 820 | return expr.value; 821 | } 822 | 823 | expressions["BooleanLiteral"] = valueLiteral; 824 | expressions["NumericLiteral"] = function(expr) 825 | { 826 | if(expr.raw && expr.raw.indexOf(".") != -1 && Math.floor(expr.value) == expr.value) 827 | return expr.value + 0.000001; 828 | else 829 | return expr.value; 830 | }; 831 | expressions["StringLiteral"] = valueLiteral; 832 | 833 | expressions["Identifier"] = function(expr) 834 | { 835 | var val = scope.get(expr.name); 836 | if(!val) 837 | throwError("use of undefined variable " + expr.name, expr.loc); 838 | return val; 839 | }; 840 | 841 | expressions["CallExpression"] = function(expr) 842 | { 843 | var base = compileExpression(expr.base); 844 | var args = []; 845 | 846 | for(var i = 0; i < expr.arguments.length; i++) 847 | { 848 | args[i] = compileExpression(expr.arguments[i]); 849 | } 850 | 851 | if(typeof base != "function") 852 | throwError(base.constructor.name + " is not a function", expr.loc); 853 | 854 | try 855 | { 856 | return base.apply(undefined, args); 857 | } 858 | catch (e) 859 | { 860 | var fnName = expr.base.name || base.name; 861 | 862 | if(options.debug) 863 | { 864 | console.log("- while calling " + fnName); 865 | throw e; 866 | } 867 | 868 | throwError(e.toString() + "\n- while calling " + fnName, expr.loc); 869 | } 870 | }; 871 | 872 | expressions["UnaryExpression"] = function(expr) 873 | { 874 | var left = compileExpression(expr.argument); 875 | 876 | if(expr.operator == "not") 877 | { 878 | return "/" + falseify(left, expr.loc); 879 | } 880 | else if(expr.operator == "-") 881 | { 882 | if(typeof left == "object") 883 | { 884 | var clone = left.isClone ? left : left.clone(); 885 | clone.isClone = true; 886 | 887 | checkOperator(left, "multiplicate", "-", expr.loc); 888 | clone.multiplicate(-1); 889 | 890 | return clone; 891 | } 892 | else 893 | { 894 | return -1 * left; 895 | } 896 | } 897 | else if(expr.operator == "#") 898 | { 899 | if(left.hasOwnProperty("length")) 900 | return left.length; 901 | else 902 | throwError("Cannot get the length of a variable of type " + left.constructor.name, expr.loc); 903 | } 904 | }; 905 | 906 | expressions["LogicalExpression"] = function(expr) 907 | { 908 | var left = compileExpression(expr.left); 909 | var right = compileExpression(expr.right); 910 | var operator = expr.operator; 911 | 912 | var compileTimeOps = { 913 | "and": function(a, b) { return a && b; }, 914 | "or": function(a, b) { return a || b; } 915 | }; 916 | 917 | var isLeftCmd = typeof left == "string" && expr.left.type != "StringLiteral"; 918 | var isRightCmd = typeof right == "string" && expr.right.type != "StringLiteral"; 919 | 920 | if(isLeftCmd && !isRightCmd) 921 | { 922 | left = commandToBool(left); 923 | } 924 | else if(isRightCmd && !isLeftCmd) 925 | { 926 | right = commandToBool(right); 927 | } 928 | 929 | if(typeof left != "object" && typeof right != "object" && !(isLeftCmd || isRightCmd)) 930 | return compileTimeOps[operator](left, right); 931 | 932 | var _left = typeof left == "object" ? left : right; 933 | var _right = typeof left == "object" ? right : left; 934 | 935 | if(typeMatch(left, right) && !(isLeftCmd || isRightCmd)) 936 | { 937 | var val = new _left.constructor(_left, nextName(operator)); 938 | val.isClone = true; 939 | 940 | if(operator == "and") 941 | { 942 | var isLeftTrue = trueify(_left, expr.loc); 943 | command(isLeftTrue); 944 | val.set(_right, true); 945 | } 946 | else if(operator == "or") 947 | { 948 | var isLeftFalse = falseify(_left, expr.loc); 949 | command(isLeftFalse); 950 | val.set(_right, true); 951 | } 952 | 953 | return val; 954 | } 955 | else 956 | { 957 | if(operator == "and") 958 | { 959 | var val = new types.Boolean(false, nextName("and")); 960 | val.isClone = true; 961 | var isLeftTrue = trueify(_left, expr.loc); 962 | var isRightTrue = trueify(_right, expr.loc); 963 | 964 | command(isLeftTrue); 965 | command(isRightTrue, true); 966 | val.set(true, true); 967 | 968 | return val; 969 | } 970 | else if(operator == "or") 971 | { 972 | var val = new types.Boolean(true, nextName("and")); 973 | val.isClone = true; 974 | var isLeftFalse = falseify(_left, expr.loc); 975 | var isRightFalse = falseify(_right, expr.loc); 976 | 977 | command(isLeftFalse); 978 | command(isRightFalse, true); 979 | val.set(false, true); 980 | 981 | return val; 982 | } 983 | } 984 | }; 985 | 986 | expressions["BinaryExpression"] = function(expr) 987 | { 988 | var left = compileExpression(expr.left); 989 | var right = compileExpression(expr.right); 990 | var operator = expr.operator; 991 | 992 | checkTypeMismatch(left, right, expr.loc); 993 | 994 | var noCommutative = ["/", "%", "<", ">", "<=", ">="]; 995 | 996 | var compileTimeOps = { 997 | "+": function(a, b) { return a + b; }, 998 | "-": function(a, b) { return a - b; }, 999 | "*": function(a, b) { return a * b; }, 1000 | "/": function(a, b) { return a / b; }, 1001 | "%": function(a, b) { return a % b; }, 1002 | "..": function(a, b) { return a.toString() + b.toString(); }, 1003 | "^": function(a, b) { return Math.pow(a, b); }, 1004 | "==": function(a, b) { return a == b; }, 1005 | "!=": function(a, b) { return a != b; }, 1006 | ">": function(a, b) { return a > b; }, 1007 | "<": function(a, b) { return a < b; }, 1008 | ">=": function(a, b) { return a >= b; }, 1009 | "<=": function(a, b) { return a <= b; } 1010 | }; 1011 | 1012 | var runtimeOps = { 1013 | "+": "add", 1014 | "-": "remove", 1015 | "*": "multiplicate", 1016 | "/": "divide", 1017 | "%": "mod", 1018 | "..": function(a, b) 1019 | { 1020 | throwError("Operator '..' is not supported for runtime variables", expr.loc); 1021 | }, 1022 | "^": function(a, b) 1023 | { 1024 | throwError("Unsupported operator '^' use the math function 'pow' instead", expr.loc); 1025 | }, 1026 | "==": function(a, b) 1027 | { 1028 | checkOperator(a, "isExact", operator, expr.loc); 1029 | return a.isExact(b); 1030 | }, 1031 | "~=": function(a, b) 1032 | { 1033 | checkOperator(a, "isExact", operator, expr.loc); 1034 | var label = nextName("not"); 1035 | base.addLabel(label); 1036 | command(a.isExact(b)); 1037 | return "testforblock %" + label + ":diff% minecraft:chain_command_block -1 {SuccessCount:0}"; 1038 | }, 1039 | ">": function(a, b) 1040 | { 1041 | checkOperator(a, "isBetweenEx", operator, expr.loc); 1042 | return a.isBetweenEx(b, undefined); 1043 | }, 1044 | "<": function(a, b) 1045 | { 1046 | checkOperator(a, "isBetweenEx", operator, expr.loc); 1047 | return a.isBetweenEx(undefined, b); 1048 | }, 1049 | ">=": function(a, b) 1050 | { 1051 | checkOperator(a, "isBetween", operator, expr.loc); 1052 | return a.isBetween(b, undefined); 1053 | }, 1054 | "<=": function(a, b) 1055 | { 1056 | checkOperator(a, "isBetween", operator, expr.loc); 1057 | return a.isBetween(undefined, b); 1058 | } 1059 | }; 1060 | 1061 | if(typeof left != "object" && typeof right != "object") 1062 | { 1063 | return compileTimeOps[operator](left, right); 1064 | } 1065 | else if(typeof right == "object" && (typeof left == "object" || noCommutative.indexOf(operator) != -1)) 1066 | { 1067 | var op = runtimeOps[operator]; 1068 | 1069 | if(typeof left != "object") 1070 | left = createRuntimeVar(left); 1071 | 1072 | checkOperator(left, "clone", "clone", expr.loc); 1073 | var clone = left.isClone ? left : left.clone(); 1074 | clone.isClone = true; 1075 | 1076 | if(typeof op == "string") 1077 | { 1078 | checkOperator(clone, op, operator, expr.loc); 1079 | clone[op](right); 1080 | return clone; 1081 | } 1082 | else 1083 | { 1084 | checkOperator(left, "remove", "-", expr.loc); 1085 | clone.remove(right); 1086 | return "/" + op(clone, 0); 1087 | } 1088 | } 1089 | else 1090 | { 1091 | var _left = typeof left == "object" ? left : right; 1092 | var _right = typeof right == "object" ? left : right; 1093 | 1094 | var op = runtimeOps[operator]; 1095 | if(typeof op == "string") 1096 | { 1097 | checkOperator(_left, "clone", "clone", expr.loc); 1098 | var clone = _left.isClone ? _left : _left.clone(); 1099 | clone.isClone = true; 1100 | 1101 | checkOperator(clone, op, operator, expr.loc); 1102 | clone[op](_right); 1103 | return clone; 1104 | } 1105 | else 1106 | { 1107 | return "/" + op(_left, _right); 1108 | } 1109 | } 1110 | }; 1111 | -------------------------------------------------------------------------------- /src/lib/Scope.js: -------------------------------------------------------------------------------- 1 | function Scope() 2 | { 3 | this.stack = [{}]; 4 | } 5 | 6 | Scope.prototype.increase = function(val) 7 | { 8 | this.stack.push(val || {}); 9 | }; 10 | 11 | Scope.prototype.decrease = function() 12 | { 13 | if(this.stack.length == 1) 14 | throw "cannot go below global in scope"; 15 | 16 | return this.stack.splice(this.stack.length - 1, 1)[0]; 17 | }; 18 | 19 | Scope.prototype.current = function() 20 | { 21 | return this.stack[this.stack.length - 1]; 22 | }; 23 | 24 | Scope.prototype.set = function(key, val) 25 | { 26 | this.current()[key] = val; 27 | }; 28 | 29 | Scope.prototype.get = function(key) 30 | { 31 | for(var i = this.stack.length - 1; i >= 0; i--) 32 | { 33 | if(this.stack[i].hasOwnProperty(key)) 34 | { 35 | return this.stack[i][key]; 36 | } 37 | } 38 | }; 39 | 40 | Scope.prototype.save = function() 41 | { 42 | return this.stack.slice(0); 43 | }; 44 | 45 | Scope.prototype.load = function(stack) 46 | { 47 | this.stack = stack; 48 | }; 49 | 50 | Scope.prototype.setGlobal = function(key, val) 51 | { 52 | this.stack[0][key] = val; 53 | }; 54 | 55 | module.exports = new Scope(); 56 | -------------------------------------------------------------------------------- /src/lib/base.js: -------------------------------------------------------------------------------- 1 | var optimize = require("./optimize.js"); 2 | var scoreName = require("./types.js").Integer.scoreName; 3 | 4 | var functions = {}; 5 | 6 | var currBlocks = []; 7 | var currLabel; 8 | var blockCache = {}; 9 | var createLabel = []; 10 | 11 | exports.command = GLOBAL.command = function command(cmd, conditional) 12 | { 13 | conditional = !!conditional; 14 | var data = {type: "command", command: cmd, conditional: conditional, label: createLabel.slice(0)}; 15 | currBlocks.push(data); 16 | 17 | if(createLabel.length > 0) 18 | createLabel = []; 19 | }; 20 | 21 | exports.unshiftCommand = function unshiftCommand(cmd, conditional) 22 | { 23 | conditional = !!conditional; 24 | var data = {type: "command", command: cmd, conditional: conditional, label: createLabel.slice(0)}; 25 | currBlocks.unshift(data); 26 | }; 27 | 28 | exports.block = GLOBAL.block = function block(tagName, data) 29 | { 30 | currBlocks.push({type: "block", tagName: tagName, data: data || 0}); 31 | }; 32 | 33 | exports.jump = function jump(label, conditional) 34 | { 35 | command("setblock %" + label + ":jmp% command_block 0 replace {Command:\"setblock ~ ~ ~ air\",auto:1b}", conditional); 36 | }; 37 | 38 | exports.rjump = function rjump(label, conditional) 39 | { 40 | command("summon ArmorStand %3:jmp% {NoGravity:1,Tags:[\"stack\"],CustomName:\"{0}\"}".format(label)); 41 | command("scoreboard players add @e[type=ArmorStand,tag=stack] {0} 1".format(scoreName)); 42 | exports.jump(label, conditional); 43 | block(options.splitterBlock); 44 | }; 45 | 46 | exports.ret = function ret() 47 | { 48 | command("execute @e[type=ArmorStand,tag=stack,score_{0}=1] ".format(scoreName) + 49 | "~ ~ ~ setblock ~ ~ ~ command_block 0 replace {Command:\"setblock ~ ~ ~ air\",auto:1b}"); 50 | command("kill @e[type=ArmorStand,tag=stack,score_{0}=1]".format(scoreName)); 51 | command("scoreboard players remove @e[type=ArmorStand,tag=stack] {0} 1".format(scoreName)); 52 | block(options.splitterBlock); 53 | }; 54 | 55 | exports.addLabel = function addLabel(name) 56 | { 57 | createLabel.push(name); 58 | }; 59 | 60 | exports.addFunction = function(label, fn) 61 | { 62 | if(functions[label] == fn) 63 | return; 64 | else if(functions[label]) 65 | throw "cannot use label " + label + " twice"; 66 | 67 | var _blocks = currBlocks; 68 | var _createLabel = createLabel; 69 | currBlocks = []; 70 | createLabel = []; 71 | 72 | exports.addLabel(label); 73 | fn(); 74 | 75 | functions[label] = currBlocks; 76 | currBlocks = _blocks; 77 | createLabel = _createLabel; 78 | }; 79 | 80 | exports.reset = function() 81 | { 82 | functions = {}; 83 | 84 | currBlocks = []; 85 | currLabel; 86 | blockCache = {}; 87 | createLabel = []; 88 | 89 | x = options.x; 90 | y = options.y; 91 | z = options.z; 92 | maxLength = options.length; 93 | direction = 5; 94 | nextDirection; 95 | curr = 1; 96 | 97 | label = exports.jmpLabel = {}; 98 | cmdBlocks = []; 99 | outputBlocks = []; 100 | }; 101 | 102 | /*exports.newFunction = function(label) 103 | { 104 | functions[currLabel] = currBlocks; 105 | currBlocks = []; 106 | 107 | exports.addLabel(label); 108 | currLabel = label; 109 | }*/ 110 | 111 | var x = options.x; 112 | var y = options.y; 113 | var z = options.z; 114 | var maxLength = options.length; 115 | var direction = 5; 116 | var nextDirection; 117 | var curr = 1; 118 | function move() 119 | { 120 | if(direction == 5) 121 | x++; 122 | else if(direction == 4) 123 | x--; 124 | else if(direction == 3) 125 | z++; 126 | 127 | curr++; 128 | if(curr >= maxLength) 129 | { 130 | if(direction == 5) 131 | { 132 | direction = 3; 133 | nextDirection = 4; 134 | } 135 | else if(direction == 4) 136 | { 137 | direction = 3; 138 | nextDirection = 5; 139 | } 140 | else if(direction == 3) 141 | { 142 | direction = nextDirection; 143 | curr = 1; 144 | } 145 | } 146 | } 147 | 148 | var label = exports.jmpLabel = {}; 149 | var cmdBlocks = []; 150 | var outputBlocks = []; 151 | function format(cmd, index) 152 | { 153 | var reg = /%[a-zA-Z0-9-\+_]+:[a-zA-Z]+%/; 154 | while(reg.test(cmd)) 155 | { 156 | var result = reg.exec(cmd)[0]; 157 | var split = result.slice(1, -1).split(":"); 158 | var descriptor = split[0]; 159 | var query = split[1]; 160 | 161 | var block; 162 | if(!isNaN(parseInt(descriptor))) 163 | block = cmdBlocks[index + parseInt(descriptor)]; 164 | else if(typeof label[descriptor] != "undefined") 165 | block = label[descriptor]; 166 | else 167 | break; //throw "invalid formatting symbol " + result; 168 | 169 | var diffX = block.x - cmdBlocks[index].x; 170 | var diffY = block.y - cmdBlocks[index].y; 171 | var diffZ = block.z - cmdBlocks[index].z; 172 | block.diff = "~" + diffX + " ~" + diffY + " ~" + diffZ; 173 | block.diffR = "~" + (-1 * diffX) + " ~" + (-1 * diffY) + " ~" + (-1 * diffZ); 174 | block.jmp = "~" + diffX + " ~" + (diffY + 1) + " ~" + diffZ; 175 | 176 | cmd = cmd.replace(result, block[query].toString()); 177 | } 178 | return cmd; 179 | } 180 | 181 | exports.output = function output(outputHandler) 182 | { 183 | var _functions = [optimize.removeDoubleSplit(currBlocks)]; 184 | for(var key in functions) 185 | _functions.push(optimize.removeDoubleSplit(functions[key])); 186 | 187 | for(var i0 = 0; i0 < _functions.length; i0++) 188 | { 189 | var blocks = _functions[i0]; 190 | for(var i = 0; i < blocks.length; i++) 191 | { 192 | if(blocks[i].type == "command") 193 | { 194 | if(blocks[i + 1] && blocks[i + 1].conditional) //conditional commandblocks cannot be in corners 195 | { 196 | var count = 0; 197 | for(var ii = i + 1; blocks[ii] && blocks[ii].conditional; ii++) 198 | { 199 | count++; 200 | } 201 | 202 | if(curr + count >= maxLength) 203 | { 204 | while(curr != 1) 205 | { 206 | outputBlocks.push({x: x, y: y, z: z, tagName: "chain_command_block", data: direction}); 207 | move(); 208 | } 209 | } 210 | } 211 | 212 | 213 | var blockData = blocks[i].conditional ? direction + 8 : direction; 214 | cmdBlocks.push({x: x, y: y, z: z, data: blockData, command: blocks[i].command}); 215 | 216 | var _label = blocks[i].label; 217 | for(var ii = 0; ii < _label.length; ii++) 218 | { 219 | label[_label[ii]] = {x: x, y: y, z: z}; 220 | } 221 | } 222 | else if(blocks[i].type == "block") 223 | { 224 | outputBlocks.push({x: x, y: y, z: z, tagName: blocks[i].tagName, data: blocks[i].data}); 225 | } 226 | move(); 227 | } 228 | 229 | outputBlocks.push({x: x, y: y, z: z, tagName: options.splitterBlock, data: 0}); 230 | move(); 231 | } 232 | 233 | for(var i = 0; i < createLabel.length; i++) 234 | label[createLabel[i]] = {x: x, y: y, z: z}; 235 | 236 | for(var i = 0; i < cmdBlocks.length; i++) 237 | { 238 | cmdBlocks[i].command = format(cmdBlocks[i].command, i, cmdBlocks); 239 | } 240 | 241 | outputHandler(outputBlocks, cmdBlocks); 242 | }; 243 | -------------------------------------------------------------------------------- /src/lib/baselib.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | var fs = require("fs"); 3 | var vm = require("vm"); 4 | 5 | var types = require("./types.js"); 6 | var scope = require("./Scope.js"); 7 | var base = require("./base.js"); 8 | GLOBAL.scope = scope; 9 | 10 | var parser = require("./../luaparse.js"); 11 | var compile = require("./../compiler.js"); 12 | 13 | var cache = []; 14 | var stdlib = {}; 15 | exports.srcPath = ""; 16 | 17 | exports.import = function(name, isMain) 18 | { 19 | luaImport(name); 20 | 21 | if(isMain) 22 | { 23 | var Integer = types.Integer; 24 | for(var i = 0; i < Integer.statics.length; i++) 25 | base.unshiftCommand(["scoreboard players set", "static" + Integer.statics[i], Integer.scoreName, Integer.statics[i]].join(" ")); 26 | 27 | base.unshiftCommand("scoreboard objectives add " + Integer.scoreName + " dummy MoonCraft Variables"); 28 | 29 | if(types.Table.used) 30 | { 31 | base.unshiftCommand("scoreboard objectives add " + types.Table.indexScoreName + " dummy MoonCraft Table"); 32 | base.unshiftCommand("scoreboard objectives add " + types.Table.tmpScoreName + " dummy MoonCraft temp"); 33 | } 34 | } 35 | }; 36 | 37 | exports.reset = function() 38 | { 39 | cache = []; 40 | }; 41 | 42 | (function() 43 | { 44 | var stdlibPath = path.join(__dirname, "../../stdlib/"); 45 | var files = fs.readdirSync(stdlibPath); //had trouble with async version 46 | 47 | for(var i = 0; i < files.length; i++) 48 | { 49 | var ext = path.extname(files[i]); 50 | var name = path.basename(files[i], ext); 51 | 52 | if(ext == ".js" || ext == ".lua") 53 | stdlib[name] = path.join(stdlibPath, files[i]); 54 | } 55 | })(); 56 | 57 | scope.set("command", require("./base.js").command); 58 | 59 | scope.set("import", luaImport); 60 | function luaImport(name) 61 | { 62 | var file; 63 | if(stdlib.hasOwnProperty(name)) 64 | { 65 | file = stdlib[name]; 66 | } 67 | else 68 | { 69 | if(path.isAbsolute(name)) 70 | file = name; 71 | else 72 | file = path.resolve(path.join(exports.srcPath, name)); 73 | 74 | if(!fs.existsSync(file)) 75 | throw "cannot import module " + name + ", file " + file + " does not exist"; 76 | } 77 | 78 | if(cache.indexOf(file) != -1) 79 | return; 80 | cache.push(file); 81 | 82 | var ext = path.extname(file); 83 | 84 | if(ext == ".lua") 85 | { 86 | var oldStack = scope.save(); 87 | scope.load([scope.stack[0]]); 88 | scope.increase(); 89 | 90 | var _srcPath = exports.srcPath; 91 | exports.srcPath = path.dirname(file); 92 | var _file = compile.file; 93 | compile.file = file; 94 | 95 | try 96 | { 97 | var src = fs.readFileSync(file).toString(); 98 | var ast = parser.parse(src, {locations: true}); 99 | } 100 | catch(e) 101 | { 102 | console.log("in file " + file); 103 | throw e; 104 | } 105 | compile(ast, path.dirname(file), false); 106 | 107 | exports.srcPath = _srcPath; 108 | compile.file = _file; 109 | 110 | scope.load(oldStack); 111 | } 112 | else if(ext == ".js") 113 | { 114 | var obj = require(file); 115 | for(var key in obj) 116 | { 117 | scope.setGlobal(key, obj[key]); 118 | } 119 | } 120 | else 121 | { 122 | throw "cannot import module " + name + ", unknown file extension " + ext; 123 | } 124 | } 125 | 126 | scope.set("js_eval", function(code) 127 | { 128 | var context = {}; 129 | for(var i = 0; i < scope.stack.length; i++) 130 | { 131 | for(var key in scope.stack[i]) 132 | context[key] = scope.stack[i][key]; 133 | } 134 | 135 | context = vm.createContext(context); 136 | return vm.runInContext(code, context); 137 | }); 138 | 139 | scope.set("boolean", function(val, name) 140 | { 141 | return new types.Boolean(val || false, name); 142 | }); 143 | 144 | scope.set("int", function(val, name) 145 | { 146 | return new types.Integer(val || 0, name); 147 | }); 148 | 149 | scope.set("float", function(val, name) 150 | { 151 | return new types.Float(val || 0, name); 152 | }); 153 | 154 | scope.set("string", function(val, name) 155 | { 156 | return new types.String(val || "", name); 157 | }); 158 | 159 | scope.set("score", function(selector, objective) 160 | { 161 | return new types.Score(selector, objective); 162 | }); 163 | 164 | scope.set("type", function(val) 165 | { 166 | return val.constructor.name; 167 | }); 168 | 169 | scope.set("table_getn", function(table) 170 | { 171 | return table.length; 172 | }); 173 | 174 | scope.set("table_maxn", function(table) 175 | { 176 | return table.maxn; 177 | }); 178 | 179 | scope.set("table_slice", function(table, start, end) 180 | { 181 | table.slice(start, end); 182 | }); 183 | 184 | scope.set("table_insert", function(table, index, value) 185 | { 186 | table.insert(index, value); 187 | }); 188 | 189 | scope.set("table_remove", function(table, index) 190 | { 191 | table.remove(index); 192 | }); 193 | 194 | scope.set("OBJECTIVE_NAME", types.Integer.scoreName); 195 | -------------------------------------------------------------------------------- /src/lib/export.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var types = require("./types.js"); 3 | var base = require("./base.js"); 4 | var nextName = require("./naming.js"); 5 | 6 | scope.setGlobal("__extern_naming", function(data) 7 | { 8 | var data = JSON.parse(data); 9 | for(var key in data) 10 | nextName.names[key] = nextName.names[key] + data[key] || data[key]; 11 | }); 12 | 13 | scope.setGlobal("__extern", function(name, pos, args, ret) 14 | { 15 | base.jmpLabel[name] = {x: pos[0], y: pos[1], z: pos[2]}; 16 | 17 | scope.setGlobal(name, function() 18 | { 19 | if(args.length != arguments.length) 20 | throw "function {0} requires {1} arguments not {2}".format(name, args.length, arguments.length); 21 | 22 | var _ret = []; 23 | for(var i = 0; i < ret.length; i++) 24 | { 25 | var ctor = types[ret[i][0]]; 26 | var _name = ret[i][1]; 27 | 28 | _ret[i] = new ctor(0, _name); 29 | } 30 | 31 | for(var i = 0; i < args.length; i++) 32 | { 33 | var ctor = types[args[i][0]]; 34 | var _name = args[i][1]; 35 | 36 | new ctor(arguments[i], _name); 37 | } 38 | 39 | base.rjump(name); 40 | return _ret; 41 | }); 42 | }); 43 | 44 | scope.setGlobal("__extern_var", function(name, type, privateName) 45 | { 46 | var val = new types[type](0, privateName, true); 47 | val.__imported = true; 48 | scope.setGlobal(name, val); 49 | }); 50 | 51 | module.exports = function(file) 52 | { 53 | var globals = scope.stack[0]; 54 | var namingData = nextName.names; 55 | var jmpLabel = base.jmpLabel; 56 | 57 | var exportCode = "-- auto generated code, you should probably not change anything"; 58 | 59 | exportCode += "\n__extern_naming({0})".format(JSON.stringify(JSON.stringify(namingData))); 60 | 61 | for(var key in globals) 62 | { 63 | if(typeof globals[key] == "function" && globals[key].funcName) 64 | { 65 | var name = JSON.stringify(globals[key].funcName); 66 | var typeSignature = tabelify(globals[key].typeSignature); 67 | var returnSignature = tabelify(globals[key].returnSignature); 68 | 69 | var pos = jmpLabel[key]; 70 | var _pos = "{{0}, {1}, {2}}".format(pos.x, pos.y, pos.z); 71 | 72 | exportCode += "\n__extern({0}, {1}, {2}, {3})".format(name, _pos, typeSignature, returnSignature); 73 | } 74 | else if(typeof globals[key] == "object" && !globals[key].__imported) 75 | { 76 | var name = JSON.stringify(key); 77 | var type = JSON.stringify(globals[key].constructor.name); 78 | var privateName = JSON.stringify(globals[key].name); 79 | 80 | exportCode += "\n__extern_var({0}, {1}, {2})".format(name, type, privateName); 81 | } 82 | } 83 | 84 | fs.writeFileSync(file, exportCode); 85 | } 86 | 87 | function tabelify(args) 88 | { 89 | var entries = []; 90 | for(var i = 0; i < args.length; i++) 91 | { 92 | var ctorName = JSON.stringify(args[i].constructor.name); 93 | var name = JSON.stringify(args[i].selector || args[i].name); 94 | entries.push("{{0}, {1}}".format(ctorName, name)); 95 | } 96 | return "{" + entries.join(", ") + "}"; 97 | } 98 | -------------------------------------------------------------------------------- /src/lib/naming.js: -------------------------------------------------------------------------------- 1 | var func = function(name) 2 | { 3 | func.names[name] = func.names[name] + 1 || 0; 4 | return name + "_" + func.names[name]; 5 | }; 6 | func.names = {}; 7 | 8 | module.exports = func; 9 | -------------------------------------------------------------------------------- /src/lib/optimize.js: -------------------------------------------------------------------------------- 1 | var scope = require("./Scope.js"); 2 | 3 | exports.selfAssign = function(left, val) // a = a + b --> a += b 4 | { 5 | var leftSupported = ["+", "-", "*", "/", "%"]; 6 | var rightSupported = ["+", "-", "*"]; 7 | 8 | var varName = left.name; 9 | if(val.type == "BinaryExpression") 10 | { 11 | var op = val.operator; 12 | 13 | if(val.left.type == "Identifier" && val.left.name == varName && leftSupported.indexOf(op) != -1) 14 | return {operator: op, argument: val.right}; 15 | else if(val.right.type == "Identifier" && val.right.name == varName && rightSupported.indexOf(op) != -1) 16 | return {operator: op, argument: val.left}; 17 | } 18 | }; 19 | 20 | exports.removeDeadEnds = function(stmtList) 21 | { 22 | var endExpressions = ["ReturnStatement", "BreakStatement"]; 23 | 24 | for(var i = 0; i < stmtList.length; i++) 25 | { 26 | var type = stmtList[i].type; 27 | if(endExpressions.indexOf(stmtList[i].type) != -1) 28 | return stmtList.slice(0, i + 1); 29 | } 30 | return stmtList; 31 | }; 32 | 33 | exports.garbageCollect = function() 34 | { 35 | var currScope = scope.current(); 36 | 37 | for(var key in currScope) 38 | { 39 | if(currScope[key].clean) 40 | currScope[key].clean(); 41 | } 42 | }; 43 | 44 | exports.removeDoubleSplit = function(blocks) 45 | { 46 | var sBlock = options.splitterBlock; 47 | for(var i = 0; i < blocks.length; i++) 48 | { 49 | if(blocks[i].tagName == sBlock && (blocks[i + 1] || {}).tagName == sBlock) 50 | { 51 | blocks.splice(i, 1); 52 | i--; 53 | } 54 | } 55 | 56 | if(blocks[blocks.length - 1].tagName == sBlock) 57 | blocks.splice(blocks.length - 1, 1); 58 | 59 | return blocks; 60 | }; 61 | -------------------------------------------------------------------------------- /src/lib/types.js: -------------------------------------------------------------------------------- 1 | exports.Integer = require("./../types/Integer.js"); 2 | exports.Boolean = require("./../types/Boolean.js"); 3 | exports.Float = require("./../types/Float.js"); 4 | exports.String = require("./../types/String.js"); 5 | exports.Score = require("./../types/Score.js"); 6 | exports.Table = require("./../types/Table.js"); 7 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | GLOBAL.options = {}; 2 | 3 | var fs = require("fs"); 4 | var path = require("path"); 5 | 6 | String.prototype.format = function() 7 | { 8 | var val = this; 9 | for(var i = 0; i < arguments.length; i++) 10 | val = val.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]); 11 | return val; 12 | }; 13 | 14 | try 15 | { 16 | var args = process.argv.slice(2); 17 | var files = []; 18 | 19 | for(var i = 0; i < args.length; i++) 20 | { 21 | if(args[i][0] != "-") 22 | { 23 | files.push(args[i]); 24 | } 25 | else 26 | { 27 | var arg = args[i][1] == "-" ? args[i].substr(2) : args[i][1]; 28 | 29 | i++; 30 | var val = true; 31 | 32 | if(args[i][0] == "-") 33 | i--; 34 | else 35 | val = args[i]; 36 | 37 | options[arg] = val; 38 | } 39 | } 40 | 41 | var config = {}; 42 | if(fs.existsSync("./config.json")) 43 | config = JSON.parse(fs.readFileSync("./config.json")); 44 | 45 | options.output = options.output || config.output || "rcon"; 46 | options.splitterBlock = options.splitterBlock || options.split || config.splitterBlock || "air"; 47 | options.x = options.x || config.x || 0; 48 | options.y = options.y || config.y || 0; 49 | options.z = options.z || config.z || 0; 50 | options.length = options.length || options.l || config.length || 20; 51 | options.rcon_ip = options.rcon_ip || config.rcon_ip || "localhost"; 52 | options.rcon_port = options.rcon_port || config.rcon_port || 25575; 53 | options.rcon_password = options.rcon_password || options.rcon_pw || config.rcon_password || "hunter2"; 54 | options.schematic_file = options.schematic_file || options.file || config.schematic_file || "output.schematic"; 55 | options.debug = options.debug || config.debug || false; 56 | options.export = options.export || config.export || false; 57 | 58 | var output = require("./output/" + options.output + ".js"); 59 | var parser = require("./luaparse.js"); 60 | var base = require("./lib/base.js"); 61 | var baseLib = require("./lib/baselib.js"); 62 | var compile = require("./compiler.js"); 63 | var luaExport = require("./lib/export.js"); 64 | 65 | if(files.length == 0) 66 | throw "No input files specified"; 67 | 68 | baseLib.srcPath = process.cwd(); 69 | 70 | for(var i = 0; i < files.length; i++) 71 | { 72 | baseLib.import(files[i], i + 1 == files.length); 73 | } 74 | 75 | command("__DONE__"); 76 | 77 | base.output(function(blocks, cmdBlocks) 78 | { 79 | if(options.export) 80 | luaExport(options.export); 81 | 82 | console.log("Code compiled to {0} command and {1} other blocks".format(cmdBlocks.length, blocks.length)); 83 | output(blocks, cmdBlocks); 84 | }); 85 | } 86 | catch(e) 87 | { 88 | if(options.debug) 89 | throw e; 90 | 91 | var err = typeof e == "undefined" ? "Unknown error occured" : e.toString(); 92 | console.log(err); 93 | process.exit(1); 94 | } 95 | -------------------------------------------------------------------------------- /src/output/itemIds.json: -------------------------------------------------------------------------------- 1 | [{"type":0,"meta":0,"name":"Air","text_type":"air"},{"type":1,"meta":0,"name":"Stone","text_type":"stone"},{"type":1,"meta":1,"name":"Granite","text_type":"stone"},{"type":1,"meta":2,"name":"Polished Granite","text_type":"stone"},{"type":1,"meta":3,"name":"Diorite","text_type":"stone"},{"type":1,"meta":4,"name":"Polished Diorite","text_type":"stone"},{"type":1,"meta":5,"name":"Andesite","text_type":"stone"},{"type":1,"meta":6,"name":"Polished Andesite","text_type":"stone"},{"type":2,"meta":0,"name":"Grass","text_type":"grass"},{"type":3,"meta":0,"name":"Dirt","text_type":"dirt"},{"type":3,"meta":1,"name":"Coarse Dirt","text_type":"dirt"},{"type":3,"meta":2,"name":"Podzol","text_type":"dirt"},{"type":4,"meta":0,"name":"Cobblestone","text_type":"cobblestone"},{"type":5,"meta":0,"name":"Oak Wood Plank","text_type":"planks"},{"type":5,"meta":1,"name":"Spruce Wood Plank","text_type":"planks"},{"type":5,"meta":2,"name":"Birch Wood Plank","text_type":"planks"},{"type":5,"meta":3,"name":"Jungle Wood Plank","text_type":"planks"},{"type":5,"meta":4,"name":"Acacia Wood Plank","text_type":"planks"},{"type":5,"meta":5,"name":"Dark Oak Wood Plank","text_type":"planks"},{"type":6,"meta":0,"name":"Oak Sapling","text_type":"sapling"},{"type":6,"meta":1,"name":"Spruce Sapling","text_type":"sapling"},{"type":6,"meta":2,"name":"Birch Sapling","text_type":"sapling"},{"type":6,"meta":3,"name":"Jungle Sapling","text_type":"sapling"},{"type":6,"meta":4,"name":"Acacia Sapling","text_type":"sapling"},{"type":6,"meta":5,"name":"Dark Oak Sapling","text_type":"sapling"},{"type":7,"meta":0,"name":"Bedrock","text_type":"bedrock"},{"type":8,"meta":0,"name":"Flowing Water","text_type":"flowing_water"},{"type":9,"meta":0,"name":"Still Water","text_type":"water"},{"type":10,"meta":0,"name":"Flowing Lava","text_type":"flowing_lava"},{"type":11,"meta":0,"name":"Still Lava","text_type":"lava"},{"type":12,"meta":0,"name":"Sand","text_type":"sand"},{"type":12,"meta":1,"name":"Red Sand","text_type":"sand"},{"type":13,"meta":0,"name":"Gravel","text_type":"gravel"},{"type":14,"meta":0,"name":"Gold Ore","text_type":"gold_ore"},{"type":15,"meta":0,"name":"Iron Ore","text_type":"iron_ore"},{"type":16,"meta":0,"name":"Coal Ore","text_type":"coal_ore"},{"type":17,"meta":0,"name":"Oak Wood","text_type":"log"},{"type":17,"meta":1,"name":"Spruce Wood","text_type":"log"},{"type":17,"meta":2,"name":"Birch Wood","text_type":"log"},{"type":17,"meta":3,"name":"Jungle Wood","text_type":"log"},{"type":18,"meta":0,"name":"Oak Leaves","text_type":"leaves"},{"type":18,"meta":1,"name":"Spruce Leaves","text_type":"leaves"},{"type":18,"meta":2,"name":"Birch Leaves","text_type":"leaves"},{"type":18,"meta":3,"name":"Jungle Leaves","text_type":"leaves"},{"type":19,"meta":0,"name":"Sponge","text_type":"sponge"},{"type":19,"meta":1,"name":"Wet Sponge","text_type":"sponge"},{"type":20,"meta":0,"name":"Glass","text_type":"glass"},{"type":21,"meta":0,"name":"Lapis Lazuli Ore","text_type":"lapis_ore"},{"type":22,"meta":0,"name":"Lapis Lazuli Block","text_type":"lapis_block"},{"type":23,"meta":0,"name":"Dispenser","text_type":"dispenser"},{"type":24,"meta":0,"name":"Sandstone","text_type":"sandstone"},{"type":24,"meta":1,"name":"Chiseled Sandstone","text_type":"sandstone"},{"type":24,"meta":2,"name":"Smooth Sandstone","text_type":"sandstone"},{"type":25,"meta":0,"name":"Note Block","text_type":"noteblock"},{"type":26,"meta":0,"name":"Bed","text_type":"bed"},{"type":27,"meta":0,"name":"Powered Rail","text_type":"golden_rail"},{"type":28,"meta":0,"name":"Detector Rail","text_type":"detector_rail"},{"type":29,"meta":0,"name":"Sticky Piston","text_type":"sticky_piston"},{"type":30,"meta":0,"name":"Cobweb","text_type":"web"},{"type":31,"meta":0,"name":"Dead Shrub","text_type":"tallgrass"},{"type":31,"meta":1,"name":"Grass","text_type":"tallgrass"},{"type":31,"meta":2,"name":"Fern","text_type":"tallgrass"},{"type":32,"meta":0,"name":"Dead Bush","text_type":"deadbush"},{"type":33,"meta":0,"name":"Piston","text_type":"piston"},{"type":34,"meta":0,"name":"Piston Head","text_type":"piston_head"},{"type":35,"meta":0,"name":"White Wool","text_type":"wool"},{"type":35,"meta":1,"name":"Orange Wool","text_type":"wool"},{"type":35,"meta":2,"name":"Magenta Wool","text_type":"wool"},{"type":35,"meta":3,"name":"Light Blue Wool","text_type":"wool"},{"type":35,"meta":4,"name":"Yellow Wool","text_type":"wool"},{"type":35,"meta":5,"name":"Lime Wool","text_type":"wool"},{"type":35,"meta":6,"name":"Pink Wool","text_type":"wool"},{"type":35,"meta":7,"name":"Gray Wool","text_type":"wool"},{"type":35,"meta":8,"name":"Light Gray Wool","text_type":"wool"},{"type":35,"meta":9,"name":"Cyan Wool","text_type":"wool"},{"type":35,"meta":10,"name":"Purple Wool","text_type":"wool"},{"type":35,"meta":11,"name":"Blue Wool","text_type":"wool"},{"type":35,"meta":12,"name":"Brown Wool","text_type":"wool"},{"type":35,"meta":13,"name":"Green Wool","text_type":"wool"},{"type":35,"meta":14,"name":"Red Wool","text_type":"wool"},{"type":35,"meta":15,"name":"Black Wool","text_type":"wool"},{"type":37,"meta":0,"name":"Dandelion","text_type":"yellow_flower"},{"type":38,"meta":0,"name":"Poppy","text_type":"red_flower"},{"type":38,"meta":1,"name":"Blue Orchid","text_type":"red_flower"},{"type":38,"meta":2,"name":"Allium","text_type":"red_flower"},{"type":38,"meta":3,"name":"Azure Bluet","text_type":"red_flower"},{"type":38,"meta":4,"name":"Red Tulip","text_type":"red_flower"},{"type":38,"meta":5,"name":"Orange Tulip","text_type":"red_flower"},{"type":38,"meta":6,"name":"White Tulip","text_type":"red_flower"},{"type":38,"meta":7,"name":"Pink Tulip","text_type":"red_flower"},{"type":38,"meta":8,"name":"Oxeye Daisy","text_type":"red_flower"},{"type":39,"meta":0,"name":"Brown Mushroom","text_type":"brown_mushroom"},{"type":40,"meta":0,"name":"Red Mushroom","text_type":"red_mushroom"},{"type":41,"meta":0,"name":"Gold Block","text_type":"gold_block"},{"type":42,"meta":0,"name":"Iron Block","text_type":"iron_block"},{"type":43,"meta":0,"name":"Double Stone Slab","text_type":"double_stone_slab"},{"type":43,"meta":1,"name":"Double Sandstone Slab","text_type":"double_stone_slab"},{"type":43,"meta":2,"name":"Double Wooden Slab","text_type":"double_stone_slab"},{"type":43,"meta":3,"name":"Double Cobblestone Slab","text_type":"double_stone_slab"},{"type":43,"meta":4,"name":"Double Brick Slab","text_type":"double_stone_slab"},{"type":43,"meta":5,"name":"Double Stone Brick Slab","text_type":"double_stone_slab"},{"type":43,"meta":6,"name":"Double Nether Brick Slab","text_type":"double_stone_slab"},{"type":43,"meta":7,"name":"Double Quartz Slab","text_type":"double_stone_slab"},{"type":44,"meta":0,"name":"Stone Slab","text_type":"stone_slab"},{"type":44,"meta":1,"name":"Sandstone Slab","text_type":"stone_slab"},{"type":44,"meta":2,"name":"Wooden Slab","text_type":"stone_slab"},{"type":44,"meta":3,"name":"Cobblestone Slab","text_type":"stone_slab"},{"type":44,"meta":4,"name":"Brick Slab","text_type":"stone_slab"},{"type":44,"meta":5,"name":"Stone Brick Slab","text_type":"stone_slab"},{"type":44,"meta":6,"name":"Nether Brick Slab","text_type":"stone_slab"},{"type":44,"meta":7,"name":"Quartz Slab","text_type":"stone_slab"},{"type":45,"meta":0,"name":"Bricks","text_type":"brick_block"},{"type":46,"meta":0,"name":"TNT","text_type":"tnt"},{"type":47,"meta":0,"name":"Bookshelf","text_type":"bookshelf"},{"type":48,"meta":0,"name":"Moss Stone","text_type":"mossy_cobblestone"},{"type":49,"meta":0,"name":"Obsidian","text_type":"obsidian"},{"type":50,"meta":0,"name":"Torch","text_type":"torch"},{"type":51,"meta":0,"name":"Fire","text_type":"fire"},{"type":52,"meta":0,"name":"Monster Spawner","text_type":"mob_spawner"},{"type":53,"meta":0,"name":"Oak Wood Stairs","text_type":"oak_stairs"},{"type":54,"meta":0,"name":"Chest","text_type":"chest"},{"type":55,"meta":0,"name":"Redstone Wire","text_type":"redstone_wire"},{"type":56,"meta":0,"name":"Diamond Ore","text_type":"diamond_ore"},{"type":57,"meta":0,"name":"Diamond Block","text_type":"diamond_block"},{"type":58,"meta":0,"name":"Crafting Table","text_type":"crafting_table"},{"type":59,"meta":0,"name":"Wheat Crops","text_type":"wheat"},{"type":60,"meta":0,"name":"Farmland","text_type":"farmland"},{"type":61,"meta":0,"name":"Furnace","text_type":"furnace"},{"type":62,"meta":0,"name":"Burning Furnace","text_type":"lit_furnace"},{"type":63,"meta":0,"name":"Standing Sign Block","text_type":"standing_sign"},{"type":64,"meta":0,"name":"Oak Door Block","text_type":"wooden_door"},{"type":65,"meta":0,"name":"Ladder","text_type":"ladder"},{"type":66,"meta":0,"name":"Rail","text_type":"rail"},{"type":67,"meta":0,"name":"Cobblestone Stairs","text_type":"stone_stairs"},{"type":68,"meta":0,"name":"Wall-mounted Sign Block","text_type":"wall_sign"},{"type":69,"meta":0,"name":"Lever","text_type":"lever"},{"type":70,"meta":0,"name":"Stone Pressure Plate","text_type":"stone_pressure_plate"},{"type":71,"meta":0,"name":"Iron Door Block","text_type":"iron_door"},{"type":72,"meta":0,"name":"Wooden Pressure Plate","text_type":"wooden_pressure_plate"},{"type":73,"meta":0,"name":"Redstone Ore","text_type":"redstone_ore"},{"type":74,"meta":0,"name":"Glowing Redstone Ore","text_type":"lit_redstone_ore"},{"type":75,"meta":0,"name":"Redstone Torch (off)","text_type":"unlit_redstone_torch"},{"type":76,"meta":0,"name":"Redstone Torch (on)","text_type":"redstone_torch"},{"type":77,"meta":0,"name":"Stone Button","text_type":"stone_button"},{"type":78,"meta":0,"name":"Snow","text_type":"snow_layer"},{"type":79,"meta":0,"name":"Ice","text_type":"ice"},{"type":80,"meta":0,"name":"Snow Block","text_type":"snow"},{"type":81,"meta":0,"name":"Cactus","text_type":"cactus"},{"type":82,"meta":0,"name":"Clay","text_type":"clay"},{"type":83,"meta":0,"name":"Sugar Canes","text_type":"reeds"},{"type":84,"meta":0,"name":"Jukebox","text_type":"jukebox"},{"type":85,"meta":0,"name":"Oak Fence","text_type":"fence"},{"type":86,"meta":0,"name":"Pumpkin","text_type":"pumpkin"},{"type":87,"meta":0,"name":"Netherrack","text_type":"netherrack"},{"type":88,"meta":0,"name":"Soul Sand","text_type":"soul_sand"},{"type":89,"meta":0,"name":"Glowstone","text_type":"glowstone"},{"type":90,"meta":0,"name":"Nether Portal","text_type":"portal"},{"type":91,"meta":0,"name":"Jack o'Lantern","text_type":"lit_pumpkin"},{"type":92,"meta":0,"name":"Cake Block","text_type":"cake"},{"type":93,"meta":0,"name":"Redstone Repeater Block (off)","text_type":"unpowered_repeater"},{"type":94,"meta":0,"name":"Redstone Repeater Block (on)","text_type":"powered_repeater"},{"type":95,"meta":0,"name":"White Stained Glass","text_type":"stained_glass"},{"type":95,"meta":1,"name":"Orange Stained Glass","text_type":"stained_glass"},{"type":95,"meta":2,"name":"Magenta Stained Glass","text_type":"stained_glass"},{"type":95,"meta":3,"name":"Light Blue Stained Glass","text_type":"stained_glass"},{"type":95,"meta":4,"name":"Yellow Stained Glass","text_type":"stained_glass"},{"type":95,"meta":5,"name":"Lime Stained Glass","text_type":"stained_glass"},{"type":95,"meta":6,"name":"Pink Stained Glass","text_type":"stained_glass"},{"type":95,"meta":7,"name":"Gray Stained Glass","text_type":"stained_glass"},{"type":95,"meta":8,"name":"Light Gray Stained Glass","text_type":"stained_glass"},{"type":95,"meta":9,"name":"Cyan Stained Glass","text_type":"stained_glass"},{"type":95,"meta":10,"name":"Purple Stained Glass","text_type":"stained_glass"},{"type":95,"meta":11,"name":"Blue Stained Glass","text_type":"stained_glass"},{"type":95,"meta":12,"name":"Brown Stained Glass","text_type":"stained_glass"},{"type":95,"meta":13,"name":"Green Stained Glass","text_type":"stained_glass"},{"type":95,"meta":14,"name":"Red Stained Glass","text_type":"stained_glass"},{"type":95,"meta":15,"name":"Black Stained Glass","text_type":"stained_glass"},{"type":96,"meta":0,"name":"Wooden Trapdoor","text_type":"trapdoor"},{"type":97,"meta":0,"name":"Stone Monster Egg","text_type":"monster_egg"},{"type":97,"meta":1,"name":"Cobblestone Monster Egg","text_type":"monster_egg"},{"type":97,"meta":2,"name":"Stone Brick Monster Egg","text_type":"monster_egg"},{"type":97,"meta":3,"name":"Mossy Stone Brick Monster Egg","text_type":"monster_egg"},{"type":97,"meta":4,"name":"Cracked Stone Brick Monster Egg","text_type":"monster_egg"},{"type":97,"meta":5,"name":"Chiseled Stone Brick Monster Egg","text_type":"monster_egg"},{"type":98,"meta":0,"name":"Stone Bricks","text_type":"stonebrick"},{"type":98,"meta":1,"name":"Mossy Stone Bricks","text_type":"stonebrick"},{"type":98,"meta":2,"name":"Cracked Stone Bricks","text_type":"stonebrick"},{"type":98,"meta":3,"name":"Chiseled Stone Bricks","text_type":"stonebrick"},{"type":99,"meta":0,"name":"Brown Mushroom Block","text_type":"brown_mushroom_block"},{"type":100,"meta":0,"name":"Red Mushroom Block","text_type":"red_mushroom_block"},{"type":101,"meta":0,"name":"Iron Bars","text_type":"iron_bars"},{"type":102,"meta":0,"name":"Glass Pane","text_type":"glass_pane"},{"type":103,"meta":0,"name":"Melon Block","text_type":"melon_block"},{"type":104,"meta":0,"name":"Pumpkin Stem","text_type":"pumpkin_stem"},{"type":105,"meta":0,"name":"Melon Stem","text_type":"melon_stem"},{"type":106,"meta":0,"name":"Vines","text_type":"vine"},{"type":107,"meta":0,"name":"Oak Fence Gate","text_type":"fence_gate"},{"type":108,"meta":0,"name":"Brick Stairs","text_type":"brick_stairs"},{"type":109,"meta":0,"name":"Stone Brick Stairs","text_type":"stone_brick_stairs"},{"type":110,"meta":0,"name":"Mycelium","text_type":"mycelium"},{"type":111,"meta":0,"name":"Lily Pad","text_type":"waterlily"},{"type":112,"meta":0,"name":"Nether Brick","text_type":"nether_brick"},{"type":113,"meta":0,"name":"Nether Brick Fence","text_type":"nether_brick_fence"},{"type":114,"meta":0,"name":"Nether Brick Stairs","text_type":"nether_brick_stairs"},{"type":115,"meta":0,"name":"Nether Wart","text_type":"nether_wart"},{"type":116,"meta":0,"name":"Enchantment Table","text_type":"enchanting_table"},{"type":117,"meta":0,"name":"Brewing Stand","text_type":"brewing_stand"},{"type":118,"meta":0,"name":"Cauldron","text_type":"cauldron"},{"type":119,"meta":0,"name":"End Portal","text_type":"end_portal"},{"type":120,"meta":0,"name":"End Portal Frame","text_type":"end_portal_frame"},{"type":121,"meta":0,"name":"End Stone","text_type":"end_stone"},{"type":122,"meta":0,"name":"Dragon Egg","text_type":"dragon_egg"},{"type":123,"meta":0,"name":"Redstone Lamp (inactive)","text_type":"redstone_lamp"},{"type":124,"meta":0,"name":"Redstone Lamp (active)","text_type":"lit_redstone_lamp"},{"type":125,"meta":0,"name":"Double Oak Wood Slab","text_type":"double_wooden_slab"},{"type":125,"meta":1,"name":"Double Spruce Wood Slab","text_type":"double_wooden_slab"},{"type":125,"meta":2,"name":"Double Birch Wood Slab","text_type":"double_wooden_slab"},{"type":125,"meta":3,"name":"Double Jungle Wood Slab","text_type":"double_wooden_slab"},{"type":125,"meta":4,"name":"Double Acacia Wood Slab","text_type":"double_wooden_slab"},{"type":125,"meta":5,"name":"Double Dark Oak Wood Slab","text_type":"double_wooden_slab"},{"type":126,"meta":0,"name":"Oak Wood Slab","text_type":"wooden_slab"},{"type":126,"meta":1,"name":"Spruce Wood Slab","text_type":"wooden_slab"},{"type":126,"meta":2,"name":"Birch Wood Slab","text_type":"wooden_slab"},{"type":126,"meta":3,"name":"Jungle Wood Slab","text_type":"wooden_slab"},{"type":126,"meta":4,"name":"Acacia Wood Slab","text_type":"wooden_slab"},{"type":126,"meta":5,"name":"Dark Oak Wood Slab","text_type":"wooden_slab"},{"type":127,"meta":0,"name":"Cocoa","text_type":"cocoa"},{"type":128,"meta":0,"name":"Sandstone Stairs","text_type":"sandstone_stairs"},{"type":129,"meta":0,"name":"Emerald Ore","text_type":"emerald_ore"},{"type":130,"meta":0,"name":"Ender Chest","text_type":"ender_chest"},{"type":131,"meta":0,"name":"Tripwire Hook","text_type":"tripwire_hook"},{"type":132,"meta":0,"name":"Tripwire","text_type":"tripwire_hook"},{"type":133,"meta":0,"name":"Emerald Block","text_type":"emerald_block"},{"type":134,"meta":0,"name":"Spruce Wood Stairs","text_type":"spruce_stairs"},{"type":135,"meta":0,"name":"Birch Wood Stairs","text_type":"birch_stairs"},{"type":136,"meta":0,"name":"Jungle Wood Stairs","text_type":"jungle_stairs"},{"type":137,"meta":0,"name":"Command Block","text_type":"command_block"},{"type":138,"meta":0,"name":"Beacon","text_type":"beacon"},{"type":139,"meta":0,"name":"Cobblestone Wall","text_type":"cobblestone_wall"},{"type":139,"meta":1,"name":"Mossy Cobblestone Wall","text_type":"cobblestone_wall"},{"type":140,"meta":0,"name":"Flower Pot","text_type":"flower_pot"},{"type":141,"meta":0,"name":"Carrots","text_type":"carrots"},{"type":142,"meta":0,"name":"Potatoes","text_type":"potatoes"},{"type":143,"meta":0,"name":"Wooden Button","text_type":"wooden_button"},{"type":144,"meta":0,"name":"Mob Head","text_type":"skull"},{"type":145,"meta":0,"name":"Anvil","text_type":"anvil"},{"type":146,"meta":0,"name":"Trapped Chest","text_type":"trapped_chest"},{"type":147,"meta":0,"name":"Weighted Pressure Plate (light)","text_type":"light_weighted_pressure_plate"},{"type":148,"meta":0,"name":"Weighted Pressure Plate (heavy)","text_type":"heavy_weighted_pressure_plate"},{"type":149,"meta":0,"name":"Redstone Comparator (inactive)","text_type":"unpowered_comparator"},{"type":150,"meta":0,"name":"Redstone Comparator (active)","text_type":"powered_comparator"},{"type":151,"meta":0,"name":"Daylight Sensor","text_type":"daylight_detector"},{"type":152,"meta":0,"name":"Redstone Block","text_type":"redstone_block"},{"type":153,"meta":0,"name":"Nether Quartz Ore","text_type":"quartz_ore"},{"type":154,"meta":0,"name":"Hopper","text_type":"hopper"},{"type":155,"meta":0,"name":"Quartz Block","text_type":"quartz_block"},{"type":155,"meta":1,"name":"Chiseled Quartz Block","text_type":"quartz_block"},{"type":155,"meta":2,"name":"Pillar Quartz Block","text_type":"quartz_block"},{"type":156,"meta":0,"name":"Quartz Stairs","text_type":"quartz_stairs"},{"type":157,"meta":0,"name":"Activator Rail","text_type":"activator_rail"},{"type":158,"meta":0,"name":"Dropper","text_type":"dropper"},{"type":159,"meta":0,"name":"White Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":1,"name":"Orange Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":2,"name":"Magenta Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":3,"name":"Light Blue Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":4,"name":"Yellow Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":5,"name":"Lime Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":6,"name":"Pink Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":7,"name":"Gray Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":8,"name":"Light Gray Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":9,"name":"Cyan Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":10,"name":"Purple Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":11,"name":"Blue Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":12,"name":"Brown Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":13,"name":"Green Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":14,"name":"Red Stained Clay","text_type":"stained_hardened_clay"},{"type":159,"meta":15,"name":"Black Stained Clay","text_type":"stained_hardened_clay"},{"type":160,"meta":0,"name":"White Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":1,"name":"Orange Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":2,"name":"Magenta Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":3,"name":"Light Blue Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":4,"name":"Yellow Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":5,"name":"Lime Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":6,"name":"Pink Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":7,"name":"Gray Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":8,"name":"Light Gray Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":9,"name":"Cyan Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":10,"name":"Purple Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":11,"name":"Blue Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":12,"name":"Brown Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":13,"name":"Green Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":14,"name":"Red Stained Glass Pane","text_type":"stained_glass_pane"},{"type":160,"meta":15,"name":"Black Stained Glass Pane","text_type":"stained_glass_pane"},{"type":161,"meta":0,"name":"Acacia Leaves","text_type":"leaves2"},{"type":161,"meta":1,"name":"Dark Oak Leaves","text_type":"leaves2"},{"type":162,"meta":0,"name":"Acacia Wood","text_type":"log2"},{"type":162,"meta":1,"name":"Dark Oak Wood","text_type":"log2"},{"type":163,"meta":0,"name":"Acacia Wood Stairs","text_type":"acacia_stairs"},{"type":164,"meta":0,"name":"Dark Oak Wood Stairs","text_type":"dark_oak_stairs"},{"type":165,"meta":0,"name":"Slime Block","text_type":"slime"},{"type":166,"meta":0,"name":"Barrier","text_type":"barrier"},{"type":167,"meta":0,"name":"Iron Trapdoor","text_type":"iron_trapdoor"},{"type":168,"meta":0,"name":"Prismarine","text_type":"prismarine"},{"type":168,"meta":1,"name":"Prismarine Bricks","text_type":"prismarine"},{"type":168,"meta":2,"name":"Dark Prismarine","text_type":"prismarine"},{"type":169,"meta":0,"name":"Sea Lantern","text_type":"sea_lantern"},{"type":170,"meta":0,"name":"Hay Bale","text_type":"hay_block"},{"type":171,"meta":0,"name":"White Carpet","text_type":"carpet"},{"type":171,"meta":1,"name":"Orange Carpet","text_type":"carpet"},{"type":171,"meta":2,"name":"Magenta Carpet","text_type":"carpet"},{"type":171,"meta":3,"name":"Light Blue Carpet","text_type":"carpet"},{"type":171,"meta":4,"name":"Yellow Carpet","text_type":"carpet"},{"type":171,"meta":5,"name":"Lime Carpet","text_type":"carpet"},{"type":171,"meta":6,"name":"Pink Carpet","text_type":"carpet"},{"type":171,"meta":7,"name":"Gray Carpet","text_type":"carpet"},{"type":171,"meta":8,"name":"Light Gray Carpet","text_type":"carpet"},{"type":171,"meta":9,"name":"Cyan Carpet","text_type":"carpet"},{"type":171,"meta":10,"name":"Purple Carpet","text_type":"carpet"},{"type":171,"meta":11,"name":"Blue Carpet","text_type":"carpet"},{"type":171,"meta":12,"name":"Brown Carpet","text_type":"carpet"},{"type":171,"meta":13,"name":"Green Carpet","text_type":"carpet"},{"type":171,"meta":14,"name":"Red Carpet","text_type":"carpet"},{"type":171,"meta":15,"name":"Black Carpet","text_type":"carpet"},{"type":172,"meta":0,"name":"Hardened Clay","text_type":"hardened_clay"},{"type":173,"meta":0,"name":"Block of Coal","text_type":"coal_block"},{"type":174,"meta":0,"name":"Packed Ice","text_type":"packed_ice"},{"type":175,"meta":0,"name":"Sunflower","text_type":"double_plant"},{"type":175,"meta":1,"name":"Lilac","text_type":"double_plant"},{"type":175,"meta":2,"name":"Double Tallgrass","text_type":"double_plant"},{"type":175,"meta":3,"name":"Large Fern","text_type":"double_plant"},{"type":175,"meta":4,"name":"Rose Bush","text_type":"double_plant"},{"type":175,"meta":5,"name":"Peony","text_type":"double_plant"},{"type":176,"meta":0,"name":"Free-standing Banner","text_type":"standing_banner"},{"type":177,"meta":0,"name":"Wall-mounted Banner","text_type":"wall_banner"},{"type":178,"meta":0,"name":"Inverted Daylight Sensor","text_type":"daylight_detector_inverted"},{"type":179,"meta":0,"name":"Red Sandstone","text_type":"red_sandstone"},{"type":179,"meta":1,"name":"Chiseled Red Sandstone","text_type":"red_sandstone"},{"type":179,"meta":2,"name":"Smooth Red Sandstone","text_type":"red_sandstone"},{"type":180,"meta":0,"name":"Red Sandstone Stairs","text_type":"red_sandstone_stairs"},{"type":181,"meta":0,"name":"Double Red Sandstone Slab","text_type":"stone_slab2"},{"type":182,"meta":0,"name":"Red Sandstone Slab","text_type":"double_stone_slab2"},{"type":183,"meta":0,"name":"Spruce Fence Gate","text_type":"spruce_fence_gate"},{"type":184,"meta":0,"name":"Birch Fence Gate","text_type":"birch_fence_gate"},{"type":185,"meta":0,"name":"Jungle Fence Gate","text_type":"jungle_fence_gate"},{"type":186,"meta":0,"name":"Dark Oak Fence Gate","text_type":"dark_oak_fence_gate"},{"type":187,"meta":0,"name":"Acacia Fence Gate","text_type":"acacia_fence_gate"},{"type":188,"meta":0,"name":"Spruce Fence","text_type":"spruce_fence"},{"type":189,"meta":0,"name":"Birch Fence","text_type":"birch_fence"},{"type":190,"meta":0,"name":"Jungle Fence","text_type":"jungle_fence"},{"type":191,"meta":0,"name":"Dark Oak Fence","text_type":"dark_oak_fence"},{"type":192,"meta":0,"name":"Acacia Fence","text_type":"acacia_fence"},{"type":193,"meta":0,"name":"Spruce Door Block","text_type":"spruce_door"},{"type":194,"meta":0,"name":"Birch Door Block","text_type":"birch_door"},{"type":195,"meta":0,"name":"Jungle Door Block","text_type":"jungle_door"},{"type":196,"meta":0,"name":"Acacia Door Block","text_type":"acacia_door"},{"type":197,"meta":0,"name":"Dark Oak Door Block","text_type":"dark_oak_door"},{"type":256,"meta":0,"name":"Iron Shovel","text_type":"iron_shovel"},{"type":257,"meta":0,"name":"Iron Pickaxe","text_type":"iron_pickaxe"},{"type":258,"meta":0,"name":"Iron Axe","text_type":"iron_axe"},{"type":259,"meta":0,"name":"Flint and Steel","text_type":"flint_and_steel"},{"type":260,"meta":0,"name":"Apple","text_type":"apple"},{"type":261,"meta":0,"name":"Bow","text_type":"bow"},{"type":262,"meta":0,"name":"Arrow","text_type":"arrow"},{"type":263,"meta":0,"name":"Coal","text_type":"coal"},{"type":263,"meta":1,"name":"Charcoal","text_type":"coal"},{"type":264,"meta":0,"name":"Diamond","text_type":"diamond"},{"type":265,"meta":0,"name":"Iron Ingot","text_type":"iron_ingot"},{"type":266,"meta":0,"name":"Gold Ingot","text_type":"gold_ingot"},{"type":267,"meta":0,"name":"Iron Sword","text_type":"iron_sword"},{"type":268,"meta":0,"name":"Wooden Sword","text_type":"wooden_sword"},{"type":269,"meta":0,"name":"Wooden Shovel","text_type":"wooden_shovel"},{"type":270,"meta":0,"name":"Wooden Pickaxe","text_type":"wooden_pickaxe"},{"type":271,"meta":0,"name":"Wooden Axe","text_type":"wooden_axe"},{"type":272,"meta":0,"name":"Stone Sword","text_type":"stone_sword"},{"type":273,"meta":0,"name":"Stone Shovel","text_type":"stone_shovel"},{"type":274,"meta":0,"name":"Stone Pickaxe","text_type":"stone_pickaxe"},{"type":275,"meta":0,"name":"Stone Axe","text_type":"stone_axe"},{"type":276,"meta":0,"name":"Diamond Sword","text_type":"diamond_sword"},{"type":277,"meta":0,"name":"Diamond Shovel","text_type":"diamond_shovel"},{"type":278,"meta":0,"name":"Diamond Pickaxe","text_type":"diamond_pickaxe"},{"type":279,"meta":0,"name":"Diamond Axe","text_type":"diamond_axe"},{"type":280,"meta":0,"name":"Stick","text_type":"stick"},{"type":281,"meta":0,"name":"Bowl","text_type":"bowl"},{"type":282,"meta":0,"name":"Mushroom Stew","text_type":"mushroom_stew"},{"type":283,"meta":0,"name":"Golden Sword","text_type":"golden_sword"},{"type":284,"meta":0,"name":"Golden Shovel","text_type":"golden_shovel"},{"type":285,"meta":0,"name":"Golden Pickaxe","text_type":"golden_pickaxe"},{"type":286,"meta":0,"name":"Golden Axe","text_type":"golden_axe"},{"type":287,"meta":0,"name":"String","text_type":"string"},{"type":288,"meta":0,"name":"Feather","text_type":"feather"},{"type":289,"meta":0,"name":"Gunpowder","text_type":"gunpowder"},{"type":290,"meta":0,"name":"Wooden Hoe","text_type":"wooden_hoe"},{"type":291,"meta":0,"name":"Stone Hoe","text_type":"stone_hoe"},{"type":292,"meta":0,"name":"Iron Hoe","text_type":"iron_hoe"},{"type":293,"meta":0,"name":"Diamond Hoe","text_type":"diamond_hoe"},{"type":294,"meta":0,"name":"Golden Hoe","text_type":"golden_hoe"},{"type":295,"meta":0,"name":"Wheat Seeds","text_type":"wheat_seeds"},{"type":296,"meta":0,"name":"Wheat","text_type":"wheat"},{"type":297,"meta":0,"name":"Bread","text_type":"bread"},{"type":298,"meta":0,"name":"Leather Helmet","text_type":"leather_helmet"},{"type":299,"meta":0,"name":"Leather Tunic","text_type":"leather_chestplate"},{"type":300,"meta":0,"name":"Leather Pants","text_type":"leather_leggings"},{"type":301,"meta":0,"name":"Leather Boots","text_type":"leather_boots"},{"type":302,"meta":0,"name":"Chainmail Helmet","text_type":"chainmail_helmet"},{"type":303,"meta":0,"name":"Chainmail Chestplate","text_type":"chainmail_chestplate"},{"type":304,"meta":0,"name":"Chainmail Leggings","text_type":"chainmail_leggings"},{"type":305,"meta":0,"name":"Chainmail Boots","text_type":"chainmail_boots"},{"type":306,"meta":0,"name":"Iron Helmet","text_type":"iron_helmet"},{"type":307,"meta":0,"name":"Iron Chestplate","text_type":"iron_chestplate"},{"type":308,"meta":0,"name":"Iron Leggings","text_type":"iron_leggings"},{"type":309,"meta":0,"name":"Iron Boots","text_type":"iron_boots"},{"type":310,"meta":0,"name":"Diamond Helmet","text_type":"diamond_helmet"},{"type":311,"meta":0,"name":"Diamond Chestplate","text_type":"diamond_chestplate"},{"type":312,"meta":0,"name":"Diamond Leggings","text_type":"diamond_leggings"},{"type":313,"meta":0,"name":"Diamond Boots","text_type":"diamond_boots"},{"type":314,"meta":0,"name":"Golden Helmet","text_type":"golden_helmet"},{"type":315,"meta":0,"name":"Golden Chestplate","text_type":"golden_chestplate"},{"type":316,"meta":0,"name":"Golden Leggings","text_type":"golden_leggings"},{"type":317,"meta":0,"name":"Golden Boots","text_type":"golden_boots"},{"type":318,"meta":0,"name":"Flint","text_type":"flint"},{"type":319,"meta":0,"name":"Raw Porkchop","text_type":"porkchop"},{"type":320,"meta":0,"name":"Cooked Porkchop","text_type":"cooked_porkchop"},{"type":321,"meta":0,"name":"Painting","text_type":"painting"},{"type":322,"meta":0,"name":"Golden Apple","text_type":"golden_apple"},{"type":322,"meta":1,"name":"Enchanted Golden Apple","text_type":"golden_apple"},{"type":323,"meta":0,"name":"Sign","text_type":"sign"},{"type":324,"meta":0,"name":"Oak Door","text_type":"wooden_door"},{"type":325,"meta":0,"name":"Bucket","text_type":"bucket"},{"type":326,"meta":0,"name":"Water Bucket","text_type":"water_bucket"},{"type":327,"meta":0,"name":"Lava Bucket","text_type":"lava_bucket"},{"type":328,"meta":0,"name":"Minecart","text_type":"minecart"},{"type":329,"meta":0,"name":"Saddle","text_type":"saddle"},{"type":330,"meta":0,"name":"Iron Door","text_type":"iron_door"},{"type":331,"meta":0,"name":"Redstone","text_type":"redstone"},{"type":332,"meta":0,"name":"Snowball","text_type":"snowball"},{"type":333,"meta":0,"name":"Boat","text_type":"boat"},{"type":334,"meta":0,"name":"Leather","text_type":"leather"},{"type":335,"meta":0,"name":"Milk Bucket","text_type":"milk_bucket"},{"type":336,"meta":0,"name":"Brick","text_type":"brick"},{"type":337,"meta":0,"name":"Clay","text_type":"clay_ball"},{"type":338,"meta":0,"name":"Sugar Canes","text_type":"reeds"},{"type":339,"meta":0,"name":"Paper","text_type":"paper"},{"type":340,"meta":0,"name":"Book","text_type":"book"},{"type":341,"meta":0,"name":"Slimeball","text_type":"slime_ball"},{"type":342,"meta":0,"name":"Minecart with Chest","text_type":"chest_minecart"},{"type":343,"meta":0,"name":"Minecart with Furnace","text_type":"furnace_minecart"},{"type":344,"meta":0,"name":"Egg","text_type":"egg"},{"type":345,"meta":0,"name":"Compass","text_type":"compass"},{"type":346,"meta":0,"name":"Fishing Rod","text_type":"fishing_rod"},{"type":347,"meta":0,"name":"Clock","text_type":"clock"},{"type":348,"meta":0,"name":"Glowstone Dust","text_type":"glowstone_dust"},{"type":349,"meta":0,"name":"Raw Fish","text_type":"fish"},{"type":349,"meta":1,"name":"Raw Salmon","text_type":"fish"},{"type":349,"meta":2,"name":"Clownfish","text_type":"fish"},{"type":349,"meta":3,"name":"Pufferfish","text_type":"fish"},{"type":350,"meta":0,"name":"Cooked Fish","text_type":"cooked_fish"},{"type":350,"meta":1,"name":"Cooked Salmon","text_type":"cooked_fish"},{"type":351,"meta":0,"name":"Ink Sack","text_type":"dye"},{"type":351,"meta":1,"name":"Rose Red","text_type":"dye"},{"type":351,"meta":2,"name":"Cactus Green","text_type":"dye"},{"type":351,"meta":3,"name":"Coco Beans","text_type":"dye"},{"type":351,"meta":4,"name":"Lapis Lazuli","text_type":"dye"},{"type":351,"meta":5,"name":"Purple Dye","text_type":"dye"},{"type":351,"meta":6,"name":"Cyan Dye","text_type":"dye"},{"type":351,"meta":7,"name":"Light Gray Dye","text_type":"dye"},{"type":351,"meta":8,"name":"Gray Dye","text_type":"dye"},{"type":351,"meta":9,"name":"Pink Dye","text_type":"dye"},{"type":351,"meta":10,"name":"Lime Dye","text_type":"dye"},{"type":351,"meta":11,"name":"Dandelion Yellow","text_type":"dye"},{"type":351,"meta":12,"name":"Light Blue Dye","text_type":"dye"},{"type":351,"meta":13,"name":"Magenta Dye","text_type":"dye"},{"type":351,"meta":14,"name":"Orange Dye","text_type":"dye"},{"type":351,"meta":15,"name":"Bone Meal","text_type":"dye"},{"type":352,"meta":0,"name":"Bone","text_type":"bone"},{"type":353,"meta":0,"name":"Sugar","text_type":"sugar"},{"type":354,"meta":0,"name":"Cake","text_type":"cake"},{"type":355,"meta":0,"name":"Bed","text_type":"bed"},{"type":356,"meta":0,"name":"Redstone Repeater","text_type":"repeater"},{"type":357,"meta":0,"name":"Cookie","text_type":"cookie"},{"type":358,"meta":0,"name":"Map","text_type":"filled_map"},{"type":359,"meta":0,"name":"Shears","text_type":"shears"},{"type":360,"meta":0,"name":"Melon","text_type":"melon"},{"type":361,"meta":0,"name":"Pumpkin Seeds","text_type":"pumpkin_seeds"},{"type":362,"meta":0,"name":"Melon Seeds","text_type":"melon_seeds"},{"type":363,"meta":0,"name":"Raw Beef","text_type":"beef"},{"type":364,"meta":0,"name":"Steak","text_type":"cooked_beef"},{"type":365,"meta":0,"name":"Raw Chicken","text_type":"chicken"},{"type":366,"meta":0,"name":"Cooked Chicken","text_type":"cooked_chicken"},{"type":367,"meta":0,"name":"Rotten Flesh","text_type":"rotten_flesh"},{"type":368,"meta":0,"name":"Ender Pearl","text_type":"ender_pearl"},{"type":369,"meta":0,"name":"Blaze Rod","text_type":"blaze_rod"},{"type":370,"meta":0,"name":"Ghast Tear","text_type":"ghast_tear"},{"type":371,"meta":0,"name":"Gold Nugget","text_type":"gold_nugget"},{"type":372,"meta":0,"name":"Nether Wart","text_type":"nether_wart"},{"type":373,"meta":0,"name":"Potion","text_type":"potion"},{"type":374,"meta":0,"name":"Glass Bottle","text_type":"glass_bottle"},{"type":375,"meta":0,"name":"Spider Eye","text_type":"spider_eye"},{"type":376,"meta":0,"name":"Fermented Spider Eye","text_type":"fermented_spider_eye"},{"type":377,"meta":0,"name":"Blaze Powder","text_type":"blaze_powder"},{"type":378,"meta":0,"name":"Magma Cream","text_type":"magma_cream"},{"type":379,"meta":0,"name":"Brewing Stand","text_type":"brewing_stand"},{"type":380,"meta":0,"name":"Cauldron","text_type":"cauldron"},{"type":381,"meta":0,"name":"Eye of Ender","text_type":"ender_eye"},{"type":382,"meta":0,"name":"Glistering Melon","text_type":"speckled_melon"},{"type":383,"meta":50,"name":"Spawn Creeper","text_type":"spawn_egg"},{"type":383,"meta":51,"name":"Spawn Skeleton","text_type":"spawn_egg"},{"type":383,"meta":52,"name":"Spawn Spider","text_type":"spawn_egg"},{"type":383,"meta":54,"name":"Spawn Zombie","text_type":"spawn_egg"},{"type":383,"meta":55,"name":"Spawn Slime","text_type":"spawn_egg"},{"type":383,"meta":56,"name":"Spawn Ghast","text_type":"spawn_egg"},{"type":383,"meta":57,"name":"Spawn Pigman","text_type":"spawn_egg"},{"type":383,"meta":58,"name":"Spawn Enderman","text_type":"spawn_egg"},{"type":383,"meta":59,"name":"Spawn Cave Spider","text_type":"spawn_egg"},{"type":383,"meta":60,"name":"Spawn Silverfish","text_type":"spawn_egg"},{"type":383,"meta":61,"name":"Spawn Blaze","text_type":"spawn_egg"},{"type":383,"meta":62,"name":"Spawn Magma Cube","text_type":"spawn_egg"},{"type":383,"meta":65,"name":"Spawn Bat","text_type":"spawn_egg"},{"type":383,"meta":66,"name":"Spawn Witch","text_type":"spawn_egg"},{"type":383,"meta":67,"name":"Spawn Endermite","text_type":"spawn_egg"},{"type":383,"meta":68,"name":"Spawn Guardian","text_type":"spawn_egg"},{"type":383,"meta":90,"name":"Spawn Pig","text_type":"spawn_egg"},{"type":383,"meta":91,"name":"Spawn Sheep","text_type":"spawn_egg"},{"type":383,"meta":92,"name":"Spawn Cow","text_type":"spawn_egg"},{"type":383,"meta":93,"name":"Spawn Chicken","text_type":"spawn_egg"},{"type":383,"meta":94,"name":"Spawn Squid","text_type":"spawn_egg"},{"type":383,"meta":95,"name":"Spawn Wolf","text_type":"spawn_egg"},{"type":383,"meta":96,"name":"Spawn Mooshroom","text_type":"spawn_egg"},{"type":383,"meta":98,"name":"Spawn Ocelot","text_type":"spawn_egg"},{"type":383,"meta":100,"name":"Spawn Horse","text_type":"spawn_egg"},{"type":383,"meta":101,"name":"Spawn Rabbit","text_type":"spawn_egg"},{"type":383,"meta":120,"name":"Spawn Villager","text_type":"spawn_egg"},{"type":384,"meta":0,"name":"Bottle o' Enchanting","text_type":"experience_bottle"},{"type":385,"meta":0,"name":"Fire Charge","text_type":"fire_charge"},{"type":386,"meta":0,"name":"Book and Quill","text_type":"writable_book"},{"type":387,"meta":0,"name":"Written Book","text_type":"written_book"},{"type":388,"meta":0,"name":"Emerald","text_type":"emerald"},{"type":389,"meta":0,"name":"Item Frame","text_type":"item_frame"},{"type":390,"meta":0,"name":"Flower Pot","text_type":"flower_pot"},{"type":391,"meta":0,"name":"Carrot","text_type":"carrot"},{"type":392,"meta":0,"name":"Potato","text_type":"potato"},{"type":393,"meta":0,"name":"Baked Potato","text_type":"baked_potato"},{"type":394,"meta":0,"name":"Poisonous Potato","text_type":"poisonous_potato"},{"type":395,"meta":0,"name":"Empty Map","text_type":"map"},{"type":396,"meta":0,"name":"Golden Carrot","text_type":"golden_carrot"},{"type":397,"meta":0,"name":"Mob Head (Skeleton)","text_type":"skull"},{"type":397,"meta":1,"name":"Mob Head (Wither Skeleton)","text_type":"skull"},{"type":397,"meta":2,"name":"Mob Head (Zombie)","text_type":"skull"},{"type":397,"meta":3,"name":"Mob Head (Human)","text_type":"skull"},{"type":397,"meta":4,"name":"Mob Head (Creeper)","text_type":"skull"},{"type":398,"meta":0,"name":"Carrot on a Stick","text_type":"carrot_on_a_stick"},{"type":399,"meta":0,"name":"Nether Star","text_type":"nether_star"},{"type":400,"meta":0,"name":"Pumpkin Pie","text_type":"pumpkin_pie"},{"type":401,"meta":0,"name":"Firework Rocket","text_type":"fireworks"},{"type":402,"meta":0,"name":"Firework Star","text_type":"firework_charge"},{"type":403,"meta":0,"name":"Enchanted Book","text_type":"enchanted_book"},{"type":404,"meta":0,"name":"Redstone Comparator","text_type":"comparator"},{"type":405,"meta":0,"name":"Nether Brick","text_type":"netherbrick"},{"type":406,"meta":0,"name":"Nether Quartz","text_type":"quartz"},{"type":407,"meta":0,"name":"Minecart with TNT","text_type":"tnt_minecart"},{"type":408,"meta":0,"name":"Minecart with Hopper","text_type":"hopper_minecart"},{"type":409,"meta":0,"name":"Prismarine Shard","text_type":"prismarine_shard"},{"type":410,"meta":0,"name":"Prismarine Crystals","text_type":"prismarine_crystals"},{"type":411,"meta":0,"name":"Raw Rabbit","text_type":"rabbit"},{"type":412,"meta":0,"name":"Cooked Rabbit","text_type":"cooked_rabbit"},{"type":413,"meta":0,"name":"Rabbit Stew","text_type":"rabbit_stew"},{"type":414,"meta":0,"name":"Rabbit's Foot","text_type":"rabbit_foot"},{"type":415,"meta":0,"name":"Rabbit Hide","text_type":"rabbit_hide"},{"type":416,"meta":0,"name":"Armor Stand","text_type":"armor_stand"},{"type":417,"meta":0,"name":"Iron Horse Armor","text_type":"iron_horse_armor"},{"type":418,"meta":0,"name":"Golden Horse Armor","text_type":"golden_horse_armor"},{"type":419,"meta":0,"name":"Diamond Horse Armor","text_type":"diamond_horse_armor"},{"type":420,"meta":0,"name":"Lead","text_type":"lead"},{"type":421,"meta":0,"name":"Name Tag","text_type":"name_tag"},{"type":422,"meta":0,"name":"Minecart with Command Block","text_type":"command_block_minecart"},{"type":423,"meta":0,"name":"Raw Mutton","text_type":"mutton"},{"type":424,"meta":0,"name":"Cooked Mutton","text_type":"cooked_mutton"},{"type":425,"meta":0,"name":"Banner","text_type":"banner"},{"type":427,"meta":0,"name":"Spruce Door","text_type":"spruce_door"},{"type":428,"meta":0,"name":"Birch Door","text_type":"birch_door"},{"type":429,"meta":0,"name":"Jungle Door","text_type":"jungle_door"},{"type":430,"meta":0,"name":"Acacia Door","text_type":"acacia_door"},{"type":431,"meta":0,"name":"Dark Oak Door","text_type":"dark_oak_door"},{"type":2256,"meta":0,"name":"13 Disc","text_type":"record_13"},{"type":2257,"meta":0,"name":"Cat Disc","text_type":"record_cat"},{"type":2258,"meta":0,"name":"Blocks Disc","text_type":"record_blocks"},{"type":2259,"meta":0,"name":"Chirp Disc","text_type":"record_chirp"},{"type":2260,"meta":0,"name":"Far Disc","text_type":"record_far"},{"type":2261,"meta":0,"name":"Mall Disc","text_type":"record_mall"},{"type":2262,"meta":0,"name":"Mellohi Disc","text_type":"record_mellohi"},{"type":2263,"meta":0,"name":"Stal Disc","text_type":"record_stal"},{"type":2264,"meta":0,"name":"Strad Disc","text_type":"record_strad"},{"type":2265,"meta":0,"name":"Ward Disc","text_type":"record_ward"},{"type":2266,"meta":0,"name":"11 Disc","text_type":"record_11"},{"type":2267,"meta":0,"name":"Wait Disc","text_type":"record_wait"}] -------------------------------------------------------------------------------- /src/output/rcon.js: -------------------------------------------------------------------------------- 1 | module.exports = function(blocks, cmdblocks) 2 | { 3 | var rcon = new Rcon(); 4 | var cmds = []; 5 | 6 | for(var i = 0; i < blocks.length; i++) 7 | { 8 | var cmd = ["setblock", blocks[i].x, blocks[i].y, blocks[i].z, blocks[i].tagName, blocks[i].data, "replace"].join(" "); 9 | cmds.push(cmd); 10 | } 11 | 12 | for(var i = 0; i < cmdblocks.length; i++) 13 | { 14 | var data = "{Command:" + JSON.stringify(cmdblocks[i].command) + ",auto:1b}"; 15 | var cmd = ["setblock", cmdblocks[i].x, cmdblocks[i].y, cmdblocks[i].z, "chain_command_block", cmdblocks[i].data, "replace", data].join(" "); 16 | cmds.push(cmd); 17 | } 18 | 19 | console.log("Outputting via rcon to " + options.rcon_ip + ":" + options.rcon_port); 20 | 21 | rcon.connect(options.rcon_ip, options.rcon_port, options.rcon_password, function(err) 22 | { 23 | if(err) 24 | throw err; 25 | 26 | function next(i) 27 | { 28 | rcon.sendCommand(cmds[i], function(err, res) 29 | { 30 | if(err) 31 | throw err; 32 | 33 | if(res.data == "An unknown error occurred while attempting to perform this command") //minecraft is weird sometimes 34 | { 35 | next(i); 36 | return; 37 | } 38 | 39 | i++; 40 | if(i < cmds.length) 41 | { 42 | next(i); 43 | } 44 | else 45 | { 46 | rcon.end(); 47 | } 48 | }); 49 | } 50 | next(0); 51 | }); 52 | } 53 | 54 | // 55 | //https://github.com/tehbeard/node-rcon 56 | //by "tehbeard" 57 | // 58 | 59 | function Rcon() 60 | { 61 | var net = require('net'); 62 | 63 | var AUTH_TYPE=0x03; 64 | var COMMAND_TYPE=0x02; 65 | var AUTH_RES_TYPE=0x02; 66 | var TIMEOUT=2000; //time to wait for a response 67 | 68 | this.socket=null; 69 | this.reqID=1; 70 | this.authed = false; 71 | this.online = false; 72 | 73 | this.isOnline = function() {return this.online;}//return online status of connection 74 | 75 | //queue management 76 | this.queue = {}; //keeps track of commands sent 77 | /** 78 | * Add a call to the queue and start the timeout. 79 | * @param {Number} Request id 80 | * @param {Function} callback 81 | */ 82 | this._addQueue = function(id, callback){ 83 | if (typeof(callback)==='undefined')return; 84 | var q = this.queue; 85 | var t = setTimeout(function(){ 86 | delete q[id]; //drop the timed out request from the queue 87 | callback("Timed out"); 88 | },TIMEOUT); 89 | this.queue[id]={callback:callback, timeout:t}; 90 | }; 91 | 92 | /** 93 | * Check if we have a request matching the response 94 | * @param {Object} response object 95 | */ 96 | this._processQueue = function(response){ 97 | //do we have anything on the queue that matches. 98 | if(response.reqID in this.queue){ 99 | var q = this.queue[response.reqID]; 100 | //clear the timeout! 101 | clearTimeout(q.timeout); 102 | //callback 103 | q.callback(null, response); 104 | //delete from the queue 105 | delete this.queue[response.reqID]; 106 | } 107 | } 108 | 109 | 110 | //connect command 111 | this.connect = function(ip,port,password,callback){ 112 | if(typeof(callback)==='undefined'){callback = function(err, response){};} 113 | this.socket = net.createConnection(port,ip); 114 | this.socket.rcon = this; 115 | this.socket.on('error',function(err){return callback(err);}); 116 | this.socket.on('close',function(){this.rcon.authed=false;this.rcon.online=false}); 117 | this.socket.on('connect',function(){ 118 | this.rcon.online=true; 119 | this.write(this.rcon.makePacket(0,AUTH_TYPE,password)); 120 | }); 121 | this.socket.on('data',function(data){ 122 | var responses = this.rcon.readPacket(data); 123 | for(var i=0; i size+4){ 189 | //position on the next one 190 | packet = packet.slice(size+4); 191 | } 192 | else{ 193 | //no more responses 194 | haveMore=false; 195 | } 196 | } 197 | //always return an array even if only one response 198 | return responses; 199 | }; 200 | } 201 | -------------------------------------------------------------------------------- /src/output/schematic.js: -------------------------------------------------------------------------------- 1 | var itemIds = require("./itemIds.json"); 2 | var tagNames = {}; 3 | for(var i = 0; i < itemIds.length; i++) 4 | { 5 | tagNames[itemIds[i].text_type] = itemIds[i].type; 6 | } 7 | 8 | module.exports = function(blocks, cmdBlocks, callback) 9 | { 10 | console.log("Outputting as schematic to " + options.schematic_file); 11 | 12 | var blockCount = blocks.length + cmdBlocks.length; 13 | var width = options.length || 20; 14 | var height = 1; 15 | var length = Math.ceil(blockCount / 20); 16 | 17 | var tileEntities = []; 18 | var _blocks = new Array(blockCount); 19 | var data = new Array(blockCount); 20 | 21 | _blocks.fill(0); 22 | data.fill(0); 23 | 24 | for(var i = 0; i < blocks.length; i++) 25 | { 26 | var adress = (blocks[i].y * length + blocks[i].z) * width + blocks[i].x; 27 | var itemId = tagNames[blocks[i].tagName]; 28 | 29 | _blocks[adress] = itemId; 30 | data[adress] = blocks[i].data & 0x0f; 31 | } 32 | for(var i = 0; i < cmdBlocks.length; i++) //{x: x, y: y, z: z, data: blockData, command: blocks[i].command} 33 | { 34 | var adress = (cmdBlocks[i].y * length + cmdBlocks[i].z) * width + cmdBlocks[i].x; 35 | 36 | _blocks[adress] = 211; //chain commandblock currently no in the item id list 37 | data[adress] = cmdBlocks[i].data & 0x0f; 38 | 39 | tileEntities.push({ 40 | Command: cmdBlocks[i].command, 41 | auto: 1, 42 | id: "Control", 43 | x: cmdBlocks[i].x, 44 | y: cmdBlocks[i].y, 45 | z: cmdBlocks[i].z 46 | }); 47 | } 48 | 49 | var data = { 50 | rootName: "Schematic", 51 | root: { 52 | Width: width, 53 | Height: height, 54 | Length: length, 55 | Materials: "Alpha", 56 | Blocks: _blocks, 57 | Data: data, 58 | Entities: [], 59 | TileEntities: tileEntities 60 | } 61 | }; 62 | 63 | schema.TileEntities = new Array(tileEntities.length); 64 | schema.TileEntities.fill(controlSchema); 65 | 66 | toNBT(data, schema, function(err, _data) 67 | { 68 | if(callback) 69 | { 70 | callback(err, _data); 71 | } 72 | else 73 | { 74 | if(err) 75 | throw err; 76 | 77 | require("fs").writeFileSync(options.schematic_file, _data); 78 | } 79 | }); 80 | } 81 | 82 | var tags = [ 83 | "end", 84 | "byte", 85 | "short", 86 | "int", 87 | "long", 88 | "float", 89 | "double", 90 | "byteArray", 91 | "string", 92 | "list", 93 | "compound", 94 | "intArray" 95 | ]; 96 | function tagId(name) 97 | { 98 | return tags.indexOf(name); 99 | } 100 | var schema = { 101 | Width: tagId("short"), 102 | Height: tagId("short"), 103 | Length: tagId("short"), 104 | Materials: tagId("string"), 105 | Blocks: tagId("byteArray"), 106 | Data: tagId("byteArray"), 107 | Entities: [ 108 | {} 109 | ], 110 | TileEntities: [] 111 | }; 112 | var controlSchema = { 113 | Command: tagId("string"), 114 | auto: tagId("byte"), 115 | id: tagId("string"), 116 | x: tagId("int"), 117 | y: tagId("int"), 118 | z: tagId("int") 119 | }; 120 | 121 | //see https://github.com/M4GNV5/node-minecraft-world/blob/master/src/nbt/writer.js 122 | var toNBT = (function() 123 | { 124 | function createWriter(bufferFunc, size) 125 | { 126 | return function(value) 127 | { 128 | var buff = new Buffer(size); 129 | buff[bufferFunc](value, 0); 130 | this.buffer.push(buff); 131 | }; 132 | } 133 | 134 | function schemaToType(schema) 135 | { 136 | if(typeof schema == "number") 137 | { 138 | return schema; 139 | } 140 | else if(schema instanceof Array) 141 | { 142 | if(schema[0] === tags.indexOf("byte")) 143 | return tags.indexof("byteArray"); 144 | else if(schema[0] === tags.indexOf("int")) 145 | return tags.indexof("intArray"); 146 | else 147 | return tags.indexOf("list"); 148 | } 149 | else if(typeof schema == "object") 150 | { 151 | return tags.indexOf("compound"); 152 | } 153 | } 154 | 155 | var Writer = function(data, schema, cb) 156 | { 157 | this.buffer = []; 158 | 159 | this.byte(10); 160 | this.string(data.rootName); 161 | this.compound(data.root, schema); 162 | 163 | var buff = Buffer.concat(this.buffer); 164 | 165 | cb(undefined, buff); 166 | } 167 | 168 | Writer.prototype.byte = createWriter("writeUInt8", 1); 169 | Writer.prototype.short = createWriter("writeInt16BE", 2); 170 | Writer.prototype.int = createWriter("writeInt32BE", 4); 171 | Writer.prototype.float = createWriter("writeFloatBE", 4); 172 | Writer.prototype.double = createWriter("writeDoubleBE", 8); 173 | 174 | Writer.prototype.end = function() 175 | { 176 | this.byte(0); 177 | } 178 | Writer.prototype.long = function(val) 179 | { 180 | this.int(val.left); 181 | this.int(val.right); 182 | } 183 | Writer.prototype.byteArray = function(val) 184 | { 185 | this.int(val.length); 186 | for(var i = 0; i < val.length; i++) 187 | { 188 | this.byte(val[i]); 189 | } 190 | } 191 | Writer.prototype.string = function(val) 192 | { 193 | this.short(val.length); 194 | this.buffer.push(new Buffer(val, "utf8")); 195 | } 196 | Writer.prototype.list = function(val, schema) 197 | { 198 | var type = schemaToType(schema[0]); 199 | this.byte(type); 200 | this.int(val.length); 201 | for(var i = 0; i < val.length; i++) 202 | { 203 | this[tags[type]](val[i], schema[i]); 204 | } 205 | } 206 | Writer.prototype.compound = function(val, schema) 207 | { 208 | for(var key in schema) 209 | { 210 | if(!val.hasOwnProperty(key)) 211 | continue; 212 | 213 | var type = schemaToType(schema[key]); 214 | this.byte(type); 215 | this.string(key); 216 | this[tags[type]](val[key], schema[key]); 217 | } 218 | this.byte(tags.indexOf("end")); 219 | } 220 | Writer.prototype.intArray = function(val) 221 | { 222 | this.int(val.length) 223 | for(var i = 0; i < val.length; i++) 224 | { 225 | this.int(val[i]); 226 | } 227 | } 228 | 229 | return function toNBT(data, schema, callback) 230 | { 231 | new Writer(data, schema, callback); 232 | }; 233 | })(); 234 | -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CPL", 3 | "version": "0.0.1", 4 | "description": "Convert Lua to commandblocks", 5 | "repository": "https://github.com/M4GNV5/CPL.git", 6 | "homepage": "https://github.com/M4GNV5/CPL", 7 | "author": "Jakob Löw ", 8 | "main": "main.js" 9 | } 10 | -------------------------------------------------------------------------------- /src/types/Boolean.js: -------------------------------------------------------------------------------- 1 | var nextName = require("./../lib/naming.js"); 2 | var Integer = require("./Integer.js"); 3 | var String = require("./String.js"); 4 | 5 | function Boolean(startVal, name, silent) 6 | { 7 | this.name = name || nextName("bool"); 8 | 9 | if(startVal instanceof Boolean) 10 | startVal = startVal.base; 11 | else if(typeof startVal.toInteger == "function") 12 | startVal = startVal; 13 | else 14 | startVal = startVal ? 1 : 0; 15 | 16 | this.base = new Integer(startVal, this.name, silent); 17 | } 18 | 19 | Boolean.prototype.set = function(val, conditional) 20 | { 21 | if(val instanceof Boolean) 22 | this.base.set(val.base, conditional); 23 | else if(typeof val.toInteger == "function") 24 | this.base.set(val, conditional); 25 | else if(typeof val == "boolean") 26 | this.base.set(val ? 1 : 0, conditional); 27 | else 28 | throw "Cannot assing '" + val.constructor.name + "' to a Boolean" + (new Error()).stack; 29 | }; 30 | 31 | Boolean.prototype.toInteger = function() 32 | { 33 | return this.base; 34 | }; 35 | 36 | Boolean.prototype.clone = function(cloneName) 37 | { 38 | return new Boolean(this, cloneName); 39 | }; 40 | 41 | Boolean.prototype.toTellrawExtra = function() 42 | { 43 | var val = new String("false"); 44 | command(this.isExact(true)); 45 | val.set("true", true); 46 | return val.toTellrawExtra(); 47 | }; 48 | 49 | Boolean.prototype.isExact = function(val) 50 | { 51 | return this.base.isExact(val ? 1 : 0); 52 | }; 53 | 54 | module.exports = Boolean; 55 | -------------------------------------------------------------------------------- /src/types/Float.js: -------------------------------------------------------------------------------- 1 | var nextName = require("./../lib/naming.js"); 2 | var Integer = require("./Integer.js"); 3 | 4 | function Float(startVal, name, silent) 5 | { 6 | this.name = name || nextName("float"); 7 | 8 | if(startVal instanceof Float) 9 | { 10 | startVal = startVal.base; 11 | } 12 | else if(typeof startVal == "object" && startVal.toInteger) 13 | { 14 | startVal = startVal.toInteger().clone(); 15 | startVal.multiplicate(Float.accuracy); 16 | } 17 | else if(typeof startVal == "number") 18 | { 19 | startVal = Math.floor(startVal * Float.accuracy); 20 | } 21 | 22 | this.base = new Integer(startVal, this.name, silent); 23 | } 24 | 25 | Float.accuracy = 2; //digits after the comma 26 | 27 | Float.accuracy = Math.pow(10, Float.accuracy); 28 | 29 | function convertStatic(val) 30 | { 31 | var _val = Math.floor(val * Float.accuracy); 32 | return _val; 33 | } 34 | 35 | Float.prototype.set = function(val, conditional) 36 | { 37 | if(val instanceof Float) 38 | { 39 | this.base.set(val.base, conditional); 40 | } 41 | else if(typeof val.toInteger == "function") 42 | { 43 | this.base.set(val.toInteger(), conditional); 44 | this.base.multiplicate(100, conditional); 45 | } 46 | else if(typeof val == "number") 47 | { 48 | this.base.set(convertStatic(val), conditional); 49 | } 50 | else 51 | { 52 | throw "Cannot assing '" + val.constructor.name + "' to a Float"; 53 | } 54 | }; 55 | 56 | Float.prototype.add = function(val, conditional) 57 | { 58 | if(val instanceof Float) 59 | { 60 | this.base.add(val.base, conditional); 61 | } 62 | else if(typeof val.toInteger == "function") 63 | { 64 | val = val.toInteger().clone(); 65 | val.multiplicate(100); 66 | this.base.add(val, conditional); 67 | } 68 | else if(typeof val == "number") 69 | { 70 | this.base.add(convertStatic(val), conditional); 71 | } 72 | else 73 | { 74 | throw "Cannot add '" + val.constructor.name + "' to a Float"; 75 | } 76 | }; 77 | 78 | Float.prototype.remove = function(val, conditional) 79 | { 80 | if(val instanceof Float) 81 | { 82 | this.base.remove(val.base, conditional); 83 | } 84 | else if(typeof val.toInteger == "function") 85 | { 86 | val = val.toInteger().clone(); 87 | val.multiplicate(100); 88 | this.base.remove(val, conditional); 89 | } 90 | else if(typeof val == "number") 91 | { 92 | this.base.remove(convertStatic(val), conditional); 93 | } 94 | else 95 | { 96 | throw "Cannot remove '" + val.constructor.name + "' from a Float"; 97 | } 98 | }; 99 | 100 | Float.prototype.multiplicate = function(val, conditional) 101 | { 102 | if(val instanceof Float) 103 | { 104 | this.base.multiplicate(val.base, conditional); 105 | this.base.divide(100, conditional); 106 | } 107 | else if(typeof val.toInteger == "function") 108 | { 109 | this.base.multiplicate(val, conditional); 110 | } 111 | else if(typeof val == "number") 112 | { 113 | this.base.multiplicate(convertStatic(val), conditional); 114 | this.base.divide(100, conditional); 115 | } 116 | else 117 | { 118 | throw "Cannot multiplicate '" + val.constructor.name + "' with a Float"; 119 | } 120 | }; 121 | 122 | Float.prototype.divide = function(val, conditional) 123 | { 124 | if(val instanceof Float) 125 | { 126 | this.base.multiplicate(100, conditional); 127 | this.base.divide(val.base, conditional); 128 | } 129 | else if(typeof val.toInteger == "function") 130 | { 131 | this.base.divide(val, conditional); 132 | } 133 | else if(typeof val == "number") 134 | { 135 | this.base.multiplicate(100, conditional); 136 | this.base.divide(convertStatic(val), conditional); 137 | } 138 | else 139 | { 140 | throw "Cannot divide a Float through '" + val.constructor.name + "'"; 141 | } 142 | }; 143 | 144 | Float.prototype.mod = function(val, conditional) 145 | { 146 | if(val instanceof Float) 147 | { 148 | this.base.mod(val.base, conditional); 149 | } 150 | else if(typeof val.toInteger == "function") 151 | { 152 | val = val.toInteger().clone(); 153 | val.multiplicate(Float.accuracy, conditional); 154 | this.base.mod(val, conditional); 155 | } 156 | else if(typeof val == "number") 157 | { 158 | this.base.mod(convertStatic(val), conditional); 159 | } 160 | else 161 | { 162 | throw "Cannot assing '" + val.constructor.name + "' to a Float"; 163 | } 164 | }; 165 | 166 | Float.prototype.toInteger = function() 167 | { 168 | var val = this.base.clone(); 169 | val.divide(Float.accuracy); 170 | return val; 171 | }; 172 | 173 | Float.prototype.clone = function(cloneName) 174 | { 175 | return new Float(this, cloneName); 176 | }; 177 | 178 | Float.prototype.toTellrawExtra = function() 179 | { 180 | var left = this.base.clone(this.name + "left"); 181 | var right = this.base.clone(this.name + "right"); 182 | left.divide(Float.accuracy); 183 | right.mod(Float.accuracy); 184 | 185 | var leftExtra = {score: {objective: Integer.scoreName, name: left.name}}; 186 | var rightExtra = {score: {objective: Integer.scoreName, name: right.name}}; 187 | 188 | return JSON.stringify(leftExtra) + ",\".\"," + JSON.stringify(rightExtra); 189 | }; 190 | 191 | Float.prototype.isExact = function(val) 192 | { 193 | val = convertStatic(val) || val; 194 | return this.base.isBetween(val, val); 195 | }; 196 | 197 | Float.prototype.isBetweenEx = function(min, max) 198 | { 199 | min = convertStatic(min) || min; 200 | max = convertStatic(max) || max; 201 | return this.base.isBetweenEx(min, max); 202 | }; 203 | 204 | Float.prototype.isBetween = function(min, max) 205 | { 206 | min = convertStatic(min) || min; 207 | max = convertStatic(max) || max; 208 | 209 | return this.base.isBetween(min, max); 210 | }; 211 | 212 | module.exports = Float; 213 | -------------------------------------------------------------------------------- /src/types/Integer.js: -------------------------------------------------------------------------------- 1 | var Score = require("./Score.js"); 2 | var nextName = require("./../lib/naming.js"); 3 | 4 | function Integer(startVal, name, silent) 5 | { 6 | this.name = name || nextName("int"); 7 | 8 | startVal = startVal || 0; 9 | var startVal = typeof startVal.toInteger == "function" ? startVal : (parseInt(startVal) || 0); 10 | 11 | if(!silent) 12 | this.set(startVal); 13 | } 14 | 15 | Integer.statics = []; 16 | 17 | Integer.scoreName = "MoonCraft"; 18 | 19 | Integer.prototype.set = function(val, conditional) 20 | { 21 | if(val instanceof Score) 22 | this.operation("=", val.selector, val.scoreName, conditional); 23 | else if(typeof val.toInteger == "function") 24 | this.operation("=", val.toInteger().name, Integer.scoreName, conditional); 25 | else if(typeof val == "number") 26 | command(["scoreboard players set", this.name, Integer.scoreName, val].join(" "), conditional); 27 | else 28 | throw "Cannot assing '" + val.constructor.name + "' to an Integer"; 29 | }; 30 | 31 | Integer.prototype.add = function(val, conditional) 32 | { 33 | if(val instanceof Score) 34 | this.operation("+=", val.selector, val.scoreName, conditional); 35 | else if(typeof val == "object" && typeof val.toInteger == "function") 36 | this.operation("+=", val.toInteger().name, Integer.scoreName, conditional); 37 | else if(typeof val == "number") 38 | command(["scoreboard players add", this.name, Integer.scoreName, val].join(" "), conditional); 39 | else 40 | throw "Cannot add '" + val.constructor.name + "' to an Integer"; 41 | }; 42 | 43 | Integer.prototype.remove = function(val, conditional) 44 | { 45 | if(val instanceof Score) 46 | this.operation("-=", val.selector, val.scoreName, conditional); 47 | else if(typeof val == "object" && typeof val.toInteger == "function") 48 | this.operation("-=", val.toInteger().name, Integer.scoreName, conditional); 49 | else if(typeof val == "number") 50 | command(["scoreboard players remove", this.name, Integer.scoreName, val].join(" "), conditional); 51 | else 52 | throw "Cannot remove '" + val.constructor.name + "' to an Integer"; 53 | }; 54 | 55 | Integer.prototype.multiplicate = function(val, conditional) 56 | { 57 | if(val instanceof Score) 58 | this.operation("*=", val.selector, val.scoreName, conditional); 59 | else if(typeof val == "object" && typeof val.toInteger == "function") 60 | this.operation("*=", val.toInteger().name, Integer.scoreName, conditional); 61 | else if(typeof val == "number") 62 | this.staticOperation("*=", val, conditional); 63 | else 64 | throw "Cannot multiplicate '" + val.constructor.name + "' with an Integer"; 65 | }; 66 | 67 | Integer.prototype.divide = function(val, conditional) 68 | { 69 | if(val instanceof Score) 70 | this.operation("/=", val.selector, val.scoreName, conditional); 71 | else if(typeof val == "object" && typeof val.toInteger == "function") 72 | this.operation("/=", val.toInteger().name, Integer.scoreName, conditional); 73 | else if(typeof val == "number") 74 | this.staticOperation("/=", val, conditional); 75 | else 76 | throw "Cannot divide Integer through '" + val.constructor.name + "'"; 77 | }; 78 | 79 | Integer.prototype.mod = function(val, conditional) 80 | { 81 | if(val instanceof Score) 82 | this.operation("%=", val.selector, val.scoreName, conditional); 83 | else if(typeof val == "object" && typeof val.toInteger == "function") 84 | this.operation("%=", val.toInteger().name, Integer.scoreName, conditional); 85 | else if(typeof val == "number") 86 | this.staticOperation("%=", val, conditional); 87 | else 88 | throw "Cannot divide Integer through '" + val.constructor.name + "'"; 89 | }; 90 | 91 | Integer.prototype.operation = function(op, otherName, otherScore, conditional) 92 | { 93 | command(["scoreboard players operation", this.name, Integer.scoreName, op, otherName, otherScore].join(" "), conditional); 94 | }; 95 | 96 | Integer.prototype.staticOperation = function(op, val, conditional) 97 | { 98 | if(options.export) 99 | command(["scoreboard players set", "static" + val, Integer.scoreName, val].join(" ")); 100 | else if(Integer.statics.indexOf(val) == -1) 101 | Integer.statics.push(val); 102 | 103 | this.operation(op, "static" + val.toString(), Integer.scoreName, conditional); 104 | }; 105 | 106 | Integer.prototype.toInteger = function() 107 | { 108 | return this; 109 | }; 110 | 111 | Integer.prototype.clone = function(cloneName) 112 | { 113 | return new Integer(this, cloneName); 114 | }; 115 | 116 | Integer.prototype.toTellrawExtra = function() 117 | { 118 | return JSON.stringify({score: {objective: Integer.scoreName, name: this.name}}); 119 | }; 120 | 121 | Integer.prototype.isExact = function(val) 122 | { 123 | return this.isBetween(val, val); 124 | }; 125 | 126 | Integer.prototype.isBetweenEx = function(min, max) 127 | { 128 | return this.isBetween(min + 1 || min, max - 1 || max); 129 | }; 130 | 131 | Integer.prototype.isBetween = function(min, max) 132 | { 133 | min = typeof min == "number" ? min : -1 * Math.pow(2, 31); 134 | max = typeof max == "number" ? max : Math.pow(2, 31) - 1; 135 | 136 | return ["scoreboard players test", this.name, Integer.scoreName, min, max].join(" "); 137 | }; 138 | 139 | module.exports = Integer; 140 | -------------------------------------------------------------------------------- /src/types/Score.js: -------------------------------------------------------------------------------- 1 | var Integer = require("./Integer.js"); 2 | 3 | function Score(selector, scoreName) 4 | { 5 | if(typeof Integer == "object") //fix cross requiring 6 | Integer = require("./Integer.js"); 7 | 8 | this.selector = selector; 9 | this.scoreName = scoreName; 10 | } 11 | 12 | Score.prototype.set = function(val, conditional) 13 | { 14 | if(val instanceof Score) 15 | this.operation("=", val.selector, val.scoreName, conditional); 16 | else if(typeof val.toInteger == "function") 17 | this.operation("=", val.toInteger().name, Integer.scoreName, conditional); 18 | else if(typeof val == "number") 19 | command(["scoreboard players set", this.selector, this.scoreName, val].join(" "), conditional); 20 | else 21 | throw "Cannot assing '" + val.constructor.name + "' to a Score"; 22 | }; 23 | 24 | Score.prototype.add = function(val, conditional) 25 | { 26 | if(val instanceof Score) 27 | this.operation("+=", val.selector, val.scoreName, conditional); 28 | else if(typeof val == "object" && typeof val.toInteger == "function") 29 | this.operation("+=", val.toInteger().name, Integer.scoreName, conditional); 30 | else if(typeof val == "number") 31 | command(["scoreboard players add", this.selector, this.scoreName, val].join(" "), conditional); 32 | else 33 | throw "Cannot add '" + val.constructor.name + "' to a Score"; 34 | }; 35 | 36 | Score.prototype.remove = function(val, conditional) 37 | { 38 | if(val instanceof Score) 39 | this.operation("-=", val.selector, val.scoreName, conditional); 40 | else if(typeof val == "object" && typeof val.toInteger == "function") 41 | this.operation("-=", val.toInteger().name, Integer.scoreName, conditional); 42 | else if(typeof val == "number") 43 | command(["scoreboard players remove", this.selector, this.scoreName, val].join(" "), conditional); 44 | else 45 | throw "Cannot remove '" + val.constructor.name + "' to a Score"; 46 | }; 47 | 48 | Score.prototype.multiplicate = function(val, conditional) 49 | { 50 | if(val instanceof Score) 51 | this.operation("*=", val.selector, val.scoreName, conditional); 52 | else if(typeof val == "object" && typeof val.toInteger == "function") 53 | this.operation("*=", val.toInteger().name, Integer.scoreName, conditional); 54 | else if(typeof val == "number") 55 | this.staticOperation("*=", val, conditional); 56 | else 57 | throw "Cannot multiplicate '" + val.constructor.name + "' with a Score"; 58 | }; 59 | 60 | Score.prototype.divide = function(val, conditional) 61 | { 62 | if(val instanceof Score) 63 | this.operation("/=", val.selector, val.scoreName, conditional); 64 | else if(typeof val == "object" && typeof val.toInteger == "function") 65 | this.operation("/=", val.toInteger().name, Integer.scoreName, conditional); 66 | else if(typeof val == "number") 67 | this.staticOperation("/=", val, conditional); 68 | else 69 | throw "Cannot divide Score through '" + val.constructor.name + "'"; 70 | }; 71 | 72 | Score.prototype.mod = function(val, conditional) 73 | { 74 | if(val instanceof Score) 75 | this.operation("=", val.selector, val.scoreName, conditional); 76 | else if(typeof val == "object" && typeof val.toInteger == "function") 77 | this.operation("%=", val.toInteger().name, Integer.scoreName, conditional); 78 | else if(typeof val == "number") 79 | this.staticOperation("%=", val, conditional); 80 | else 81 | throw "Cannot divide Score through '" + val.constructor.name + "'"; 82 | }; 83 | 84 | Score.prototype.operation = function(op, otherName, otherScore, conditional) 85 | { 86 | command(["scoreboard players operation", this.selector, this.scoreName, op, otherName, otherScore].join(" "), conditional); 87 | }; 88 | 89 | Score.prototype.staticOperation = function(op, val, conditional) 90 | { 91 | if(Integer.statics.indexOf(val) == -1) 92 | Integer.statics.push(val); 93 | this.operation(op, "static" + val.toString(), Integer.scoreName, conditional); 94 | }; 95 | 96 | Score.prototype.toInteger = function(name) 97 | { 98 | var val = new Integer(undefined, name); 99 | val.operation("=", this.selector, this.scoreName); 100 | return val; 101 | }; 102 | 103 | Score.prototype.clone = function(cloneName) 104 | { 105 | return this.toInteger(cloneName); 106 | }; 107 | 108 | Score.prototype.toTellrawExtra = function() 109 | { 110 | var val = this.toInteger(); 111 | return val.toTellrawExtra(); 112 | }; 113 | 114 | Score.prototype.isExact = function(val) 115 | { 116 | return this.isBetween(val, val); 117 | }; 118 | 119 | Score.prototype.isBetweenEx = function(min, max) 120 | { 121 | return this.isBetween(min + 1 || min, max - 1 || max); 122 | }; 123 | 124 | Score.prototype.isBetween = function(min, max) 125 | { 126 | min = typeof min == "number" ? min : -1 * Math.pow(2, 31); 127 | max = typeof max == "number" ? max : Math.pow(2, 31) - 1; 128 | 129 | return ["scoreboard players test", this.selector, this.scoreName, min, max].join(" "); 130 | }; 131 | 132 | module.exports = Score; 133 | -------------------------------------------------------------------------------- /src/types/String.js: -------------------------------------------------------------------------------- 1 | var nextName = require("./../lib/naming.js"); 2 | var scope = require("./../lib/Scope.js"); 3 | var Integer = require("./Integer.js"); 4 | 5 | var nextId = 1; 6 | 7 | function String(startVal, name, silent) 8 | { 9 | if(silent) 10 | throw "cannot silently create a string"; 11 | 12 | this.name = name || nextName("string"); 13 | startVal = startVal || ""; 14 | var _startVal = startVal.toString() || name; 15 | 16 | this.selector = "@e[type=ArmorStand,score_{0}_min={1},score_{0}={1},tag=string]".format(Integer.scoreName, nextId); 17 | 18 | command("kill {0}".format(this.selector)); 19 | command("summon ArmorStand ~ ~1 ~ {NoGravity:1,CustomName:\"{0}\",Tags:[\"string\"]}".format(this.name)); 20 | 21 | command("scoreboard players set @e[type=ArmorStand] {0} {1} {CustomName:\"{2}\"}".format(Integer.scoreName, nextId, this.name)); 22 | nextId++; 23 | 24 | this.set(startVal.toString()); 25 | 26 | //set invisible variable for garbage collector 27 | scope.set("." + this.name, this); 28 | } 29 | 30 | String.prototype.set = function(val, conditional) 31 | { 32 | if(typeof val == "string") 33 | command("entitydata {0} {CustomName:\"{1}\"}".format(this.selector, val.toString()), conditional); 34 | else 35 | throw "Cannot assing '" + val.constructor.name + "' to a String"; 36 | }; 37 | 38 | String.prototype.clean = function() 39 | { 40 | command("kill {0}".format(this.selector)); 41 | }; 42 | 43 | String.prototype.toTellrawExtra = function() 44 | { 45 | return JSON.stringify({selector: this.selector}); 46 | }; 47 | 48 | String.prototype.isExact = function(val) 49 | { 50 | return "testfor {0} {CustomName:\"{1}\"}".format(this.selector, val); 51 | }; 52 | 53 | module.exports = String; 54 | -------------------------------------------------------------------------------- /src/types/Table.js: -------------------------------------------------------------------------------- 1 | var Integer = require("./Integer.js"); 2 | var Score = require("./Score.js"); 3 | var nextName = require("./../lib/naming.js"); 4 | 5 | function Table(val, name, silent) 6 | { 7 | this.name = name || nextName("table"); 8 | 9 | Table.used = true; 10 | 11 | Object.defineProperty(this, "length", { 12 | get: function() 13 | { 14 | var val = new Integer(); 15 | val.isClone = true; 16 | command("execute @e[type=ArmorStand,tag={0}] ~ ~ ~ scoreboard players add {1} {2} 1" 17 | .format(this.name, val.name, Integer.scoreName)); 18 | return val; 19 | } 20 | }); 21 | 22 | Object.defineProperty(this, "maxn", { 23 | get: function() 24 | { 25 | var val = new Integer(); 26 | val.isClone = true; 27 | var selfSel = "@e[type=ArmorStand,c=1,r=0,tag={0}]".format(table.name); 28 | 29 | command("execute @e[type=ArmorStand,tag={0}] ~ ~ ~ scoreboard players operation {1} {2} > {3} {4}" 30 | .format(table.name, val.name, Integer.scoreName, selfSel, Table.indexScoreName)); 31 | return val; 32 | } 33 | }); 34 | 35 | if(val && !silent) 36 | this.set(val); 37 | } 38 | 39 | Table.scoreName = Integer.scoreName; 40 | Table.used = false; 41 | Table.indexScoreName = "MoonCraftTable"; 42 | Table.tmpScoreName = "MoonCraftTmp"; 43 | 44 | Table.prototype.set = function(val) 45 | { 46 | this.clean(); 47 | 48 | if(val instanceof Table) 49 | { 50 | //super non hacky fix for table armorstands at same position 51 | command("spreadplayers ~ ~ 1 50 false @e[tag={0}]".format(val.name)); 52 | 53 | var otherSel = "@e[type=ArmorStand,tag={0}]".format(val.name); 54 | var selfSel = "@e[type=ArmorStand,r=0,tag={0}]".format(val.name); 55 | var newSel = "@e[type=ArmorStand,tag=tableTmp,r=0]"; 56 | 57 | command("execute {0} ~ ~ ~ summon ArmorStand ~ ~ ~ {NoGravity:true,Tags:[\"tableTmp\"]}".format(otherSel)); 58 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} = {3} {2}".format(otherSel, newSel, Table.indexScoreName, selfSel)); 59 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} = {3} {2}".format(otherSel, newSel, Table.scoreName, selfSel)); 60 | command("entitydata @e[type=ArmorStand,tag=tableTmp] {Tags:[\"{0}\"]}".format(this.name)); 61 | } 62 | else if(val instanceof Array) 63 | { 64 | var sel = "@e[type=ArmorStand,tag=tableTmp,c=1]"; 65 | var score = new Score(sel, Table.scoreName); 66 | var index = new Score(sel, Table.indexScoreName); 67 | 68 | for(var i = 0; i < val.length; i++) 69 | { 70 | if(typeof val[i] == "object" && typeof val[i].toInteger != "function") 71 | throw "Cannot assing '" + val[i].constructor.name + "' to a Table"; 72 | 73 | var _val = typeof val[i] == "object" ? val[i].toInteger() : val[i]; 74 | 75 | command("summon ArmorStand ~ ~1 ~ {NoGravity:true,Tags:[\"tableTmp\"]}"); 76 | score.set(_val); 77 | index.set(i + 1); 78 | 79 | command("entitydata {0} {Tags:[\"{1}\"]}".format(sel, this.name)); 80 | } 81 | } 82 | else 83 | { 84 | throw "Cannot assing '" + val.constructor.name + "' to a Table"; 85 | } 86 | } 87 | 88 | Table.prototype.clean = function() 89 | { 90 | command("kill @e[type=ArmorStand,tag={0}]".format(this.name)); 91 | } 92 | 93 | Table.prototype.insert = function(index, val) 94 | { 95 | this.getScoreAt(index); 96 | 97 | if(typeof index == "number") 98 | { 99 | command("scoreboard players add @e[type=ArmorStand,tag={0},score_{1}_min={2}] {1} 1" 100 | .format(this.name, Table.indexScoreName, index)); 101 | } 102 | else if(typeof index.toInteger == "function") 103 | { 104 | command("scoreboard players add @e[type=ArmorStand,tag={0},score_{1}_min=0] {2} 1" 105 | .format(this.name, Table.tmpScoreName, Table.indexScoreName)); 106 | } 107 | 108 | var sel = "@e[type=ArmorStand,tag=tableTmp,c=1]"; 109 | var score = new Score(sel, Table.scoreName); 110 | var _index = new Score(sel, Table.indexScoreName); 111 | 112 | command("summon ArmorStand ~ ~1 ~ {NoGravity:true,Tags:[\"tableTmp\"]}"); 113 | score.set(val); 114 | _index.set(index); 115 | command("entitydata {0} {Tags:[\"{1}\"]}".format(sel, this.name)); 116 | } 117 | 118 | Table.prototype.remove = function(index) 119 | { 120 | var sel = this.getScoreAt(index).selector; 121 | command("kill " + sel); 122 | 123 | if(typeof index == "number") 124 | { 125 | command("scoreboard players remove @e[type=ArmorStand,tag={0},score_{1}_min={2}] {1} 1" 126 | .format(this.name, Table.indexScoreName, index)); 127 | } 128 | else if(typeof index.toInteger == "function") 129 | { 130 | command("scoreboard players remove @e[type=ArmorStand,tag={0},score_{1}_min=0] {2} 1" 131 | .format(this.name, Table.tmpScoreName, Table.indexScoreName)); 132 | } 133 | } 134 | 135 | Table.prototype.slice = function(start, end) 136 | { 137 | if(typeof start == "number") 138 | { 139 | start = start - 1; 140 | command("kill @e[type=ArmorStand,tag={0},score_{1}={2}]".format(this.name, Table.indexScoreName, start)); 141 | var index = new Score("@e[type=ArmorStand,tag={0}]".format(this.name), Table.indexScoreName); 142 | index.remove(start); 143 | 144 | if(typeof end == "number") 145 | end = end - start; 146 | else if(typeof (end || {}).toInteger == "function") 147 | end.remove(start); 148 | } 149 | else if(typeof start.toInteger == "function") 150 | { 151 | start = start.toInteger(); 152 | start.remove(1); 153 | 154 | var sel = "@e[type=ArmorStand,tag={0}]".format(this.name); 155 | var selfSel = "@e[type=ArmorStand,c=1,r=0,tag={0}]".format(this.name); 156 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} -= {3} {4}".format(sel, selfSel, Table.indexScoreName, start.name, Integer.scoreName)); 157 | command("kill @e[type=ArmorStand,tag={0},score_{1}=0]".format(this.name, Table.indexScoreName)); 158 | 159 | if(typeof end == "number") 160 | end = new Integer(end); 161 | 162 | if(typeof (end || {}).toInteger == "function") 163 | end.remove(start); 164 | } 165 | 166 | if(typeof end == "number") 167 | { 168 | command("kill @e[type=ArmorStand,tag={0},score_{1}_min={2}]".format(this.name, Table.indexScoreName, end + 1)); 169 | } 170 | else if(typeof (end || {}).toInteger == "function") 171 | { 172 | this.getScoreAt(end); 173 | command("kill @e[type=ArmorStand,tag={0},score_{1}_min=1]".format(this.name, Table.tmpScoreName)); 174 | } 175 | } 176 | 177 | Table.prototype.setAt = function(index, val) 178 | { 179 | var score = this.getScoreAt(index); 180 | command("kill " + score.selector); 181 | 182 | command("summon ArmorStand %1:jmp% {NoGravity:true,Tags:[\"tableTmp\"]}".format(this.name)); 183 | var sel = "@e[type=ArmorStand,tag=tableTmp]"; 184 | if(typeof index == "number") 185 | { 186 | var indexScore = new Score(sel, Table.indexScoreName); 187 | indexScore.set(index); 188 | } 189 | else 190 | { 191 | var indexScore = new Score(sel, Table.indexScoreName); 192 | indexScore.set(index); 193 | } 194 | 195 | var valScore = new Score(sel, Table.scoreName); 196 | valScore.set(val); 197 | 198 | command("entitydata {0} {Tags:[\"{1}\"]}".format(sel, this.name)); 199 | } 200 | 201 | Table.prototype.get = function(index) 202 | { 203 | var score = this.getScoreAt(index); 204 | var val = score.toInteger(); 205 | val.isClone = true; 206 | return val; 207 | } 208 | 209 | Table.prototype.getScoreAt = function(index) 210 | { 211 | if(typeof index == "number") 212 | { 213 | var sel = "@e[type=ArmorStand,tag={0},score_{1}_min={2},score_{1}={2}]".format(this.name, Table.indexScoreName, index); 214 | return new Score(sel, Table.scoreName); 215 | } 216 | else if(typeof index.toInteger == "function") 217 | { 218 | index = index.toInteger(); 219 | var sel = "@e[type=ArmorStand,tag={0}]".format(this.name); 220 | var selfSel = "@e[type=ArmorStand,c=1,r=0,tag={0}]".format(this.name); 221 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} = {1} {3}".format(sel, selfSel, Table.tmpScoreName, Table.indexScoreName)); 222 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} -= {3} {4}".format(sel, selfSel, Table.tmpScoreName, index.name, Integer.scoreName)); 223 | 224 | var valSel = "@e[type=ArmorStand,tag={0},score_{1}_min=0,score_{1}=0]".format(this.name, Table.tmpScoreName); 225 | return new Score(valSel, Table.scoreName); 226 | } 227 | else 228 | { 229 | throw "Cannot get value from a Table using an index of type '" + index.constructor.name + "'"; 230 | } 231 | } 232 | 233 | Table.prototype.toTellrawExtra = function() 234 | { 235 | var len = this.length.toTellrawExtra(); 236 | return "\"table[\",{0},\"]\"".format(len); 237 | } 238 | 239 | module.exports = Table; 240 | -------------------------------------------------------------------------------- /stdlib/chat.js: -------------------------------------------------------------------------------- 1 | exports.out = function(val) 2 | { 3 | var val = val.toTellrawExtra ? val.toTellrawExtra() : JSON.stringify(val.toString()); 4 | command("tellraw @a [\"Output: \",{0}]".format(val)); 5 | } 6 | 7 | exports.chat_message = function(text, color, format, click, hover) 8 | { 9 | text = text || ""; 10 | var msg = {text: text}; 11 | 12 | if(color) 13 | msg.color = color; 14 | 15 | format = format || {}; 16 | if(format.bold) 17 | msg.bold = format.bold; 18 | if(format.italic) 19 | msg.italic = format.italic; 20 | if(format.underlined) 21 | msg.underlined = format.underlined; 22 | if(format.strikethrough) 23 | msg.strikethrough = format.strikethrough; 24 | 25 | if(click) 26 | msg.clickEvent = click; 27 | if(hover) 28 | msg.hoverEvent = hover; 29 | 30 | return msg; 31 | } 32 | 33 | exports.chat_format = function(bold, italic, underlined, strikethrough) 34 | { 35 | var format = {}; 36 | if(bold) 37 | format.bold = true; 38 | if(italic) 39 | format.italic = true; 40 | if(underlined) 41 | format.underlined = true; 42 | if(strikethrough) 43 | format.strikethrough = true; 44 | 45 | return format; 46 | } 47 | 48 | exports.chat_event = function(action, value) 49 | { 50 | return {action: action, value: value}; 51 | } 52 | 53 | exports.chat_message_array = function() 54 | { 55 | var extras = []; 56 | for(var i = 0; i < arguments.length; i++) 57 | extras[i] = arguments[i].toTellrawExtra ? arguments[i].toTellrawExtra() : JSON.stringify(arguments[i]); 58 | 59 | return "[{0}]".format(extras.join(",")); 60 | } 61 | 62 | exports.tellraw = function() 63 | { 64 | var msg = exports.chat_message_array.apply(exports, arguments); 65 | command("tellraw @a {0}".format(msg)); 66 | } 67 | -------------------------------------------------------------------------------- /stdlib/debug.js: -------------------------------------------------------------------------------- 1 | var tellraw = scope.get("tellraw"); 2 | var chat_message = scope.get("chat_message"); 3 | var chat_event = scope.get("chat_event"); 4 | 5 | var scoreName = scope.get("OBJECTIVE_NAME"); 6 | var tmpScoreName = "MoonCraftTmp"; 7 | 8 | var debug_break = scope.get("debug_break"); 9 | var debug_backtrace = scope.get("debug_backtrace"); 10 | 11 | exports.debug = function() 12 | { 13 | exports.debug_variables(); 14 | tellraw(""); 15 | 16 | debug_backtrace(); 17 | tellraw(""); 18 | 19 | debug_break(); 20 | } 21 | 22 | exports.debug_variables = function() 23 | { 24 | maxCount = 100; 25 | var stack = scope.stack; 26 | var changeSupports = ["Integer", "Float", "Boolean", "Score"]; 27 | 28 | for(var i = stack.length - 1; i >= 0 && maxCount > 0; i--) 29 | { 30 | var curr = stack[i]; 31 | for(var key in curr) 32 | { 33 | if(key[0] == "." || typeof curr[key] == "function") 34 | continue; 35 | 36 | var val = curr[key]; 37 | 38 | 39 | var change = ""; 40 | if(changeSupports.indexOf(val.constructor.name) != -1) 41 | { 42 | var sel = val.name || val.selector; 43 | var objective = val.scoreName || scoreName; 44 | 45 | var ev = chat_event("suggest_command", "/scoreboard players set {0} {1} ".format(sel, objective)); 46 | change = chat_message(" [change]", "blue", false, ev); 47 | } 48 | 49 | var typeStr = typeof val == "object" ? val.constructor.name : typeof val; 50 | 51 | var type = chat_message(typeStr[0], false, false, false, chat_event("show_text", typeStr)); 52 | 53 | if(typeStr[0] == "I") //align and stuff 54 | tellraw(type, chat_message(".", "dark_gray"), chat_message(" : ", "green"), key, chat_message(" = ", "red"), curr[key], change); 55 | else 56 | tellraw(type, chat_message(" : ", "green"), key, chat_message(" = ", "red"), curr[key], change); 57 | 58 | maxCount--; 59 | if(maxCount == 0) 60 | break; 61 | } 62 | } 63 | } 64 | 65 | exports.debug_stackcount = function(val) 66 | { 67 | var selfSel = "@e[type=ArmorStand,c=1,r=0,tag=stack]"; 68 | command("execute @e[type=ArmorStand,tag=stack] ~ ~ ~ scoreboard players operation {0} {1} > {2} {3}" 69 | .format(val.name, scoreName, selfSel, scoreName)); 70 | } 71 | 72 | exports.debug_select_stack = function(index) 73 | { 74 | var sel = "@e[type=ArmorStand,tag=stack]"; 75 | var selfSel = "@e[type=ArmorStand,c=1,r=0,tag=stack]"; 76 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} = {1} {3}".format(sel, selfSel, tmpScoreName, scoreName)); 77 | command("execute {0} ~ ~ ~ scoreboard players operation {1} {2} -= {3} {4}".format(sel, selfSel, tmpScoreName, index.name, scoreName)); 78 | 79 | var _sel = "@e[type=ArmorStand,tag=stack,score_{0}_min=0,score_{0}=0]".format(tmpScoreName); 80 | return {selector: _sel}; 81 | } 82 | -------------------------------------------------------------------------------- /stdlib/debug.lua: -------------------------------------------------------------------------------- 1 | import("chat") 2 | 3 | function debug_backtrace() 4 | count = 0 5 | debug_stackcount(count) 6 | 7 | tellraw(chat_message("Stacktrace:", "red")) 8 | 9 | for i = 2, count do 10 | tellraw("- ", debug_select_stack(i)) 11 | end 12 | end 13 | 14 | function debug_break() 15 | await = 0 16 | 17 | tellraw( 18 | chat_message("Breakpoint reached. ", "red"), 19 | chat_message("[continue]", "blue", false, 20 | chat_event("run_command", "/scoreboard players set " .. js_eval("await.name") .. " " .. OBJECTIVE_NAME .. " 1") 21 | ) 22 | ) 23 | 24 | repeat 25 | -- wait... 26 | until await == 1 27 | end 28 | 29 | import("./debug.js") 30 | -------------------------------------------------------------------------------- /stdlib/math.lua: -------------------------------------------------------------------------------- 1 | PI = 3.14 2 | EULER = 2.72 3 | 4 | function abs(val) 5 | if val < 0 then 6 | return -val 7 | else 8 | return val 9 | end 10 | end 11 | 12 | function floor(val) 13 | local intval = int(val) 14 | local diff = val - intval 15 | 16 | if diff < 0 then 17 | return intval - 1 18 | else 19 | return intval 20 | end 21 | end 22 | 23 | function round(val) 24 | local intval = int(val) 25 | local diff = val - intval 26 | 27 | if (diff > 0 and diff < 0.5) or (diff < 0 and diff >= -0.5) or diff == 0 then 28 | return intval 29 | elseif diff > 0 then 30 | return intval + 1 31 | else --diff < 0 32 | return intval - 1 33 | end 34 | end 35 | 36 | function ceil(val) 37 | local intval = int(val) 38 | local diff = val - intval 39 | 40 | if diff > 0 then 41 | return intval + 1 42 | else 43 | return intval 44 | end 45 | end 46 | 47 | function pow(base, exponent) 48 | local result = 1 49 | 50 | while exponent > 0 do 51 | result = result * base 52 | exponent = exponent - 1 53 | end 54 | 55 | return result 56 | end 57 | 58 | function sqrt(value) 59 | local curr = int(value) 60 | local currplusone = curr 61 | 62 | local curr2 = 0 63 | local currpone2 = 0 64 | 65 | if curr < 0 then 66 | local damnitfixthebugs = 0 67 | return damnitfixthebugs 68 | end 69 | 70 | repeat 71 | curr = (curr + value / curr) / 2 --ty Heron of Alexandria 72 | currplusone = curr + 1 73 | curr2 = curr * curr 74 | currpone2 = currplusone * currplusone 75 | until curr2 <= value and value < currpone2 76 | 77 | if value - curr2 < currpone2 - value then 78 | return curr 79 | else 80 | return currplusone 81 | end 82 | end 83 | 84 | function sin(value) 85 | 86 | --https://upload.wikimedia.org/math/a/3/b/a3b692cd234b734e121ef24621f3635b.png 87 | 88 | local value = (-value + 3.14) % 6.28 89 | 90 | local result = value 91 | 92 | local numerator = value 93 | numerator = numerator * value 94 | numerator = numerator * value 95 | result = result - numerator / 6 96 | 97 | numerator = numerator * value 98 | numerator = numerator * value 99 | result = result + numerator / 120 100 | 101 | numerator = numerator * value 102 | numerator = numerator * value 103 | result = result - numerator / 5040 104 | 105 | numerator = numerator * value 106 | numerator = numerator * value 107 | result = result + numerator / 362880 108 | 109 | return result 110 | 111 | end 112 | 113 | function cos(value) 114 | return sin(value + 3.14 / 2) 115 | end 116 | -------------------------------------------------------------------------------- /stdlib/query.js: -------------------------------------------------------------------------------- 1 | var scoreName = scope.get("OBJECTIVE_NAME"); 2 | 3 | exports.query = function(val, kind, cmd) 4 | { 5 | var selector = "@e[type=ArmorStand,tag=query]"; 6 | command("summon ArmorStand ~ ~ ~ {Tags:[\"query\"],NoGravity:true}"); 7 | command("scoreboard players set {0} {1} -1".format(selector, scoreName)); 8 | command("stats block %1:diff% set {1} {0} {2}".format(selector, kind, scoreName)); 9 | command(cmd); 10 | command("scoreboard players operation {0} {2} = {1} {2}".format(val.name, selector, scoreName)); 11 | command("kill {0}".format(selector)); 12 | }; 13 | -------------------------------------------------------------------------------- /stdlib/random.js: -------------------------------------------------------------------------------- 1 | exports._rand_fast = function(result, rnd, both) 2 | { 3 | for(var i = 0; i < 30; i++) 4 | { 5 | result.add(rnd); 6 | both.multiplicate(2); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /stdlib/random.lua: -------------------------------------------------------------------------------- 1 | import("./random.js") 2 | 3 | function rand_fast() 4 | command("summon ArmorStand ~ ~ ~ {NoGravity:true,Tags:[\"random\"]}") 5 | command("summon ArmorStand ~ ~ ~ {NoGravity:true,Tags:[\"random\"]}") 6 | 7 | local rnd = score("@r[type=ArmorStand,tag=random]", OBJECTIVE_NAME) 8 | local both = score("@e[type=ArmorStand,tag=random]", OBJECTIVE_NAME) 9 | 10 | local result = 0 11 | rnd = 1 12 | 13 | _rand_fast(result, rnd, both) 14 | 15 | both = 1 16 | rnd = -1 17 | result = result * rnd 18 | 19 | command("kill @e[type=ArmorStand,tag=random]") 20 | return result 21 | end 22 | 23 | function rand_small() 24 | command("summon ArmorStand ~ ~ ~ {NoGravity:true,Tags:[\"random\"]}") 25 | command("summon ArmorStand ~ ~ ~ {NoGravity:true,Tags:[\"random\"]}") 26 | 27 | local rnd = score("@r[type=ArmorStand,tag=random]", OBJECTIVE_NAME) 28 | local both = score("@e[type=ArmorStand,tag=random]", OBJECTIVE_NAME) 29 | 30 | local result = 0 31 | rnd = 1 32 | 33 | for i = 0, 29 do 34 | result = result + rnd 35 | both = both * 2 36 | end 37 | 38 | both = 1 39 | rnd = -1 40 | result = result * rnd 41 | 42 | command("kill @e[type=ArmorStand,tag=random]") 43 | return result 44 | end 45 | -------------------------------------------------------------------------------- /stdlib/time.lua: -------------------------------------------------------------------------------- 1 | import("./query.js") 2 | 3 | function daytime() 4 | val = 0 5 | query(val, "QueryResult", "time query daytime") 6 | return val 7 | end 8 | 9 | function gametime() 10 | val = 0 11 | query(val, "QueryResult", "time query gametime") 12 | return val 13 | end 14 | 15 | function day() 16 | val = 0 17 | query(val, "QueryResult", "time query day") 18 | return val 19 | end 20 | -------------------------------------------------------------------------------- /stdlib/title.js: -------------------------------------------------------------------------------- 1 | var chat_message_array = require("./chat.js").chat_message_array; 2 | 3 | exports.title = function() 4 | { 5 | var msg = chat_message_array.apply(undefined, arguments); 6 | command("title @a title {0}".format(msg)); 7 | } 8 | 9 | exports.subtitle = function() 10 | { 11 | var msg = chat_message_array.apply(undefined, arguments); 12 | command("title @a subtitle {0}".format(msg)); 13 | } 14 | 15 | exports.title_clear = function() 16 | { 17 | command("title @a clear"); 18 | } 19 | 20 | exports.title_times = function(fadeIn, stay, fadeOut) 21 | { 22 | fadeIn = parseInt(fadeIn) || 0; 23 | stay = parseInt(stay) || 1; 24 | fadeOut = parseInt(fadeOut) || 0; 25 | 26 | command("title @a times {0} {1} {2}".format(fadeIn, stay, fadeOut)); 27 | } 28 | 29 | exports.title_reset = function() 30 | { 31 | command("title @a reset"); 32 | } 33 | --------------------------------------------------------------------------------