Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend registry api #22

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public final class PlayerAnimationRegistry {
Expand All @@ -34,11 +35,41 @@ public static Optional<KeyframeAnimation> getAnimationOptional(@NotNull Resource
return Optional.ofNullable(getAnimation(identifier));
}

/**
* @return an unmodifiable map of all the animations
*/
public static Map<ResourceLocation, KeyframeAnimation> getAnimations() {
return Map.copyOf(animations);
}

/**
* Returns the animations of a specific mod/namespace
* @param modid namespace (assets/modid)
* @return map of path and animations
*/
public static Map<String, KeyframeAnimation> getModAnimations(String modid) {
HashMap<String, KeyframeAnimation> map = new HashMap<>();
for (Map.Entry<ResourceLocation, KeyframeAnimation> entry: animations.entrySet()) {
if (entry.getKey().getNamespace().equals(modid)) {
map.put(entry.getKey().getPath(), entry.getValue());
}
}
return map;
}

/**
* Clear animation registry, INTERNAL, only happens before resource loading
*/
@ApiStatus.Internal
public static void clearAnimation() {
animations.clear();
}

/**
* add animation to the registry, used by resource loader.
* @param location animation identifier
* @param animation animation
*/
@ApiStatus.Internal
public static void addAnimation(@NotNull ResourceLocation location, @NotNull KeyframeAnimation animation) {
animations.put(location, animation);
Expand Down