Created
March 28, 2020 15:29
-
-
Save ci010/9032360a9137c8f8c37c0b07a93b3ee6 to your computer and use it in GitHub Desktop.
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
static Random r = new Random(); | |
static int size = Block.REGISTRY.getKeys().size(); | |
static boolean isValidBlock(Block block) { | |
if (block.getCreativeTab() != CreativeTabs.BUILDING_BLOCKS) | |
return false; | |
if (block == Blocks.WATER) | |
return false; | |
if (block == Blocks.WATERLILY) | |
return false; | |
if (block == Blocks.ICE) | |
return false; | |
if (block == Blocks.FROSTED_ICE) | |
return false; | |
if (block == Blocks.PACKED_ICE) | |
return false; | |
if (block == Blocks.GRAVEL) | |
return false; | |
if (block == Blocks.SAND) | |
return false; | |
return true; | |
} | |
static IBlockState getBlockState() { | |
Block block; | |
do { | |
block = Block.REGISTRY.getObjectById(r.nextInt(size)); | |
} while (!isValidBlock(block)); | |
ImmutableList<IBlockState> states = block.getBlockState().getValidStates(); | |
return states.get(r.nextInt(states.size())); | |
} | |
static int getIndex(int x, int y, int z) { | |
return y << 8 | z << 4 | x; | |
} | |
// generate random block in chunk 0,0,0 | |
static void generate(World world) { | |
for (int x = 0; x < 16; x += 2) { | |
for (int y = 0; y < 16; y += 2) { | |
for (int z = 0; z < 16; z += 2) { | |
IBlockState state = getBlockState(); | |
world.setBlockState(new BlockPos(x, y, z), state, 1); | |
} | |
} | |
} | |
} | |
// dump chunk 0,0,0 blockstates | |
static void dump(World world) { | |
List<String> lines = new ArrayList<>(); | |
Chunk chunk = world.getChunk(0, 0); | |
net.minecraft.world.chunk.BlockStateContainer container = chunk.getBlockStorageArray()[0].getData(); | |
BitArray arr = null; | |
Field f; | |
try { | |
f = container.getClass().getDeclaredField("storage"); | |
f.setAccessible(true); | |
arr = (BitArray) f.get(container); | |
} catch (Exception e1) { | |
e1.printStackTrace(); | |
} | |
lines.clear(); | |
for (int x = 0; x < 16; x += 2) { | |
for (int y = 0; y < 16; y += 2) { | |
for (int z = 0; z < 16; z += 2) { | |
IBlockState state = container.get(x, y, z); | |
int persistId = Block.BLOCK_STATE_IDS.get(state); | |
lines.add(new StringBuilder().append(persistId).append(" ").append(x).append(" ").append(y).append(" ") | |
.append(z).append(" ").append(state).toString()); | |
} | |
} | |
} | |
try { | |
Files.write(Paths.get("mock.txt"), lines, Charset.defaultCharset()); | |
} catch (Exception e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment