-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add minecraft-data 1.8 and 1.9 as submodules, start doing #4
- Loading branch information
Showing
7 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "minecraft-data-1.8"] | ||
path = minecraft-data/1.8 | ||
url = https://github.com/PrismarineJS/minecraft-data.git | ||
branch = 1.8 | ||
[submodule "minecraft-data-1.9"] | ||
path = minecraft-data/1.9 | ||
url = https://github.com/PrismarineJS/minecraft-data.git | ||
branch = 1.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
var nmcData=require("./"); | ||
var nmcData=require("./")("1.8.8"); | ||
|
||
console.log(nmcData.blocksByName["stone"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,84 @@ | ||
var mcData=require("minecraft-data"); | ||
var indexes=require("./indexes.js"); | ||
var fs = require("fs"); | ||
|
||
module.exports = { | ||
blocks: indexes.blocksById, | ||
blocksByName: indexes.blocksByName, | ||
blocksArray:mcData.blocks, | ||
|
||
biomes: indexes.biomesById, | ||
biomesArray: mcData.biomes, | ||
var cache={}; // prevent reindexing when requiring multiple time the same version | ||
|
||
items: indexes.itemsById, | ||
itemsByName: indexes.itemsByName, | ||
itemsArray: mcData.items, | ||
module.exports = function(mcVersion) | ||
{ | ||
var majorVersion=toMajor(mcVersion); | ||
if(majorVersion==null) | ||
return null; | ||
if(cache[majorVersion]) | ||
return cache[majorVersion]; | ||
var mcData=mcVersionToMcData(majorVersion); | ||
if(mcData==null) | ||
return null; | ||
var nmcData=mcDataToNode(mcData); | ||
cache[majorVersion]=nmcData; | ||
return nmcData; | ||
}; | ||
|
||
recipes: mcData.recipes, | ||
function toMajor(mcVersion) | ||
{ | ||
var parts=mcVersion.split("."); | ||
if(parts.size<=1) | ||
return null; | ||
mcVersion=parts.slice(0,2).join("."); | ||
return mcVersion; | ||
} | ||
|
||
instruments: indexes.instrumentsById, | ||
instrumentsArray: mcData.instruments, | ||
function mcVersionToMcData(mcVersion) | ||
{ | ||
var dir="./minecraft-data/"+mcVersion; | ||
if(!fs.existsSync(dir)) | ||
return null; | ||
return { | ||
blocks: require(dir+'/enums/blocks'), | ||
biomes: require(dir+'/enums/biomes'), | ||
items: require(dir+'/enums/items'), | ||
recipes: require(dir+'/enums/recipes'), | ||
instruments: require(dir+'/enums/instruments'), | ||
materials: require(dir+'/enums/materials'), | ||
entities: require(dir+'/enums/entities'), | ||
protocol: require(dir+'/enums/protocol') | ||
}; | ||
} | ||
|
||
materials: mcData.materials, | ||
function mcDataToNode(mcData) { | ||
var indexes=require("./indexes.js")(mcData); | ||
return { | ||
blocks: indexes.blocksById, | ||
blocksByName: indexes.blocksByName, | ||
blocksArray: mcData.blocks, | ||
|
||
entities: indexes.entitiesById, | ||
entitiesByName:indexes.entitiesByName, | ||
entitiesArray: mcData.entities, | ||
biomes: indexes.biomesById, | ||
biomesArray: mcData.biomes, | ||
|
||
items: indexes.itemsById, | ||
itemsByName: indexes.itemsByName, | ||
itemsArray: mcData.items, | ||
|
||
recipes: mcData.recipes, | ||
|
||
instruments: indexes.instrumentsById, | ||
instrumentsArray: mcData.instruments, | ||
|
||
materials: mcData.materials, | ||
|
||
entities: indexes.entitiesById, | ||
entitiesByName: indexes.entitiesByName, | ||
entitiesArray: mcData.entities, | ||
|
||
findItemOrBlockById:function(id) | ||
{ | ||
var item=indexes.itemsById[id]; | ||
if(item !== undefined) return item; | ||
return indexes.blocksById[id]; | ||
}, | ||
findItemOrBlockByName:function(name) | ||
{ | ||
var item=indexes.itemsByName[name]; | ||
if(item !== undefined) return item; | ||
return indexes.blocksByName[name]; | ||
} | ||
}; | ||
|
||
findItemOrBlockById: function (id) { | ||
var item = indexes.itemsById[id]; | ||
if (item !== undefined) return item; | ||
return indexes.blocksById[id]; | ||
}, | ||
findItemOrBlockByName: function (name) { | ||
var item = indexes.itemsByName[name]; | ||
if (item !== undefined) return item; | ||
return indexes.blocksByName[name]; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
var mcData=require("minecraft-data"); | ||
var indexer=require("./indexer.js"); | ||
|
||
module.exports= { | ||
biomesById:indexer.buildIndexFromArray(mcData.biomes,"id"), | ||
module.exports= function(mcData){ | ||
return { | ||
biomesById:indexer.buildIndexFromArray(mcData.biomes,"id"), | ||
|
||
blocksById:indexer.buildIndexFromArray(mcData.blocks,"id"), | ||
blocksByName:indexer.buildIndexFromArray(mcData.blocks,"name"), | ||
blocksById:indexer.buildIndexFromArray(mcData.blocks,"id"), | ||
blocksByName:indexer.buildIndexFromArray(mcData.blocks,"name"), | ||
|
||
entitiesById:indexer.buildIndexFromArray(mcData.entities,"id"), | ||
entitiesByName:indexer.buildIndexFromArray(mcData.entities,"name"), | ||
entitiesById:indexer.buildIndexFromArray(mcData.entities,"id"), | ||
entitiesByName:indexer.buildIndexFromArray(mcData.entities,"name"), | ||
|
||
instrumentsById:indexer.buildIndexFromArray(mcData.instruments,"id"), | ||
instrumentsById:indexer.buildIndexFromArray(mcData.instruments,"id"), | ||
|
||
itemsById:indexer.buildIndexFromArray(mcData.items,"id"), | ||
itemsByName:indexer.buildIndexFromArray(mcData.items,"name") | ||
itemsById:indexer.buildIndexFromArray(mcData.items,"id"), | ||
itemsByName:indexer.buildIndexFromArray(mcData.items,"name") | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters