@@ -39,8 +39,9 @@ public final class SoundPackLoader {
3939 private static final String CACHE_FNAME = ExtraSounds .MODID + ".cache" ;
4040 private static final Path CACHE_PATH = Path .of (System .getProperty ("java.io.tmpdir" ), ".minecraft_fabric" , CACHE_FNAME );
4141
42- private static final Map <Identifier , VersionedSoundEventWrapper > BUILT_IN_SOUND_EVENT = new HashMap <>();
42+ private static final Map <Identifier , VersionedSoundEventWrapper > AUTO_GEN_SOUND_EVENT = new HashMap <>();
4343 private static final Map <Identifier , VersionedSoundEventWrapper > EXTERNAL_SOUND_EVENT = new HashMap <>();
44+ private static final Map <Identifier , VersionedSoundEventWrapper > CUSTOM_SOUND_EVENT = new HashMap <>();
4445 public static final VersionedClientResource EXTRA_SOUNDS_RESOURCE = Objects .requireNonNull (
4546 VersionedClientResource .newInstance (ExtraSounds .MODID , "%s Runtime Resources" .formatted (ExtraSounds .class .getSimpleName ()))
4647 );
@@ -141,7 +142,7 @@ public static void init() {
141142 } else if (DebugUtils .DEBUG ) {
142143 LOGGER .info ("init finished; took {}ms." , tookMillis );
143144 }
144- LOGGER .info ("Built-in sound pack successfully loaded; {} entries." , BUILT_IN_SOUND_EVENT .size ());
145+ LOGGER .info ("Generated sound pack successfully loaded; {} entries." , AUTO_GEN_SOUND_EVENT .size ());
145146 }
146147
147148 /**
@@ -220,29 +221,33 @@ private static void generateSoundEntry(Identifier clickId, SoundEventRegistratio
220221 * @param clickId Target id.
221222 */
222223 private static void putSoundEvent (Identifier clickId ) {
223- BUILT_IN_SOUND_EVENT .put (clickId , ExtraSounds .createEvent (clickId ));
224+ AUTO_GEN_SOUND_EVENT .put (clickId , ExtraSounds .createEvent (clickId ));
224225 }
225226
226227 private static void putExternalSoundEvent (Identifier identifier ) {
227228 EXTERNAL_SOUND_EVENT .put (identifier , ExtraSounds .createEvent (identifier ));
228229 }
229230
230231 public static Optional <VersionedSoundEventWrapper > getSoundEventById (Identifier ... ids ) {
232+ if (ids == null ) {
233+ return Optional .empty ();
234+ }
235+
231236 for (Identifier target : ids ) {
232- if (EXTERNAL_SOUND_EVENT .containsKey (target )) {
233- return Optional .of (EXTERNAL_SOUND_EVENT .get (target ));
234- }
235- if (BUILT_IN_SOUND_EVENT .containsKey (target )) {
236- return Optional .of (BUILT_IN_SOUND_EVENT .get (target ));
237+ if (CUSTOM_SOUND_EVENT .containsKey (target )) {
238+ return Optional .of (CUSTOM_SOUND_EVENT .get (target ));
237239 }
238240 }
239241 return Optional .empty ();
240242 }
241243
242244 public static void reloadExternalSoundEvent () {
245+ EXTERNAL_SOUND_EVENT .clear ();
246+ CUSTOM_SOUND_EVENT .clear ();
247+
243248 for (var pack : Minecraft .getInstance ().getResourceManager ().getResourceStack (SOUNDS_JSON_ID )) {
244249 if (pack .sourcePackId ().equals (ExtraSounds .MODID )) {
245- // Avoid built-in resource via SoundPackLoader.
250+ // Avoid auto-gen resource via SoundPackLoader.
246251 continue ;
247252 }
248253 try (InputStream stream = pack .open ()) {
@@ -254,8 +259,11 @@ public static void reloadExternalSoundEvent() {
254259 } catch (Exception ignored ) {
255260 }
256261 }
262+
263+ CUSTOM_SOUND_EVENT .putAll (AUTO_GEN_SOUND_EVENT );
257264 if (!EXTERNAL_SOUND_EVENT .isEmpty ()) {
258265 LOGGER .info ("External sound pack was found; {} entries." , EXTERNAL_SOUND_EVENT .size ());
266+ CUSTOM_SOUND_EVENT .putAll (EXTERNAL_SOUND_EVENT );
259267 }
260268 }
261269
0 commit comments