提供: Minecraft Modding Wiki
(新規作成) |
(SideOnly) |
||
(他の1人の利用者による、間の1版が非表示) | |||
27行目: | 27行目: | ||
import net.minecraftforge.client.event.sound.SoundLoadEvent; | import net.minecraftforge.client.event.sound.SoundLoadEvent; | ||
import net.minecraftforge.event.ForgeSubscribe; | import net.minecraftforge.event.ForgeSubscribe; | ||
+ | import cpw.mods.fml.relauncher.Side; | ||
+ | import cpw.mods.fml.relauncher.SideOnly; | ||
public class SoundHandler | public class SoundHandler | ||
{ | { | ||
+ | @SideOnly(Side.CLIENT) | ||
@ForgeSubscribe | @ForgeSubscribe | ||
public void onSound(SoundLoadEvent event) | public void onSound(SoundLoadEvent event) | ||
{ | { | ||
try { | try { | ||
− | event.manager.addSound("soundsample: | + | event.manager.addSound("soundsample:hoge.ogg"); |
} catch (Exception e) { | } catch (Exception e) { | ||
System.err.println("Failed to register one or more sounds."); | System.err.println("Failed to register one or more sounds."); | ||
44行目: | 47行目: | ||
===SoundHandler.java=== | ===SoundHandler.java=== | ||
<source lang = "java"> | <source lang = "java"> | ||
+ | @SideOnly(Side.CLIENT) | ||
@ForgeSubscribe | @ForgeSubscribe | ||
public void onSound(SoundLoadEvent event) | public void onSound(SoundLoadEvent event) |
2014年6月28日 (土) 01:21時点における最新版
この記事は"Minecraft Forge Universal 9.10.0.xxx~"を前提MODとしています。 |
1.6のサウンドの追加[編集]
1.6でのサウンドの追加方法
ソースコード[編集]
- SoundSample.java
package mods.soundsample; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.event.FMLInitializationEvent; import net.minecraftforge.common.MinecraftForge; @Mod(modid="SoundSampleMod", name="SoundSampleMod", version="1.0") @NetworkMod(clientSideRequired=true, serverSideRequired=false) public class SoundSample { @Mod.EventHandler public void load(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new SoundHandler()); } }
- SoundHandler.java
package mods.soundsample; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.ForgeSubscribe; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class SoundHandler { @SideOnly(Side.CLIENT) @ForgeSubscribe public void onSound(SoundLoadEvent event) { try { event.manager.addSound("soundsample:hoge.ogg"); } catch (Exception e) { System.err.println("Failed to register one or more sounds."); } } }
解説[編集]
SoundHandler.java[編集]
@SideOnly(Side.CLIENT) @ForgeSubscribe public void onSound(SoundLoadEvent event) { try { event.manager.addSound("soundsample:hoge.ogg"); } catch (Exception e) { System.err.println("Failed to register one or more sounds."); } }
イベントによる登録。addSoundメソッドの引数で登録される音声ファイルのファイルパスは
"/assets/soundsample/sound/hoge.ogg"
となる。また、playsoundメソッド等に渡す文字列引数は
"soundsample:hoge"
となる。
SoundSample.java[編集]
@Mod.EventHandler public void load(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new SoundHandler()); }
先ほどのSoundHandlerクラスをForgeのイベントバスに登録。