Don't crash server on startup trying to use sounds
This commit is contained in:
parent
585b0685d0
commit
43e67bdbd3
5 changed files with 69 additions and 29 deletions
src/main/java/StevenDimDoors
mod_pocketDim
mod_pocketDimClient
|
@ -2,6 +2,7 @@ package StevenDimDoors.mod_pocketDim;
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -12,6 +13,8 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class CommonProxy implements IGuiHandler
|
||||
{
|
||||
public static String BLOCK_PNG = "/PocketBlockTextures.png";
|
||||
|
@ -145,7 +148,7 @@ public class CommonProxy implements IGuiHandler
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void registerSidedHooks(DDProperties properties) {
|
||||
}
|
||||
|
||||
}
|
|
@ -51,12 +51,9 @@ public class EventHookContainer
|
|||
private DDWorldProperties worldProperties;
|
||||
private RiftRegenerator regenerator;
|
||||
|
||||
private ISound limboMusic;
|
||||
|
||||
public EventHookContainer(DDProperties properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
this.limboMusic = PositionedSoundRecord.func_147673_a(new ResourceLocation(mod_pocketDim.modid + ":creepy"));
|
||||
}
|
||||
|
||||
public void setSessionFields(DDWorldProperties worldProperties, RiftRegenerator regenerator)
|
||||
|
@ -82,24 +79,6 @@ public class EventHookContainer
|
|||
*/
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public void onSoundEffectResult(PlaySoundEvent17 event)
|
||||
{
|
||||
ResourceLocation playingSound = event.sound.getPositionedSoundLocation();
|
||||
if (playingSound != null && playingSound.getResourceDomain().equals("minecraft") && (playingSound.getResourcePath().equals("music.game") || playingSound.getResourcePath().equals("music.game.creative"))) {
|
||||
if (FMLClientHandler.instance().getClient().thePlayer.worldObj.provider.dimensionId == mod_pocketDim.properties.LimboDimensionID) {
|
||||
ResourceLocation sound = new ResourceLocation(mod_pocketDim.modid + ":creepy");
|
||||
|
||||
if (!Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(limboMusic)) {
|
||||
event.result = limboMusic;
|
||||
} else {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerEvent(PlayerInteractEvent event)
|
||||
{
|
||||
|
@ -144,11 +123,6 @@ public class EventHookContainer
|
|||
{
|
||||
PocketManager.load();
|
||||
}
|
||||
|
||||
if (event.world.provider.dimensionId == mod_pocketDim.properties.LimboDimensionID &&
|
||||
event.world.isRemote && !Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(limboMusic)) {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(limboMusic);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -177,6 +177,8 @@ public class mod_pocketDim
|
|||
hooks = new EventHookContainer(properties);
|
||||
MinecraftForge.EVENT_BUS.register(hooks);
|
||||
MinecraftForge.TERRAIN_GEN_BUS.register(hooks);
|
||||
|
||||
proxy.registerSidedHooks(properties);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package StevenDimDoors.mod_pocketDimClient;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundEvent17;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
public class ClientOnlyHooks {
|
||||
private DDProperties properties;
|
||||
|
||||
private ISound limboMusic;
|
||||
|
||||
public ClientOnlyHooks(DDProperties properties) {
|
||||
this.properties = properties;
|
||||
this.limboMusic = PositionedSoundRecord.func_147673_a(new ResourceLocation(mod_pocketDim.modid + ":creepy"));
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public void onSoundEffectResult(PlaySoundEvent17 event)
|
||||
{
|
||||
ResourceLocation playingSound = event.sound.getPositionedSoundLocation();
|
||||
if (playingSound != null && playingSound.getResourceDomain().equals("minecraft") && (playingSound.getResourcePath().equals("music.game") || playingSound.getResourcePath().equals("music.game.creative"))) {
|
||||
if (FMLClientHandler.instance().getClient().thePlayer.worldObj.provider.dimensionId == mod_pocketDim.properties.LimboDimensionID) {
|
||||
ResourceLocation sound = new ResourceLocation(mod_pocketDim.modid + ":creepy");
|
||||
|
||||
if (!Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(limboMusic)) {
|
||||
event.result = limboMusic;
|
||||
} else {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoad(WorldEvent.Load event) {
|
||||
if (event.world.provider.dimensionId == mod_pocketDim.properties.LimboDimensionID &&
|
||||
event.world.isRemote && !Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(limboMusic)) {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(limboMusic);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
package StevenDimDoors.mod_pocketDimClient;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.CommonProxy;
|
||||
|
@ -12,6 +13,7 @@ import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor;
|
|||
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
|
@ -49,5 +51,11 @@ public class ClientProxy extends CommonProxy
|
|||
public void printStringClient(String string)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerSidedHooks(DDProperties properties) {
|
||||
ClientOnlyHooks hooks = new ClientOnlyHooks(properties);
|
||||
MinecraftForge.EVENT_BUS.register(hooks);
|
||||
MinecraftForge.TERRAIN_GEN_BUS.register(hooks);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue