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

[1.21.3] Render Minecraft logo as builtin mods logoFile #1617

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
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
55 changes: 31 additions & 24 deletions src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.LogoRenderer;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -374,30 +375,36 @@ private void updateCache() {
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);

@SuppressWarnings("resource")
Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final Pack.ResourcesSupplier resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId())
.orElse(ResourcePackLoader.getPackFor("neoforge").orElseThrow(() -> new RuntimeException("Can't find neoforge, WHAT!")));
try (PackResources packResources = resourcePack.openPrimary(new PackLocationInfo("mod/" + selectedMod.getModId(), Component.empty(), PackSource.BUILT_IN, Optional.empty()))) {
NativeImage logo = null;
IoSupplier<InputStream> logoResource = packResources.getRootResource(logoFile.split("[/\\\\]"));
if (logoResource != null)
logo = NativeImage.read(logoResource.get());
if (logo != null) {

return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException | IllegalArgumentException e) {}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
Pair<ResourceLocation, Size2i> logoData;

if (selectedMod.getModId().equals(ResourceLocation.DEFAULT_NAMESPACE)) {
logoData = Pair.of(LogoRenderer.MINECRAFT_LOGO, new Size2i(LogoRenderer.LOGO_TEXTURE_WIDTH, LogoRenderer.LOGO_TEXTURE_HEIGHT));
} else {
logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final Pack.ResourcesSupplier resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId())
.orElse(ResourcePackLoader.getPackFor("neoforge").orElseThrow(() -> new RuntimeException("Can't find neoforge, WHAT!")));
try (PackResources packResources = resourcePack.openPrimary(new PackLocationInfo("mod/" + selectedMod.getModId(), Component.empty(), PackSource.BUILT_IN, Optional.empty()))) {
NativeImage logo = null;
IoSupplier<InputStream> logoResource = packResources.getRootResource(logoFile.split("[/\\\\]"));
if (logoResource != null)
logo = NativeImage.read(logoResource.get());
if (logo != null) {

return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException | IllegalArgumentException e) {}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
}

lines.add(selectedMod.getDisplayName());
lines.add(FMLTranslations.parseMessage("fml.menu.mods.info.version", MavenVersionTranslator.artifactVersionToString(selectedMod.getVersion())));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,6 @@ public net.minecraft.world.item.enchantment.Enchantment locationContext(Lnet/min
public net.minecraft.world.item.enchantment.Enchantment entityContext(Lnet/minecraft/server/level/ServerLevel;ILnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/level/storage/loot/LootContext;
public net.minecraft.world.item.enchantment.Enchantment blockHitContext(Lnet/minecraft/server/level/ServerLevel;ILnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/storage/loot/LootContext;
public net.minecraft.world.item.enchantment.Enchantment applyEffects(Ljava/util/List;Lnet/minecraft/world/level/storage/loot/LootContext;Ljava/util/function/Consumer;)V
# Made public for mc logo render in mods list
public net.minecraft.client.gui.components.LogoRenderer LOGO_TEXTURE_WIDTH
public net.minecraft.client.gui.components.LogoRenderer LOGO_TEXTURE_HEIGHT