Skip to main content

Sound effects

Introduction​

If you want to customize the global sound experience of Lasers Enigma, you’ve come to the right place. This guide explains how to replace the default sounds triggered by in-game actions (such as creating or deleting an area) with your own custom effects.

Replace Existing Sounds​

1. Identify Replaceable Sounds​

Before you begin customising, you need to know which sounds can be replaced. To do this, refer to the PlaySoundCause enum. Each constant in this enum represents a specific sound event in Lasers Enigma you can replace.

2. Intercept the PlaySoundEvent​

In your plugin, listen for the PlaySoundEvent to intercept the default sound and replace it with your own. For example:

@EventHandler
public void onPlaySoundListener(PlaySoundEvent playSoundEvent) {
switch (event.getPlaySoundCause()) {
case CONCENTRATOR_ROTATE, LASER_SENDER_ROTATE, LASER_RECEIVER_ROTATE, MIRROR_SUPPORT_ROTATE:
// Cancel the default sound effect
event.setCancelled(true);

World world = event.getLocation().getWorld();

if (world == null) return;

// Play your custom sound
world.playSound(event.getLocation(), "lasers-enigma.rotate", 1.0f, 1.0f);
break;
default:
break;
}
}

Note: The Sound "lasers-enigma.rotate" must be included in your Ressource Pack. Ensure you add it to your sounds.json file.

3. Configure Your Resource Pack​

To register your custom sound with Minecraft, update your resource pack as follows:

Example of my_ressource_pack/minecraft/sounds.json:

{
"lasers-enigma.rotate": {
"sounds": [
"lasers-enigma/rotate_1",
"lasers-enigma/rotate_2",
"lasers-enigma/rotate_3",
"lasers-enigma/rotate_4"
]
}
}

Directory Structure:

sounds
└── lasers-enigma
├── rotate_1.ogg
├── rotate_2.ogg
├── rotate_3.ogg
└── rotate_4.ogg

Recommendations​

To automate the process of replacing sounds, consider dynamically constructing the sound name using the enum constant. For example:

private static final String LASERS_ENIGMA_SOUND_NAME_PREFIX = "lasers-enigma.";

@EventHandler
public void onPlaySoundListener(PlaySoundEvent event) {
switch (event.getPlaySoundCause()) {
case CONCENTRATOR_COLOR_CHANGE, LASER_RECEIVER_ACTIVATED, MIRROR_INSERT_SUPPORT, MIRROR_EXTRACT_SUPPORT,
MIRROR_INSERT_SPHERE, MIRROR_EXTRACT_SPHERE, CLAY_MELTDOWN, REACHED_AREA_WIN_CONDITIONS:
event.setCancelled(true);
playSound(event, event.getPlaySoundCause().name().toLowerCase(Locale.ROOT));
break;
default:
break;
}
}

private void playSound(PlaySoundEvent event, String soundName) {
World world = event.getLocation().getWorld();

if (world == null) return;

world.playSound(event.getLocation(), LASERS_ENIGMA_SOUND_NAME_PREFIX + soundName, 1.0f, 1.0f
);
}

Important: Ensure that the sound names in your sounds.json file exactly match the enumeration constants (converted to lowercase).

Known issues​

For more details on known issues, please check our issue board.