Created
June 7, 2020 04:18
-
-
Save reedacartwright/8540c29faec405e7d2146e0483f67a77 to your computer and use it in GitHub Desktop.
Minecraft Bedrock: Extract block information for the region 0,16,0 to 63,79,63 in a world file.
This file contains hidden or 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
# update if neccessary | |
devtools::install_github("reedacartwright/rbedrock") | |
library(jsonlite) | |
library(tidyverse) | |
library(rbedrock) | |
db <- bedrockdb(dbpath_goes_here) | |
# read blocks in cube from 0,16,0 to 63,79,63 | |
g <- expand_grid(x=0:3,z=0:3,y=1:4) | |
k <- create_chunk_key(g$x,g$z,0,47,g$y) | |
m <- db$mget(k) %>% set_names(k) %>% compact() %>% map(~read_subchunk(.,names_only=FALSE)) | |
# convert blocks into a list with pos, name, and states Exclude all "air" blocks | |
ret <- imap(m, function(x,n) { | |
# extract block names | |
block_names <- modify(x, ~.$name) | |
# which blocks are not air | |
w <- which(block_names != "minecraft:air") | |
# generate x,y,z positions for blocks | |
offsets <- arrayInd(w, dim(block_names))[,c(3,1,2), drop=FALSE] | |
co <- subchunk_coords(offsets, unlist(subchunk_origin(n))) | |
colnames(co) <- c("x","y","z") | |
# convert to list | |
co <- array_tree(co) | |
# extract name and states | |
a <- map(x[w], ~.[c("name", "states")]) | |
# merge positions with names and states. | |
list_merge(co, !!!a) | |
}) | |
# output as json | |
write_json(purrr::flatten(ret), "blocks.json", auto_unbox=TRUE, pretty=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment