package Ġcom . github . gj um . minecraft . j mc data Ċ Ċ import Ġcom . google . gson . Gson Ċ import Ġcom . google . gson . JsonArray Ċ import Ġcom . google . gson . JsonObject Ċ import Ġjava . io . InputStream Reader Ċ Ċ class ĠMinecraft Data ( mc Version : ĠString ) Ġ{ Ċ ĉ val Ġitems Ġ= ĠItem Info Storage ( Ċĉ ĉ load Json ( mc Version , Ġ" items ", ĠJson Array :: class . java ), Ċĉ ĉ * getBlock Items Info Source ( mc Version )) ĊĊ ĉ val Ġblocks Ġ= ĠBlock Info Storage ( Ċĉ ĉ load Json ( mc Version , Ġ" blocks ", ĠJson Array :: class . java ), Ċĉ ĉ load Json ( mc Version , Ġ" block Collision Shapes ", ĠJsonObject :: class . java ), Ċĉ ĉ items ) ĊĊ ĉ val Ġwindows Ġ= ĠWindow Info Storage ( load Json ( mc Version , Ġ" windows ", ĠJson Array :: class . java )) Ċ } Ċ Ċ /** Ċ Ġ* ĠFor Ġversions Ġbefore ĠThe ĠFlat ten ing , Ġ` blocks . json ` Ġhas Ġto Ġbe Ġloaded Ġas Ġadditional Ġitems . Ċ Ġ* Ġ@ return Ġempty Ġarray Ġafter ĠThe ĠFlat ten ing , Ġsingleton Ġarray Ġof Ġ` blocks . json ` Ġfor Ġolder Ġversions Ċ Ġ*/ Ċ private Ġfun Ġget Block Items Info Source ( mc Version : ĠString ): ĠArray < JsonArray > Ġ{ Ċ ĉ val Ġdata Paths Ġ= ĠgetData Paths ( mc Version , Ġ" pc ") Ċ ĉ val Ġblocks Are Items Ġ= Ġdata Paths [" blocks Are Items "] ?. as Boolean Ġ?: Ġfalse Ċ ĉ if Ġ(! blocks Are Items ) Ġreturn Ġempty Array () Ċ ĉ return ĠarrayOf ( load Json ( mc Version , Ġ" blocks ", ĠJson Array :: class . java )) Ċ } Ċ Ċ private Ġfun Ġ< T > Ġload Json ( mc Version : ĠString , ĠfileName : ĠString , Ġtype : ĠClass < T >): ĠT Ġ{ Ċ ĉ val Ġpath Ġ= ĠgetData FilePath ( mc Version , ĠfileName ) Ċ ĉ val Ġjson Stream Ġ= ĠMinecraft Data :: class . java . getResource AsStream ( path ) Ċĉ ĉ ?: Ġerror (" Could Ġnot Ġfind Ġ$ fileName Ġdata Ġfor ĠMinecraft Ġversion Ġ$ mc Version ") Ċ ĉ return ĠGson (). fromJson ( InputStream Reader ( json Stream ), Ġtype ) Ċ } Ċ Ċ private Ġfun ĠgetData FilePath ( mc Version : ĠString , ĠfileName : ĠString ): ĠString Ġ{ Ċ ĉ val Ġdata Paths Ġ= ĠgetData Paths ( mc Version , Ġ" pc ") Ċ ĉ val Ġsub Dir Ġ= Ġdata Paths . get ( fileName )?. asString Ċĉ ĉ ?: Ġerror (" Unknown Ġdata Ġfile Ġ`$ fileName ` Ġfor Ġversion Ġ`$ mc Version ` ") Ċ ĉ val Ġdir Ġ= Ġsub Dir . substring After (" pc /") Ċ ĉ return Ġ"/ mc data /$ dir /$ fileName . json " Ċ } Ċ Ċ private Ġfun ĠgetData Paths ( mc Version : ĠString , Ġplatform : ĠString Ġ= Ġ" pc "): ĠJsonObject Ġ{ Ċ ĉ val Ġjson Stream Ġ= ĠMinecraft Data :: class . java . getResource AsStream ("/ mc data / data Paths . json ") Ċ ĉ val Ġdata Paths Ġ= ĠGson (). fromJson ( InputStream Reader ( json Stream ), ĠJsonObject :: class . java ) Ċ ĉ val Ġplatform Obj Ġ= Ġdata Paths . get ( platform )?. as JsonObject Ċĉ ĉ ?: Ġerror (" Unknown Ġplatform Ġ`$ platform ` ") Ċ ĉ return Ġplatform Obj . get ( mc Version )?. as JsonObject Ċĉ ĉ ?: Ġerror (" Unknown ĠMinecraft Ġversion Ġ`$ mc Version ` ") Ċ } Ċ Ċ private Ġval ĠString . base Version Ġget () Ġ= Ġsplit ('. '). take ( 2 ). join ToString (".") Ċ