提供: Minecraft Modding Wiki
移動先: 案内検索

警告: ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。ログインまたはアカウントを作成すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
1行目: 1行目:
{{前提MOD|reqmod="Fabric API 0.3.2 build 230~"}}
 
{{チュートリアル難易度|difficulty=0|clear=none}}
 
<br>
 
<br>
 
<br>
 
<p>再生できるサウンドの追加方法</p>
 
==サウンドの追加==
 
===外部サイト===
 
[https://minecraft-ja.gamepedia.com/Sounds.json Sounds.jsonの書き方(Minecraft公式Wiki)]
 
===ソースコード===
 
  
*SampleMod.java
+
public class SampleMod {
<source lang = "java">
+
     public static final Identifier SAMPLE_SOUND_ID = new Identifier(MOD_ID":sample_sound")
package com.example.sound;
 
 
 
import net.fabricmc.api.ModInitializer;
 
import net.minecraft.sound.SoundEvent;
 
import net.minecraft.util.Identifier;
 
import net.minecraft.util.registry.Registry;
 
 
 
public class SampleMod implements ModInitializer {
 
     public static final Identifier SAMPLE_SOUND_ID = new Identifier("samplemod:sample_sound")
 
 
     public static SoundEvent SAMPLE_SOUND_EVENT = new SoundEvent(SAMPLE_SOUND_ID);
 
     public static SoundEvent SAMPLE_SOUND_EVENT = new SoundEvent(SAMPLE_SOUND_ID);
  
 
     @Override
 
     @Override
 
     public void onInitialize(){
 
     public void onInitialize(){
         Registry.register(Registry.SOUND_EVENT, SampleMod.SAMPLE_SOUND_ID, SAMPLE_SOUND_EVENT);
+
         Registry.register(Registry.SOUND_EVENT,                             SampleMod.SAMPLE_SOUND_ID, SAMPLE_SOUND_EVENT);
 
     }  
 
     }  
 
}
 
}
</source>
 
 
==サウンドの再生==
 
===ソースコード===
 
*SampleBlock.java
 
<source lang = "java">
 
//省略
 
    @Override
 
    public boolean activate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {
 
        if (!world.isClient) {
 
            world.playSound(
 
                    null, // Player (purpose unknown, edit if you know)
 
                    blockPos, // The position of where the sound will come from
 
                    SampleMod.SAMPLE_SOUND_EVENT, // The sound that will play
 
                    SoundCategory.BLOCKS, // This determines which of the volume sliders affect this sound
 
                    1f, //Volume multiplier, 1 is normal, 0.5 is half volume, etc
 
                    1f // Pitch multiplier, 1 is normal, 0.5 is half pitch, etc
 
            );
 
        }
 
        return false;
 
    }
 
//省略
 
</source>
 
*SampleItem.java
 
<source lang = "java">
 
package com.example.sound;
 
 
import net.minecraft.entity.player.PlayerEntity;
 
import net.minecraft.item.Item;
 
import net.minecraft.item.ItemStack;
 
import net.minecraft.util.ActionResult;
 
import net.minecraft.util.Hand;
 
import net.minecraft.util.TypedActionResult;
 
import net.minecraft.world.World;
 
 
public class SampleItem extends Item
 
{
 
    public SampleItem(Settings settings) {
 
        super(settings);
 
    }
 
    @Override
 
    public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand)
 
    {
 
        playerEntity.playSound(SampleMod.SAMPLE_SOUND_EVENT, 1.0F, 1.0F);
 
        return new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));
 
//19w37aではreturn new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand).true);となる。
 
 
    }
 
}
 
</source>
 
 
==解説==
 
<source lang = "java">
 
.playSound(SampleMod.SAMPLE_SOUND_EVENT, 1.0F, 1.0F)
 
</source>
 
再生することができる。
 

Minecraft Modding Wikiへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細はMinecraft Modding Wiki:著作権を参照)。 著作権保護されている作品は、許諾なしに投稿しないでください!

このページを編集するには、下記の確認用の質問に回答してください (詳細):

取り消し 編集の仕方 (新しいウィンドウで開きます)

このページで使用されているテンプレート: