11package org .cloudburstmc .server .registry ;
22
3+ import com .nukkitx .blockstateupdater .BlockStateUpdaters ;
34import com .nukkitx .nbt .NBTInputStream ;
45import com .nukkitx .nbt .NbtList ;
56import com .nukkitx .nbt .NbtMap ;
1011
1112import java .io .IOException ;
1213import java .io .InputStream ;
14+ import java .nio .file .Files ;
15+ import java .nio .file .Paths ;
16+ import java .nio .file .StandardOpenOption ;
17+ import java .util .ArrayList ;
1318import java .util .HashSet ;
19+ import java .util .List ;
1420import java .util .Set ;
1521
1622public class BlockRegistryTest {
1723
1824 @ DisplayName ("Block Palette Test" )
1925 @ Test
20- public void blockPaletteTest () {
26+ public void blockPaletteTest () throws IOException {
2127 Set <NbtMap > vanillaPalette ;
2228 InputStream stream = BlockRegistryTest .class .getClassLoader ().getResourceAsStream ("runtime_block_states.dat" );
2329 try (NBTInputStream nbtStream = NbtUtils .createNetworkReader (stream )) {
@@ -27,21 +33,37 @@ public void blockPaletteTest() {
2733 throw new AssertionError ("Unable to load block palette" );
2834 }
2935
36+ int version = BlockStateUpdaters .getLatestVersion ();
37+ int major = (version >> 24 ) & 0xFF ;
38+ int minor = (version >> 16 ) & 0xFF ;
39+ int patch = (version >> 8 ) & 0xFF ;
40+ int build = version & 0xFF ;
41+ System .out .printf ("Latest block state version: %d.%d.%d.%d%n" , major , minor , patch , build );
42+
3043 NbtList <NbtMap > serverPalette = BlockRegistry .get ().getPaletteTag (); // init
3144
32- boolean failed = false ;
45+ List <String > invalidStates = new ArrayList <>();
46+ int invalid = 0 ;
3347 for (NbtMap state : serverPalette ) {
3448 if (!vanillaPalette .remove (state )) {
35- System . out . println ( "State does not exist in vanilla palette: \n " + state .toString ());
36- failed = true ;
49+ invalidStates . add ( state .toString ());
50+ invalid ++ ;
3751 }
3852 }
3953
54+ System .out .println ("Found " + invalid + " invalid block states" );
55+ Files .write (Paths .get ("invalid_states.log" ), invalidStates , StandardOpenOption .TRUNCATE_EXISTING , StandardOpenOption .CREATE );
56+
57+ List <String > missingStates = new ArrayList <>();
58+ int missing = 0 ;
4059 for (NbtMap state : vanillaPalette ) {
41- System . out . println ( "State does not exist in Cloudburst: \n " + state . toString ()) ;
42- failed = true ;
60+ missing ++ ;
61+ missingStates . add ( state . toString ()) ;
4362 }
4463
45- Assertions .assertFalse (failed , "One or more block states did not match the vanilla palette" );
64+ System .out .println ("Found " + missing + " missing block states" );
65+ Files .write (Paths .get ("missing_states.log" ), missingStates , StandardOpenOption .TRUNCATE_EXISTING , StandardOpenOption .CREATE );
66+
67+ Assertions .assertFalse (missing > 0 | invalid > 0 , "One or more block states did not match the vanilla palette" );
4668 }
4769}
0 commit comments