Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
make getting icons more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Jul 2, 2023
1 parent 0a8c9ed commit c697db7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/net/pl3x/map/mobs/markers/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import javax.imageio.ImageIO;
import net.pl3x.map.core.Pl3xMap;
Expand Down Expand Up @@ -239,8 +243,16 @@ <T extends Mob> Icon(@NotNull EntityType type, @Nullable Function<T, Boolean> pr
return this.type;
}

public static @NotNull Icon get(@NotNull Mob mob) {
private static final Map<EntityType, Set<Icon>> BY_TYPE = new HashMap<>();

static {
for (Icon icon : values()) {
BY_TYPE.computeIfAbsent(icon.getType(), k -> new HashSet<>()).add(icon);
}
}

public static @NotNull Icon get(@NotNull Mob mob) {
for (Icon icon : BY_TYPE.get(mob.getType())) {
if (icon.getType() == mob.getType()) {
if (icon.predicate == null || icon.predicate.apply(mob)) {
return icon;
Expand Down

0 comments on commit c697db7

Please sign in to comment.