-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
98 deletions.
There are no files selected for viewing
56 changes: 0 additions & 56 deletions
56
modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SoundPlayEvent.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...es/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SoundPlayedEvent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.polyfrost.oneconfig.api.event.v1.events; | ||
|
||
public class SoundPlayedEvent implements Event { | ||
|
||
private final String name; | ||
private final Object category; | ||
private Object sound; | ||
|
||
public SoundPlayedEvent(String name, Object category, Object sound) { | ||
this.name = name; | ||
this.category = category; | ||
this.sound = sound; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T getCategory() { | ||
return (T) category; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T getSound() { | ||
return (T) sound; | ||
} | ||
|
||
} |
62 changes: 20 additions & 42 deletions
62
versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/SoundManagerMixin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,31 @@ | ||
/* | ||
* This file is part of OneConfig. | ||
* OneConfig - Next Generation Config Library for Minecraft: Java Edition | ||
* Copyright (C) 2021~2024 Polyfrost. | ||
* <https://polyfrost.org> <https://github.com/Polyfrost/> | ||
* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* OneConfig is licensed under the terms of version 3 of the GNU Lesser | ||
* General Public License as published by the Free Software Foundation, AND | ||
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost, | ||
* either version 1.0 of the Additional Terms, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License. If not, see <https://www.gnu.org/licenses/>. You should | ||
* have also received a copy of the Additional Terms Applicable | ||
* to OneConfig, as published by Polyfrost. If not, see | ||
* <https://polyfrost.org/legal/oneconfig/additional-terms> | ||
*/ | ||
|
||
package org.polyfrost.oneconfig.internal.mixin; | ||
|
||
import net.minecraft.client.audio.ISound; | ||
import net.minecraft.client.audio.SoundEventAccessorComposite; | ||
import net.minecraft.client.audio.SoundManager; | ||
import org.polyfrost.oneconfig.api.event.v1.EventManager; | ||
import org.polyfrost.oneconfig.api.event.v1.events.SoundPlayEvent; | ||
import org.polyfrost.oneconfig.api.event.v1.events.SoundPlayedEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Coerce; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
@Mixin(SoundManager.class) | ||
public class SoundManagerMixin { | ||
@Inject(method = "playSound", at = @At(value = "INVOKE", | ||
//#if MC<=11202 | ||
target = "Lnet/minecraft/client/audio/SoundHandler;getSound(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/audio/SoundEventAccessorComposite;" | ||
//#else | ||
//$$ target = "Lnet/minecraft/client/audio/ISound;getSoundLocation()Lnet/minecraft/util/ResourceLocation;" | ||
//#endif | ||
), cancellable = true) | ||
private void onPlaySound(@Coerce Object sound, CallbackInfo ci) { | ||
if (sound == null) return; | ||
SoundPlayEvent ev = new SoundPlayEvent(sound); | ||
EventManager.INSTANCE.post(ev); | ||
if (ev.cancelled) ci.cancel(); | ||
|
||
@ModifyVariable( | ||
method = "playSound", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/audio/SoundHandler;getSound(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/audio/SoundEventAccessorComposite;" | ||
), | ||
argsOnly = true | ||
) | ||
private ISound oneconfig$playSound(ISound value) { | ||
SoundEventAccessorComposite accessor = ((SoundManager) (Object) this).sndHandler.getSound(value.getSoundLocation()); | ||
String name = value.getSoundLocation().getResourcePath(); | ||
SoundPlayedEvent event = new SoundPlayedEvent(name, (accessor == null ? null : accessor.getSoundCategory()), value); | ||
EventManager.INSTANCE.post(event); | ||
return event.getSound(); | ||
} | ||
|
||
} |
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