Skip to content

Commit

Permalink
Lookup namespace in resource packs if mod not present
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Feb 11, 2024
1 parent 6946034 commit d9fb713
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.orecruncher.dsurround.config.IndividualSoundConfigEntry;
Expand All @@ -25,10 +26,7 @@
import org.orecruncher.dsurround.sound.IAudioPlayer;
import org.orecruncher.dsurround.sound.SoundMetadata;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.*;

public class IndividualSoundControlListEntry extends ContainerObjectSelectionList.Entry<IndividualSoundControlListEntry> implements AutoCloseable {

Expand Down Expand Up @@ -250,7 +248,7 @@ protected List<FormattedCharSequence> getToolTip(final int mouseX, final int mou
// Cache the static part of the tooltip if needed
if (this.cachedToolTip.isEmpty()) {
ResourceLocation id = this.config.soundEventId;
PLATFORM.getModDisplayName(id.getNamespace())
this.resolveDisplayName(id.getNamespace())
.ifPresent(name -> {
FormattedCharSequence modName = FormattedCharSequence.forward(Objects.requireNonNull(ChatFormatting.stripFormatting(name)), STYLE_MOD_NAME);
this.cachedToolTip.add(modName);
Expand Down Expand Up @@ -311,6 +309,18 @@ protected List<FormattedCharSequence> getToolTip(final int mouseX, final int mou
return generatedTip;
}

private Optional<String> resolveDisplayName(String namespace) {
var displayName = PLATFORM.getModDisplayName(namespace);
if (displayName.isPresent())
return displayName;

// Could be a resource pack
return GameUtils.getResourceManager().listPacks()
.filter(pack -> pack.getNamespaces(PackType.CLIENT_RESOURCES).contains(namespace))
.map(PackResources::packId)
.findAny();
}

/**
* Retrieves the updated data from the entry
*
Expand Down

0 comments on commit d9fb713

Please sign in to comment.