- 57
- 3
- 7
Пользовался справочным материалом учебника, сделал как там, но что-то не так, звук не хочет воспроизводиться:
MainEvent
CommonProxy
Sounds
sounds.json
Расположние файлов:
MainEvent
Java:
import com.mod.currentmagic.Sounds;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class MainEvent {
@SubscribeEvent
public void RightClick(PlayerInteractEvent.RightClickEmpty event) {
if(event.getEntity() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) event.getEntity();
event.getWorld().playSound(player.posX, player.posY, player.posZ, Sounds.test, SoundCategory.PLAYERS,
1F, 1F, false);
}
}
}
CommonProxy
Java:
import com.mod.currentmagic.Sounds;
import com.mod.currentmagic.events.MainEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
public class CommonProxy
{
public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new MainEvent());
MinecraftForge.EVENT_BUS.register(new Sounds());
}
public void init(FMLInitializationEvent event) {
}
public void postInit(FMLPostInitializationEvent event) {
}
}
Sounds
Java:
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
public class Sounds {
public static final SoundEvent test = registry("test_sound");
@SubscribeEvent
public void registerSounds(RegistryEvent.Register<SoundEvent> e) {
ForgeRegistries.SOUND_EVENTS.register(test);
}
private static SoundEvent registry(String name) {
ResourceLocation uniqueName = new ResourceLocation("current-magic", name);
return new SoundEvent(uniqueName).setRegistryName(uniqueName);
}
}
sounds.json
JSON:
{
"test_sound": {
"category": "player",
"sounds": [
{
"name": "current-magic:flame",
"stream": true
}
]
}
}
Расположние файлов: