Skip to content

Instantly share code, notes, and snippets.

@Levertion
Last active December 19, 2017 19:20
Show Gist options
  • Save Levertion/0a6c67cd949623d0a649ea8eb87a9b42 to your computer and use it in GitHub Desktop.
Save Levertion/0a6c67cd949623d0a649ea8eb87a9b42 to your computer and use it in GitHub Desktop.
A utility to collect all the block states from an Minecraft Anvil Region world after the 'flattening'

Minecraft 1.13 Block states from world utility

A utility to collect all the block states from an Minecraft Anvil Region world post 1.13 flattening.
The tool used to collect the region in a JSON format is made by @MrPingouinMC. It can be found here: https://github.com/MrPingouinMC/nbtToText/releases/tag/1.0
This utility is under the MIT license.

A list generated using this method is in a gist - here. This list has no copyright, and the code is under the MIT license as at the project root.

Format

The format of the generated file is as follows:

{
    "<block ID (EG minecraft:stone)>":{
        "states":{
            "stateName":["valueOption1","valueOption2"]
        }
    }
}

N.B the states key is not generated if the block has no available states.

Generating the list yourself

However, once it has been released, you'll need to follow these steps:

  • Click Download ZIP above, and extract the zip into the folder
  • Create a debug world. This can be done by shift-left-clicking the world type option a few times.
  • Open the world folder, and the folder within it called region.
  • Copy the file called r.0.0.mca into the root of where you extracted your zip.
  • Use the region -> JSON tool provided by MrPingouin, found here. Rename the generated file to region.json.
  • Compile the program by running tsc -p ./ from your extracted folder.
  • Run the program using node index.
  • Use the output in blockstates.json.
import * as fs from "fs";
fs.readFile("region.json", (err, data) => {
if (!err) {
try {
const region = JSON.parse(data.toString()) as { [chunk: string]: Chunk };
fs.writeFile("blockstates.json", JSON.stringify(getBlocks(region)), (e) => {
if (!!e) {
console.log(e);
}
});
} catch (error) {
console.log("Region file contains invalid json");
}
} else {
console.log(err);
}
});
interface BlockResult {
[id: string]: Block;
}
interface Block {
states: {
[state: string]: BlockStateValue[],
};
}
type BlockStateValue = string;
interface Chunk {
DataVersion: number;
Level: Level;
}
interface Level {
Entities: any[];
Sections: Section[];
[additional: string]: any;
}
interface Section {
Palette: Array<{
Name: string,
Properties?: { [value: string]: BlockStateValue },
}>;
Y: number;
[additional: string]: any;
}
function getBlocks(chunkIDs: { [chunk: string]: Chunk }): BlockResult {
const blocks: BlockResult = {};
const chunks: Chunk[] = [];
for (const key in chunkIDs) {
if (chunkIDs.hasOwnProperty(key)) {
const element = chunkIDs[key];
chunks.push(element);
}
}
for (const chunk of chunks) {
try {
const level = chunk.Level;
if (!!level && !!level.Sections) {
const sections = level.Sections;
for (const section of sections) {
for (const block of section.Palette) {
if (!blocks.hasOwnProperty(block.Name)) {
blocks[block.Name] = {} as Block;
}
if (!!block.Properties) {
if (!blocks[block.Name].states) {
blocks[block.Name].states = {};
}
for (const property in block.Properties) {
if (block.Properties.hasOwnProperty(property)) {
const element = block.Properties[property];
if (!blocks[block.Name].states.hasOwnProperty(property)) {
blocks[block.Name].states[property] = [element];
} else {
if (blocks[block.Name].states[property].indexOf(element) === -1) {
blocks[block.Name].states[property].push(element);
}
}
}
}
}
}
}
}
} catch (error) {
console.log(error);
}
}
return blocks;
}
Copyright 2017 Levertion
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"strict": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment