From d56f0d0d553728670d012a4a37eff9dbac6ea50f Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 13 Jun 2012 21:09:00 -0700 Subject: [PATCH] Added new ISoundHandler.onPlaySoundAtEntity hook. Should be backwards compatible with any older ISoundHandler implementations. --- .../minecraft/src/forge/ForgeHooksClient.java | 17 ++++- .../minecraft/src/forge/ISoundHandler.java | 16 ++++- .../src/forge/MinecraftForgeClient.java | 16 +++++ .../forge/adaptors/SoundHandlerAdaptor.java | 7 ++ .../net/minecraft/src/World.java.patch | 66 +++++++++++-------- 5 files changed, 94 insertions(+), 28 deletions(-) diff --git a/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java b/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java index 2d1ff8b75..e8dbe6bb5 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/ForgeHooksClient.java @@ -455,6 +455,7 @@ public class ForgeHooksClient } public static LinkedList soundHandlers = new LinkedList(); + public static LinkedList soundHandlers2 = new LinkedList(); 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) { diff --git a/forge/forge_client/src/net/minecraft/src/forge/ISoundHandler.java b/forge/forge_client/src/net/minecraft/src/forge/ISoundHandler.java index 727345914..82579f6de 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/ISoundHandler.java +++ b/forge/forge_client/src/net/minecraft/src/forge/ISoundHandler.java @@ -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); } diff --git a/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java b/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java index 4594e0032..17e9fe113 100755 --- a/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/MinecraftForgeClient.java @@ -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 diff --git a/forge/forge_client/src/net/minecraft/src/forge/adaptors/SoundHandlerAdaptor.java b/forge/forge_client/src/net/minecraft/src/forge/adaptors/SoundHandlerAdaptor.java index c7b29b145..fba44d4fa 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/adaptors/SoundHandlerAdaptor.java +++ b/forge/forge_client/src/net/minecraft/src/forge/adaptors/SoundHandlerAdaptor.java @@ -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; + } } diff --git a/forge/patches/minecraft/net/minecraft/src/World.java.patch b/forge/patches/minecraft/net/minecraft/src/World.java.patch index f7553a0ee..3d190cdd1 100644 --- a/forge/patches/minecraft/net/minecraft/src/World.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/World.java.patch @@ -1,10 +1,11 @@ --- ../src_base/minecraft/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000 -@@ -9,8 +9,17 @@ +@@ -9,8 +9,18 @@ import java.util.Set; import java.util.TreeSet; +import net.minecraft.src.forge.ForgeHooks; ++import net.minecraft.src.forge.ForgeHooksClient; + public class World implements IBlockAccess { @@ -18,7 +19,7 @@ /** * boolean; if true updates scheduled by scheduleBlockUpdate happen immediately */ -@@ -79,7 +88,7 @@ +@@ -79,7 +89,7 @@ * Contains a timestamp from when the World object was created. Is used in the session.lock file */ private long lockTimestamp; @@ -27,7 +28,7 @@ /** Option > Difficulty setting (0 - 3) */ public int difficultySetting; -@@ -214,6 +223,7 @@ +@@ -214,6 +224,7 @@ this.chunkProvider = this.createChunkProvider(); this.calculateInitialSkylight(); this.calculateInitialWeather(); @@ -35,7 +36,7 @@ } public World(World par1World, WorldProvider par2WorldProvider) -@@ -259,6 +269,7 @@ +@@ -259,6 +270,7 @@ this.chunkProvider = this.createChunkProvider(); this.calculateInitialSkylight(); this.calculateInitialWeather(); @@ -43,7 +44,7 @@ } public World(ISaveHandler par1ISaveHandler, String par2Str, WorldSettings par3WorldSettings) -@@ -340,6 +351,7 @@ +@@ -340,6 +352,7 @@ this.calculateInitialSkylight(); this.calculateInitialWeather(); @@ -51,7 +52,7 @@ } /** -@@ -507,6 +519,7 @@ +@@ -507,6 +520,7 @@ } this.chunkProvider.saveChunks(par1, par2IProgressUpdate); @@ -59,7 +60,7 @@ } } -@@ -559,7 +572,8 @@ +@@ -559,7 +573,8 @@ */ public boolean isAirBlock(int par1, int par2, int par3) { @@ -69,7 +70,20 @@ } /** -@@ -2068,7 +2082,7 @@ +@@ -1453,6 +1468,12 @@ + */ + public void playSoundAtEntity(Entity par1Entity, String par2Str, float par3, float par4) + { ++ par2Str = ForgeHooksClient.onPlaySoundAtEntity(par1Entity, par2Str, par3, par4); ++ if (par2Str == null) ++ { ++ return; ++ } ++ + for (int var5 = 0; var5 < this.worldAccesses.size(); ++var5) + { + ((IWorldAccess)this.worldAccesses.get(var5)).playSound(par2Str, par1Entity.posX, par1Entity.posY - (double)par1Entity.yOffset, par1Entity.posZ, par3, par4); +@@ -2068,7 +2089,7 @@ if (var7 != null) { @@ -78,7 +92,7 @@ } } } -@@ -2098,18 +2112,18 @@ +@@ -2098,18 +2119,18 @@ { this.loadedTileEntityList.add(var8); } @@ -101,7 +115,7 @@ } } -@@ -2122,13 +2136,13 @@ +@@ -2122,13 +2143,13 @@ public void addTileEntity(Collection par1Collection) { @@ -121,7 +135,7 @@ } } -@@ -2150,7 +2164,7 @@ +@@ -2150,7 +2171,7 @@ int var4 = MathHelper.floor_double(par1Entity.posZ); byte var5 = 32; @@ -130,7 +144,7 @@ { par1Entity.lastTickPosX = par1Entity.posX; par1Entity.lastTickPosY = par1Entity.posY; -@@ -2327,7 +2341,14 @@ +@@ -2327,7 +2348,14 @@ if (var11 == Block.fire.blockID || var11 == Block.lavaMoving.blockID || var11 == Block.lavaStill.blockID) { return true; @@ -146,7 +160,7 @@ } } } -@@ -2631,25 +2652,19 @@ +@@ -2631,25 +2659,19 @@ */ public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity) { @@ -184,21 +198,21 @@ } } -@@ -2658,27 +2673,10 @@ +@@ -2658,27 +2680,10 @@ */ public void removeBlockTileEntity(int par1, int par2, int par3) { - TileEntity var4 = this.getBlockTileEntity(par1, par2, par3); - - if (var4 != null && this.scanningTileEntities) -+ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4); -+ if (chunk != null) - { +- { - var4.invalidate(); - this.addedTileEntityList.remove(var4); - } - else -- { ++ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4); ++ if (chunk != null) + { - if (var4 != null) - { - this.addedTileEntityList.remove(var4); @@ -215,7 +229,7 @@ } } -@@ -2704,7 +2702,8 @@ +@@ -2704,7 +2709,8 @@ */ public boolean isBlockNormalCube(int par1, int par2, int par3) { @@ -225,7 +239,7 @@ } /** -@@ -2720,7 +2719,7 @@ +@@ -2720,7 +2726,7 @@ if (var5 != null && !var5.isEmpty()) { Block var6 = Block.blocksList[this.getBlockId(par1, par2, par3)]; @@ -234,7 +248,7 @@ } else { -@@ -2985,6 +2984,7 @@ +@@ -2985,6 +2991,7 @@ } } } @@ -242,7 +256,7 @@ Profiler.endSection(); -@@ -3308,7 +3308,7 @@ +@@ -3308,7 +3315,7 @@ private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6) { @@ -251,7 +265,7 @@ int var8 = this.getSavedLightValue(EnumSkyBlock.Block, par2 - 1, par3, par4) - par6; int var9 = this.getSavedLightValue(EnumSkyBlock.Block, par2 + 1, par3, par4) - par6; int var10 = this.getSavedLightValue(EnumSkyBlock.Block, par2, par3 - 1, par4) - par6; -@@ -3668,10 +3668,10 @@ +@@ -3668,10 +3675,10 @@ public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) { this.entitiesWithinAABBExcludingEntity.clear(); @@ -266,7 +280,7 @@ for (int var7 = var3; var7 <= var4; ++var7) { -@@ -3692,10 +3692,10 @@ +@@ -3692,10 +3699,10 @@ */ public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB) { @@ -281,7 +295,7 @@ ArrayList var7 = new ArrayList(); for (int var8 = var3; var8 <= var4; ++var8) -@@ -3840,7 +3840,10 @@ +@@ -3840,7 +3847,10 @@ { var8 = null; } @@ -293,7 +307,7 @@ return par1 > 0 && var8 == null && var9.canPlaceBlockOnSide(this, par2, par3, par4, par6); } } -@@ -4449,4 +4452,39 @@ +@@ -4449,4 +4459,39 @@ { return this.worldInfo.getTerrainType() == WorldType.FLAT ? 0.0D : 63.0D; }