@@ -129,14 +129,22 @@ class BetterModelFabricImpl : ModInitializer, BetterModelPlatformImpl, BetterMod
129129 PolymerResourcePackUtils .markAsRequired()
130130
131131 config = loadOrSaveConfig()
132+
133+ val initialLoad = AtomicBoolean ()
134+
132135 PolymerResourcePackUtils .RESOURCE_PACK_CREATION_EVENT .register { builder ->
133- loadAndIncludeAssets(builder)
136+ val isInitialLoad = initialLoad.compareAndSet(false , true )
137+ reload {
138+ includeAssets(builder, it.packResult)
139+ if (isInitialLoad) loadLog(it)
140+ }
134141 }
135142
136143 ServerLifecycleEvents .SERVER_STARTED .register {
137144 allManagers.forEach {
138145 it.start()
139146 }
147+ if (initialLoad.compareAndSet(false , true )) reload { loadLog(it) }
140148 }
141149
142150 BetterModelAttachments .init ()
@@ -149,56 +157,41 @@ class BetterModelFabricImpl : ModInitializer, BetterModelPlatformImpl, BetterMod
149157 }
150158 }
151159
152- private fun loadAndIncludeAssets (builder : ResourcePackBuilder ) {
153- when (
154- val reloadResult = reload(ReloadInfo (false , Audience .empty()))
155- ) {
156- is Failure -> {
157- reloadResult.throwable.handleException(" Unable to load mod properly." )
158- }
159-
160- is OnReload -> {
161- throw RuntimeException (" mod load failed." )
162- }
163-
164- is Success -> {
165- includeAssets(builder, reloadResult.packResult())
166- info(
167- " Mod is loaded. (${reloadResult.totalTime().withComma()} ms)" .toComponent(GREEN ),
168- " Platform: Fabric" .toComponent(AQUA )
169- )
170- }
160+ private fun reload (callback : (Success ) -> Unit ) {
161+ when (val result = reload(ReloadInfo (false , Audience .empty()))) {
162+ is Failure -> result.throwable.handleException(" Unable to load mod properly." )
163+ is OnReload -> throw RuntimeException (" mod load failed." )
164+ is Success -> callback(result)
171165 }
172166 }
173167
174168 private fun includeAssets (builder : ResourcePackBuilder , packResult : PackResult ) {
175169 packResult.stream().forEach { packByte ->
176- val path = packByte.path.path
177- if (path == " pack.png" ) {
178- return @forEach
170+ when ( val path = packByte.path.path) {
171+ " pack.png" , " pack.mcmeta " -> return @forEach
172+ else -> builder.addData(path, packByte.bytes)
179173 }
180-
181- if (path != " pack.mcmeta " ) {
182- builder.addData(path, packByte.bytes)
174+ }
175+ packResult.meta().overlays?.entries?.forEach { entry ->
176+ if (entry.directory == " bettermodel_legacy " ) {
183177 return @forEach
184178 }
185179
186- packResult.meta().overlays?.entries?.forEach { entry ->
187- if (entry.directory == " bettermodel_legacy" ) {
188- return @forEach
189- }
180+ val min = entry.minFormat.run { PackFormat (major, minor) }
181+ val max = entry.maxFormat.run { PackFormat (major, minor) }
182+ val range = InclusiveRange (min, max)
190183
191- val min = entry.minFormat.run { PackFormat (major, minor) }
192- val max = entry.maxFormat.run { PackFormat (major, minor) }
193- val range = InclusiveRange (min, max)
194-
195- builder.packMcMetaBuilder.addOverlay(range, entry.directory)
196- }
197-
198- return @forEach
184+ builder.packMcMetaBuilder.addOverlay(range, entry.directory)
199185 }
200186 }
201187
188+ private fun loadLog (success : Success ) {
189+ info(
190+ " Mod is loaded. (${success.totalTime().withComma()} ms)" .toComponent(GREEN ),
191+ " Platform: Fabric" .toComponent(AQUA )
192+ )
193+ }
194+
202195 override fun getResource (fileName : String ): InputStream ? {
203196 return javaClass.getResourceAsStream(" /$fileName " )
204197 }
0 commit comments