├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── doc ├── api.md └── examples.js ├── index.js ├── lib ├── block-entity.js ├── block.js └── entity.js ├── package.json └── test ├── plane.schematic └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test/plane.schematic -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 1b8 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # schematic 2 | 3 | [![NPM version](https://img.shields.io/npm/v/mc-schematic.svg)](http://npmjs.com/package/mc-schematic) 4 | 5 | Read Minecraft MCEdit/WorldEdit schematics. 6 | 7 | ```js 8 | var fs = require('fs'); 9 | var Schematic = require('schematic')('1.8'); 10 | 11 | fs.readFile('test/test1.schematic', function (err, data) { 12 | Schematic.parse(data, function (err, schem) { 13 | console.log(schem.getBlock(0, 0, 0)); 14 | }); 15 | }); 16 | ``` 17 | 18 | ### [Documentation](https://github.com/1b8/schematic/blob/master/doc/api.md) 19 | ### [Example](https://github.com/1b8/schematic/blob/master/doc/examples.js) 20 | -------------------------------------------------------------------------------- /doc/api.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [Classes](#classes) 6 | - [Schematic](#schematic) 7 | - [Static functions](#static-functions) 8 | - [Schematic.parse(data, callback)](#schematicparsedata-callback) 9 | - [Instance properties](#instance-properties) 10 | - [schematic.raw](#schematicraw) 11 | - [schematic.width](#schematicwidth) 12 | - [schematic.height](#schematicheight) 13 | - [schematic.length](#schematiclength) 14 | - [schematic.entities](#schematicentities) 15 | - [schematic.blockEntities](#schematicblockentities) 16 | - [Methods](#methods) 17 | - [schematic.getBlock(x, y, z)](#schematicgetblockx-y-z) 18 | - [Entity](#entity) 19 | - [entity.dimension](#entitydimension) 20 | - [entity.raw](#entityraw) 21 | - [entity.id](#entityid) 22 | - [entity.position](#entityposition) 23 | - [entity.velocity](#entityvelocity) 24 | - [entity.yaw](#entityyaw) 25 | - [entity.pitch](#entitypitch) 26 | - [entity.fallDistance](#entityfalldistance) 27 | - [entity.fireTicks](#entityfireticks) 28 | - [entity.air](#entityair) 29 | - [entity.onGround](#entityonground) 30 | - [entity.invulnerable](#entityinvulnerable) 31 | - [entity.portalCooldown](#entityportalcooldown) 32 | - [entity.uuid](#entityuuid) 33 | - [entity.customName](#entitycustomname) 34 | - [entity.customNameVisible](#entitycustomnamevisible) 35 | - [entity.silent](#entitysilent) 36 | - [entity.rider](#entityrider) 37 | - [entity.glowing](#entityglowing) 38 | - [entity.nbt](#entitynbt) 39 | - [entity.commandStats](#entitycommandstats) 40 | - [entity.commandStats.successCountObjective](#entitycommandstatssuccesscountobjective) 41 | - [entity.commandStats.successCountName](#entitycommandstatssuccesscountname) 42 | - [entity.commandStats.affectedBlocksObjective](#entitycommandstatsaffectedblocksobjective) 43 | - [entity.commandStats.affectedBlocksName](#entitycommandstatsaffectedblocksname) 44 | - [entity.commandStats.affectedEntitiesObjective](#entitycommandstatsaffectedentitiesobjective) 45 | - [entity.commandStats.affectedEntitiesName](#entitycommandstatsaffectedentitiesname) 46 | - [entity.commandStats.affectedItemsObjective](#entitycommandstatsaffecteditemsobjective) 47 | - [entity.commandStats.affectedItemsName](#entitycommandstatsaffecteditemsname) 48 | - [entity.commandStats.queryResultObjective](#entitycommandstatsqueryresultobjective) 49 | - [entity.commandStats.queryResultName](#entitycommandstatsqueryresultname) 50 | - [BlockEntity](#blockentity) 51 | - [blockEntity.raw](#blockentityraw) 52 | - [Container](#container) 53 | - [blockEntity.customName](#blockentitycustomname) 54 | - [blockEntity.lockKey](#blockentitylockkey) 55 | - [blockEntity.items](#blockentityitems) 56 | - [blockEntity](#blockentity) 57 | - [Banner](#banner) 58 | - [blockEntity.background](#blockentitybackground) 59 | - [blockEntity.patterns](#blockentitypatterns) 60 | - [Beacon](#beacon) 61 | - [blockEntity.lockKey](#blockentitylockkey-1) 62 | - [blockEntity.levels](#blockentitylevels) 63 | - [blockEntity.powers](#blockentitypowers) 64 | - [blockEntity.powers.primary](#blockentitypowersprimary) 65 | - [blockEntity.powers.secondary](#blockentitypowerssecondary) 66 | - [Brewing stand](#brewing-stand) 67 | - [blockEntity.brewTime](#blockentitybrewtime) 68 | - [blockEntity.fuel](#blockentityfuel) 69 | - [Chest](#chest) 70 | - [blockEntity.lootTable](#blockentityloottable) 71 | - [blockEntity.lootTableSeed](#blockentityloottableseed) 72 | - [Redstone Comparator](#redstone-comparator) 73 | - [blockEntity.outputSignal](#blockentityoutputsignal) 74 | - [Command Block](#command-block) 75 | - [blockEntity.customName](#blockentitycustomname-1) 76 | - [blockEntity.lockKey](#blockentitylockkey-2) 77 | - [blockEntity.commandStats](#blockentitycommandstats) 78 | - [blockEntity.command](#blockentitycommand) 79 | - [blockEntity.successCount](#blockentitysuccesscount) 80 | - [blockEntity.trackOutput](#blockentitytrackoutput) 81 | - [blockEntity.powered](#blockentitypowered) 82 | - [blockEntity.auto](#blockentityauto) 83 | - [Dropper](#dropper) 84 | - [Enchantment Table](#enchantment-table) 85 | - [blockEntity.customName](#blockentitycustomname-2) 86 | - [End Gateway](#end-gateway) 87 | - [blockEntity.age](#blockentityage) 88 | - [blockEntity.exactTeleport](#blockentityexactteleport) 89 | - [blockEntity.exitPortal](#blockentityexitportal) 90 | - [Flower Pot](#flower-pot) 91 | - [blockEntity.flower](#blockentityflower) 92 | - [Furnace](#furnace) 93 | - [blockEntity.burnTimeLeft](#blockentityburntimeleft) 94 | - [blockEntity.cookTime](#blockentitycooktime) 95 | - [blockEntity.cookTimeTotal](#blockentitycooktimetotal) 96 | - [Hopper](#hopper) 97 | - [blockEntity.transferCooldown](#blockentitytransfercooldown) 98 | - [Note block](#note-block) 99 | - [blockEntity.note](#blockentitynote) 100 | - [blockEntity.powered](#blockentitypowered-1) 101 | 102 | 103 | 104 | # Classes 105 | 106 | ## Schematic 107 | `Schematic` is the main class; `require('schematic')(version)` returns this. 108 | 109 | ### Static functions 110 | 111 | #### Schematic.parse(data, callback) 112 | Read a `Buffer` and execute the callback with these args: 113 | * `err` - Any error 114 | * `data` - The parsed `Schematic` object 115 | 116 | ### Instance properties 117 | 118 | #### schematic.raw 119 | 'raw' schematic object, returned from prismarine-nbt`.simplify()`. 120 | 121 | #### schematic.width 122 | Size along the x axis. 123 | 124 | #### schematic.height 125 | Size along the y axis. 126 | 127 | #### schematic.length 128 | Size along the z axis. 129 | 130 | #### schematic.entities 131 | `Array` of entities in the schematic. 132 | See [Entity](#entity). 133 | 134 | #### schematic.blockEntities 135 | `Array` of block entities in the schematic (not intended for direct use; 136 | `schematic.blockAt()` will return a block entity if there is a block entity at 137 | the specified position). 138 | See [BlockEntity](#blockentity). 139 | 140 | ### Methods 141 | 142 | #### schematic.getBlock(x, y, z) 143 | Arguments can either be three numbers or one Vec3 instance. 144 | Returns the block at the `x`, `y`, and `z` co-ordinates. 145 | See [prismarine-block](https://github.com/PrismarineJS/prismarine-block). 146 | 147 | ## Entity 148 | 149 | ### entity.dimension 150 | `"nether"`, `"overworld"`, or `"end"`. 151 | 152 | ### entity.raw 153 | Raw data 154 | 155 | ### entity.id 156 | The name of the entity, such as `"Zombie"`, or `"EntityHorse"`. 157 | 158 | ### entity.position 159 | [`Vec3`](https://github.com/andrewrk/node-vec3), the position of the entity. 160 | 161 | ### entity.velocity 162 | [`Vec3`](https://github.com/andrewrk/node-vec3), the speed at which the entity 163 | is moving, in blocks per tick. 164 | 165 | ### entity.yaw 166 | 167 | ### entity.pitch 168 | 169 | ### entity.fallDistance 170 | The amount of distance the entity has fallen, or 0 if the entity is not falling. 171 | 172 | ### entity.fireTicks 173 | The number of ticks until the entity stops being on fire. 174 | If negative, how many ticks while standing in fire for the entity to start burning. 175 | 176 | ### entity.air 177 | The number of ticks while underwater until the entity starts drowning. 178 | 179 | ### entity.onGround 180 | Boolean. 181 | 182 | ### entity.invulnerable 183 | Boolean. 184 | 185 | ### entity.portalCooldown 186 | Number of ticks until the entity can be teleported through a portal. 187 | 188 | ### entity.uuid 189 | The entity's UUID. Looks like: 190 | ```json 191 | [ 192 | [ 193 | 739277774, 194 | -1808448075 195 | ], 196 | [ 197 | -1817433807, 198 | 1980514233 199 | ] 200 | ] 201 | ``` 202 | 203 | ### entity.customName 204 | `CustomName` of the entity, or an empty string. 205 | 206 | ### entity.customNameVisible 207 | Boolean. 208 | 209 | ### entity.silent 210 | Boolean. 211 | 212 | ### entity.rider 213 | 1.9 only, another `Entity`. 214 | 215 | ### entity.glowing 216 | (1.9 effects) Boolean. 217 | 218 | ### entity.nbt 219 | Extra data about the entity. 220 | 221 | ### entity.commandStats 222 | #### entity.commandStats.successCountObjective 223 | #### entity.commandStats.successCountName 224 | #### entity.commandStats.affectedBlocksObjective 225 | #### entity.commandStats.affectedBlocksName 226 | #### entity.commandStats.affectedEntitiesObjective 227 | #### entity.commandStats.affectedEntitiesName 228 | #### entity.commandStats.affectedItemsObjective 229 | #### entity.commandStats.affectedItemsName 230 | #### entity.commandStats.queryResultObjective 231 | #### entity.commandStats.queryResultName 232 | 233 | ## BlockEntity 234 | 235 | Inherits from [prismarine-block](https://github.com/prismarinejs/prismarine-block) 236 | 237 | ### blockEntity.raw 238 | 239 | ### Container 240 | 241 | #### blockEntity.customName 242 | Custom name of this container. May not exist, or may exist and be empty. 243 | 244 | #### blockEntity.lockKey 245 | If set, a player must hold an item with this string as its name to open the container. 246 | 247 | #### blockEntity.items 248 | `Array` of [prismarine-item](https://github.com/prismarinejs/prismarine-item)s, 249 | EXCEPT `item.nbt` is an `Object` instead of a `Buffer`. 250 | 251 | #### blockEntity 252 | 253 | ### Banner 254 | 255 | #### blockEntity.background 256 | #### blockEntity.patterns 257 | Looks like: 258 | ```json 259 | { 260 | "color": 4, 261 | "pattern": "Border" 262 | } 263 | ``` 264 | 265 | ### Beacon 266 | 267 | #### blockEntity.lockKey 268 | #### blockEntity.levels 269 | Number of pyramid levels. 270 | 271 | #### blockEntity.powers 272 | ##### blockEntity.powers.primary 273 | ##### blockEntity.powers.secondary 274 | 275 | ### Brewing stand 276 | Container. 277 | #### blockEntity.brewTime 278 | #### blockEntity.fuel 279 | Added in 1.9. 280 | 281 | ### Chest 282 | Container. 283 | #### blockEntity.lootTable 284 | Added in 1.9. 285 | #### blockEntity.lootTableSeed 286 | Added in 1.9. 287 | 288 | ### Redstone Comparator 289 | #### blockEntity.outputSignal 290 | 291 | ### Command Block 292 | #### blockEntity.customName 293 | #### blockEntity.lockKey 294 | #### blockEntity.commandStats 295 | See [`entity.commandStats`](#entitycommandstats) 296 | #### blockEntity.command 297 | The command the block will execute. 298 | #### blockEntity.successCount 299 | #### blockEntity.trackOutput 300 | Boolean. 301 | #### blockEntity.powered 302 | Added in 1.9. 303 | #### blockEntity.auto 304 | Added in 1.9. 305 | 306 | ### Dropper 307 | Container. 308 | 309 | ### Enchantment Table 310 | #### blockEntity.customName 311 | 312 | ### End Gateway 313 | Added in 1.9. 314 | #### blockEntity.age 315 | #### blockEntity.exactTeleport 316 | Boolean. 317 | #### blockEntity.exitPortal 318 | Vec3. 319 | 320 | ### Flower Pot 321 | #### blockEntity.flower 322 | Block. 323 | 324 | ### Furnace 325 | Container. 326 | #### blockEntity.burnTimeLeft 327 | In ticks. 328 | #### blockEntity.cookTime 329 | Time it's been cooking for, in ticks. 330 | #### blockEntity.cookTimeTotal 331 | Time it will take to cook, in ticks. 332 | 333 | ### Hopper 334 | Container. 335 | #### blockEntity.transferCooldown 336 | 337 | ### Note block 338 | #### blockEntity.note 339 | Pitch, integer. 340 | #### blockEntity.powered 341 | Added in 1.9. 342 | 343 | TODO: More block entity types. 344 | -------------------------------------------------------------------------------- /doc/examples.js: -------------------------------------------------------------------------------- 1 | // Example 2 | 3 | var fs = require('fs'); 4 | var Schematic = require('../')('1.8'); 5 | 6 | fs.readFile('../test/plane.schematic', function (err, data) { 7 | if (err) throw err; 8 | 9 | Schematic.parse(data, function (err, schem) { 10 | if (err) throw err; 11 | 12 | console.log(schem.getBlock(0, 0, 0)); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var nbt = require('prismarine-nbt'); 2 | var vec3 = require('vec3'); 3 | 4 | module.exports = function (version) { 5 | var Block = require('./lib/block')(version); 6 | var BlockEntity = require('./lib/block-entity')(version); 7 | var Entity = require('./lib/entity'); 8 | 9 | Schematic.parse = function (data, callback) { 10 | if (!callback) callback = function (err) { 11 | if (err) throw err; 12 | }; 13 | 14 | nbt.parse(data, function (err, data) { 15 | if (err) callback(err); 16 | callback(err, new Schematic(nbt.simplify(data))); 17 | }); 18 | }; 19 | 20 | function Schematic(raw) { 21 | this._ = raw; 22 | var entities = this._.Entities; 23 | var blockEntities = this._.TileEntities; 24 | this.raw = raw; 25 | this.width = this._.Width; 26 | this.height = this._.Height; 27 | this.length = this._.Length; 28 | this.entities = []; 29 | this.blockEntities = []; 30 | if(entities) { 31 | for (var i = 0; i < entities.length; i++) 32 | this.entities.push(new Entity(entities[i])); 33 | } 34 | if(blockEntities) { 35 | for (i = 0; i < blockEntities.length; i++) 36 | this.blockEntities.push(new BlockEntity(this, blockEntities[i])); 37 | } 38 | } 39 | 40 | Schematic.prototype.getBlock = function (x, y, z) { 41 | var pos = typeof x === 'number' ? vec3(x, y, z) : x; 42 | 43 | // Check if it's a block entity 44 | var blockEntity; 45 | for (var i = 0; i < this.blockEntities.length; i++) { 46 | blockEntity = this.blockEntities[i]; 47 | if (blockEntity.position.equals(pos)) return blockEntity; 48 | } 49 | 50 | var args = this._blockArgs(pos); 51 | return new Block(args[0], args[1], args[2]); 52 | }; 53 | 54 | // Returns the arguments to pass into new Block 55 | Schematic.prototype._blockArgs = function (pos) { 56 | var index = (pos.y * this.length + pos.z) * this.width + pos.x; 57 | return [this._.Blocks[index]&0xff, this._.Data[index], pos]; 58 | }; 59 | 60 | return Schematic; 61 | }; 62 | -------------------------------------------------------------------------------- /lib/block-entity.js: -------------------------------------------------------------------------------- 1 | var vec3 = require('vec3'); 2 | var commandStats = require('./entity').commandStats; 3 | var util = require('util'); 4 | 5 | module.exports = function (version) { 6 | var Block = require('./block')(version); 7 | var Item = require('prismarine-item')(version); 8 | var itemsById = require('minecraft-data')(version).items; 9 | 10 | function container(self, raw) { 11 | if (raw.CustomName) self.customName = raw.CustomName; 12 | self.lockKey = raw.Lock; 13 | self.items = []; 14 | raw.Items.forEach(function (item) { 15 | var data = itemsById[item.id]; 16 | self.items.push(new Item(data ? data.id : 1, 17 | item.Count, item.Damage, item.tag ? item.tag : {})); 18 | }); 19 | } 20 | 21 | function BlockEntity(schem, raw) { 22 | Block.apply(this, schem._blockArgs(vec3(raw.x, raw.y, raw.z))); 23 | this.raw = raw; 24 | 25 | switch (raw.id) { 26 | case 'Banner': 27 | this.background = raw.Base; 28 | this.patterns = []; 29 | var patterns = raw.Patterns, pattern; 30 | for (var i = 0; i < patterns.length; i++) { 31 | pattern = patterns[i]; 32 | this.patterns.push({ 33 | color: pattern.Color, 34 | pattern: pattern.Pattern 35 | }); 36 | } 37 | break; 38 | case 'Beacon': 39 | this.lockKey = raw.Lock; 40 | this.levels = raw.Levels; 41 | this.powers = { 42 | primary: raw.Primary, 43 | secondary: raw.Secondary 44 | }; 45 | break; 46 | case 'Cauldron': 47 | // Brewing stand 48 | container(this, raw); 49 | this.brewTime = raw.BrewTime; 50 | if (raw.Fuel) this.fuel = raw.Fuel; 51 | break; 52 | case 'Chest': 53 | container(this, raw); 54 | if (raw.LootTable) this.lootTable = raw.LootTable; 55 | if (raw.LootTableSeed) this.lootTableSeed = raw.LootTableSeed; 56 | break; 57 | case 'Comparator': 58 | this.outputSignal = raw.OutputSignal; 59 | break; 60 | case 'Control': 61 | // Command block 62 | if (raw.CustomName) this.customName = raw.CustomName; 63 | this.lockKey = raw.Lock; 64 | commandStats(this, raw); 65 | this.command = raw.Command; 66 | this.successCount = raw.SuccessCount; 67 | this.trackOutput = Boolean(raw.TrackOutput); 68 | if (typeof raw.powered !== 'undefined') this.powered = Boolean(raw.powered); 69 | if (typeof raw.auto !== 'undefined') this.auto = Boolean(raw.auto); 70 | break; 71 | case 'Dropper': 72 | container(this, raw); 73 | break; 74 | case 'EnchantTable': 75 | if (raw.CustomName) this.customName = raw.CustomName; 76 | break; 77 | case 'EndGateway': 78 | this.age = raw.Age; 79 | this.exactTeleport = Boolean(raw.ExactTeleport); 80 | var exit = raw.ExitPortal; 81 | this.exitPortal = vec3(exit.X, exit.Y, exit.Z); 82 | break; 83 | case 'FlowerPot': 84 | this.flower = new Block(raw.Item, raw.Data); 85 | break; 86 | case 'Furnace': 87 | container(this, raw); 88 | this.burnTimeLeft = raw.BurnTime; 89 | this.cookTime = raw.CookTime; 90 | this.cookTimeTotal = raw.CookTimeTotal; 91 | break; 92 | case 'Hopper': 93 | container(this, raw); 94 | this.transferCooldown = raw.TransferCooldown; 95 | break; 96 | case 'MobSpawner': 97 | // TODO 98 | break; 99 | case 'Music': 100 | this.note = raw.note; 101 | if (typeof raw.powered !== 'undefined') this.powered = Boolean(raw.powered); 102 | break; 103 | case 'Piston': 104 | // TODO... 105 | } 106 | } 107 | util.inherits(BlockEntity, Block); 108 | return BlockEntity; 109 | }; 110 | -------------------------------------------------------------------------------- /lib/block.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | 3 | module.exports = function (version) { 4 | var PrismarineBlock = require('prismarine-block')(version); 5 | 6 | function Block(id, data, pos) { 7 | PrismarineBlock.call(this, id, null, data); 8 | this.position = pos; 9 | }; 10 | util.inherits(Block, PrismarineBlock); 11 | return Block; 12 | }; 13 | -------------------------------------------------------------------------------- /lib/entity.js: -------------------------------------------------------------------------------- 1 | var vec3 = require('vec3'); 2 | 3 | module.exports = function (raw) { 4 | var rot = raw.Rotation; 5 | switch (raw.Dimension) { 6 | case -1: 7 | this.dimension = 'nether'; 8 | break; 9 | case 0: 10 | this.dimension = 'overworld'; 11 | break; 12 | case 1: 13 | this.dimension = 'end'; 14 | } 15 | this.raw = raw; 16 | this.id = raw.id; 17 | this.position = vec3(raw.Pos); 18 | this.velocity = vec3(raw.Motion); // metres per tick 19 | this.yaw = rot[0]; 20 | this.pitch = rot[1]; 21 | this.fallDistance = raw.FallDistance; 22 | this.fireTicks = raw.Fire; 23 | this.air = raw.Air; 24 | this.onGround = Boolean(raw.OnGround); 25 | this.invulnerable = Boolean(raw.Invulnerable); 26 | this.portalCooldown = raw.PortalCooldown; 27 | this.uuid = [raw.UUIDMost, raw.UUIDLeast]; 28 | this.customName = raw.CustomName ? raw.CustomName : ''; 29 | this.customNameVisible = typeof raw.CustomNameVisible !== 'undefined' ? Boolean(raw.CustomNameVisible) : false; 30 | this.silent = typeof raw.Silent !== 'undefined' ? Boolean(raw.Silent) : false; 31 | if (raw.Passengers) this.rider = new Entity(raw.Passengers); // Added in 1.9 32 | this.glowing = typeof raw.Glowing !== 'undefined' ? Boolean(raw.Glowing) : false; 33 | this.nbt = raw.Tags ? raw.Tags : []; 34 | commandStats(this, raw); 35 | }; 36 | 37 | function commandStats(self, raw) { 38 | if (raw.CommandStats) { 39 | var stats = raw.CommandStats; 40 | self.commandStats = { 41 | successCountObjective: stats.SuccessCountObjective, 42 | successCountName: stats.SuccessCountName, 43 | affectedBlocksObjective: stats.AffectedBlocksObjective, 44 | affectedBlocksName: stats.AffectedBlocksName, 45 | affectedEntitiesObjective: stats.AffectedEntitiesObjective, 46 | affectedEntitiesName: stats.AffectedEntitiesName, 47 | affectedItemsObjective: stats.AffectedItemsObjective, 48 | affectedItemsName: stats.AffectedItemsName, 49 | queryResultObjective: stats.QueryResultObjective, 50 | queryResultName: stats.QueryResultName 51 | }; 52 | } 53 | } 54 | module.exports.commandStats = commandStats; 55 | 56 | // TODO Mobs & breedable mobs, tameable mobs, Projectiles, Items, XPOrbs, Vehicles, dynamic tiles, & other 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mc-schematic", 3 | "version": "2.0.0", 4 | "description": "Read MCEdit/WorldEdit schematics", 5 | "main": "index.js", 6 | "keywords": [ 7 | "minecraft", 8 | "nbt", 9 | "worldedit" 10 | ], 11 | "bugs": "https://github.com/1b8/schematic/issues", 12 | "license": "MIT", 13 | "author": { 14 | "name": "1b8" 15 | }, 16 | "repository": "1b8/schematic", 17 | "dependencies": { 18 | "minecraft-data": "^1.2.6", 19 | "prismarine-block": "^1.0.0", 20 | "prismarine-item": "1.0.0", 21 | "prismarine-nbt": "0.2.0", 22 | "vec3": "^0.1.3" 23 | }, 24 | "devDependencies": { 25 | "doctoc": "0.15.0" 26 | }, 27 | "scripts": { 28 | "test": "node test/test.js" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/plane.schematic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1b8/schematic/f2738a487d921050904516d9f075c08c34bbfe8e/test/plane.schematic -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var Schematic = require('../')('1.8'); 3 | 4 | fs.readFile(__dirname+'/plane.schematic', function (err, data) { 5 | if (err) throw err; 6 | 7 | Schematic.parse(data, function (err, schem) { 8 | if (err) throw err; 9 | 10 | l('Hello'); 11 | l(schem.getBlock(0,0,0).digTime(42)); 12 | // TODO tests 13 | }); 14 | }); 15 | 16 | function l() {console.log.apply(null, arguments);} 17 | --------------------------------------------------------------------------------