generated from liachmodded/carttemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: liach <liach@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/code/java/com/github/liachmodded/kayak/client/sound/EntitySpecificSoundManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.github.liachmodded.kayak.client.sound; | ||
|
||
import com.google.common.collect.MapMaker; | ||
import java.util.Map; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public final class EntitySpecificSoundManager { | ||
|
||
private final Map<Entity, StoppableEntityTrackingSoundInstance> specificSounds; | ||
|
||
public EntitySpecificSoundManager() { | ||
specificSounds = new MapMaker().weakKeys().weakValues().makeMap(); | ||
} | ||
|
||
public void put(Entity entity, StoppableEntityTrackingSoundInstance sound) { | ||
StoppableEntityTrackingSoundInstance previous = specificSounds.put(entity, sound); | ||
if (previous != null) { | ||
previous.stop(); | ||
} | ||
MinecraftClient.getInstance().getSoundManager().play(sound); | ||
} | ||
|
||
public void remove(Entity entity) { | ||
StoppableEntityTrackingSoundInstance previous = specificSounds.remove(entity); | ||
if (previous != null) { | ||
previous.stop(); | ||
} | ||
} | ||
|
||
public @Nullable StoppableEntityTrackingSoundInstance get(Entity entity) { | ||
return specificSounds.get(entity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters