mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-24 22:14:32 +00:00
Added new ISoundHandler.onPlaySoundAtEntity hook. Should be backwards compatible with any older ISoundHandler implementations.
This commit is contained in:
1 parent
320d1360b8
commit
d56f0d0d55
5 files changed
+94
-28
No files matched your search
@@ -455,6 +455,7 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
public static LinkedList<ISoundHandler> soundHandlers = new LinkedList<ISoundHandler>();
|
||||
public static LinkedList<ISoundHandler> soundHandlers2 = new LinkedList<ISoundHandler>();
|
||||
public static void onSetupAudio(SoundManager soundManager)
|
||||
{
|
||||
for (ISoundHandler handler : soundHandlers)
|
||||
@@ -514,7 +515,7 @@ public class ForgeHooksClient
|
||||
{
|
||||
for (ISoundHandler handler : soundHandlers)
|
||||
{
|
||||
entry = handler.onPlaySoundEffect(soundManager, entry, soundName,volume, pitch);
|
||||
entry = handler.onPlaySoundEffect(soundManager, entry, soundName, volume, pitch);
|
||||
if (entry == null)
|
||||
{
|
||||
return null;
|
||||
@@ -522,6 +523,20 @@ public class ForgeHooksClient
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static String onPlaySoundAtEntity(Entity entity, String soundName, float volume, float pitch)
|
||||
{
|
||||
MinecraftForgeClient.checkMinecraftVersion("Minecraft Minecraft 1.2.5", "Interface check in onPlaySoundAtEntity, remove it Mods should be updated");
|
||||
for (ISoundHandler handler : soundHandlers2)
|
||||
{
|
||||
soundName = handler.onPlaySoundAtEntity(entity, soundName,volume, pitch);
|
||||
if (soundName == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void onLogin(Packet1Login login, NetClientHandler net, NetworkManager netManager)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.src.forge;
|
||||
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.SoundManager;
|
||||
import net.minecraft.src.SoundPoolEntry;
|
||||
|
||||
@@ -91,5 +92,18 @@ public interface ISoundHandler
|
||||
* @return The new sound entry to play, or the current one passed in.
|
||||
*/
|
||||
SoundPoolEntry onPlaySoundEffect(SoundManager soundManager, SoundPoolEntry entry, String soundName, float volume, float pitch);
|
||||
|
||||
|
||||
/**
|
||||
* Raised when an entity attempts to play a sound via World's playSoundAtEntity
|
||||
* function. This is so that additional data about the state of the entity can
|
||||
* be obtained efficiently without using AABBs. An important thing to note:
|
||||
* This hook will be called even if the sound is off.
|
||||
*
|
||||
* @param entity The entity that the sound should be played at. Always the calling Entity or the Player.
|
||||
* @param soundName The name of the requested sound.
|
||||
* @param volume The sound's volume, between 0.0 and 1.0.
|
||||
* @param pitch The sound's pitch
|
||||
* @return The sound to play, null to cancel the event.
|
||||
*/
|
||||
String onPlaySoundAtEntity(Entity entity, String soundName, float volume, float pitch);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package net.minecraft.src.forge;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.ModLoader;
|
||||
@@ -63,6 +64,21 @@ public class MinecraftForgeClient
|
||||
public static void registerSoundHandler(ISoundHandler handler)
|
||||
{
|
||||
ForgeHooksClient.soundHandlers.add(handler);
|
||||
checkMinecraftVersion("Minecraft Minecraft 1.2.5", "Interface check in registerSoundHandler, remove it Mods should be updated");
|
||||
try
|
||||
{
|
||||
if (handler.getClass().getDeclaredMethod("onPlaySoundAtEntity", Entity.class, String.class, float.class, float.class) != null)
|
||||
{
|
||||
ForgeHooksClient.soundHandlers2.add(handler);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (MinecraftForgeClient.class.getPackage().getName().equals("net.minecraft.src.forge"))
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Bind a texture. This is used to bind a texture file when
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.src.forge.adaptors;
|
||||
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.SoundManager;
|
||||
import net.minecraft.src.SoundPoolEntry;
|
||||
import net.minecraft.src.forge.ISoundHandler;
|
||||
@@ -39,4 +40,10 @@ public class SoundHandlerAdaptor implements ISoundHandler
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaySoundAtEntity(Entity entity, String soundName, float volume, float pitch)
|
||||
{
|
||||
return soundName;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user