Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public interface IModData

boolean isLogoSmooth();

boolean isLibrary();
default boolean isLibrary()
{
Type type = this.getType();
return type == Type.LIBRARY || type == Type.GENERATED;
}

void openConfigScreen(Screen parent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -162,13 +163,11 @@ public int getInnerWidth() {
};
this.searchTextField.addFormatter(this::formatQuery);
this.searchTextField.setMaxLength(128);
this.searchTextField.setValue(OPTION_QUERY.getValue());
this.searchTextField.setValue(OPTION_QUERY.get());
this.searchTextField.setResponder(s -> {
if(!OPTION_QUERY.getValue().equals(s)) {
if(!OPTION_QUERY.get().equals(s)) {
OPTION_QUERY.setValue(s);
this.updateSearchFieldSuggestion(s);
this.modList.filterAndUpdateList();
this.updateSelectedModList();
}
});
this.addWidget(this.searchTextField);
Expand Down Expand Up @@ -252,14 +251,12 @@ public int getInnerWidth() {
if(this.selectedModData != null)
{
this.setSelectedModData(this.selectedModData);
this.updateSelectedModList();
ModListEntry entry = this.modList.getEntryFromInfo(this.selectedModData);
ModListEntry entry = this.modList.getSelected();
if(entry != null)
{
this.modList.centerScrollOn(entry);
}
}
this.updateSearchFieldSuggestion(this.searchTextField.getValue());
}

/**
Expand Down Expand Up @@ -289,7 +286,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
boolean inMenu = this.menu != null;
super.render(graphics, inMenu ? -1000 : mouseX, inMenu ? -1000 : mouseY, partialTicks);

if(OPTION_QUERY.getValue().startsWith("@"))
if(OPTION_QUERY.get().startsWith("@"))
{
int iconX = this.searchTextField.getX() + this.searchTextField.getWidth() - 15;
int iconY = this.searchTextField.getY() + (this.searchTextField.getHeight() - 10) / 2;
Expand Down Expand Up @@ -352,17 +349,9 @@ private void setTooltip(GuiGraphics graphics, Component message, int mouseX, int
graphics.setTooltipForNextFrame(this.font.split(message, Math.min(200, this.width)), mouseX, mouseY);
}

private void updateSelectedModList()
{
ModListEntry selectedEntry = this.modList.getEntryFromInfo(this.selectedModData);
if(selectedEntry != null)
{
this.modList.setSelected(selectedEntry);
}
}

private void updateSearchFieldSuggestion(String value)
private void updateSearchFieldSuggestion()
{
String value = this.searchTextField.getValue();
if(value.isEmpty())
{
this.searchTextField.setSuggestion(Component.translatable("catalogue.gui.search").append(Component.literal("...")).getString());
Expand Down Expand Up @@ -395,7 +384,7 @@ else if(value.startsWith("@"))
else
{
Optional<IModData> optional = CACHED_MODS.values().stream().filter(data -> {
return data.getDisplayName().toLowerCase(Locale.ENGLISH).startsWith(value.toLowerCase(Locale.ENGLISH));
return ModList.FILTER_PREDICATE.test(data) && data.getDisplayName().toLowerCase(Locale.ENGLISH).startsWith(value.toLowerCase(Locale.ENGLISH));
}).min(Comparator.comparing(IModData::getDisplayName));
if(optional.isPresent())
{
Expand Down Expand Up @@ -543,21 +532,23 @@ private void drawModInfo(GuiGraphics graphics, int mouseX, int mouseY, float par
* @param y the y position
* @param maxWidth the maximum width the string can render
* @param mouseX the current mouse x position
* @param mouseY the current mouse u position
* @param mouseY the current mouse y position
*/
private void drawStringWithLabel(GuiGraphics graphics, String format, String text, int x, int y, int maxWidth, int mouseX, int mouseY, ChatFormatting labelColor, ChatFormatting contentColor)
{
Component formatted = ClientServices.COMPONENT.createFormatted(format, text);
String rawString = formatted.getString();
String label = rawString.substring(0, rawString.indexOf(":") + 1);
String content = rawString.substring(rawString.indexOf(":") + 1);
String colon = rawString.contains(":") ? ":" : ":";
String label = rawString.substring(0, rawString.indexOf(colon) + 1);
String content = rawString.substring(rawString.indexOf(colon) + 1);
if(this.font.width(formatted) > maxWidth)
{
content = this.font.plainSubstrByWidth(content, maxWidth - this.font.width(label) - 7) + "...";
MutableComponent credits = Component.literal(label).withStyle(labelColor);
credits.append(Component.literal(content).withStyle(contentColor));
graphics.drawString(this.font, credits, x, y, 0xFFFFFFFF);
if(ClientHelper.isMouseWithin(x, y, maxWidth, 9, mouseX, mouseY)) // Sets the active tool tip if string is too long so users can still read it
// Sets the active tool tip if string is too long so users can still read it
if(ClientHelper.isMouseWithin(x, y, maxWidth, 9, mouseX, mouseY))
{
this.setTooltip(graphics, Component.literal(text), mouseX, mouseY);
}
Expand Down Expand Up @@ -598,6 +589,10 @@ public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
}
}
}
if(event.button() == GLFW.GLFW_MOUSE_BUTTON_RIGHT && this.searchTextField.isActive() && this.searchTextField.isHovered())
{
this.searchTextField.setValue("");
}
return super.mouseClicked(event, doubleClick);
}

Expand Down Expand Up @@ -799,7 +794,7 @@ private void reloadBackground(IModData data)
private class ModList extends ObjectSelectionList<ModListEntry>
{
private static final Predicate<IModData> SEARCH_PREDICATE = data -> {
String query = OPTION_QUERY.getValue();
String query = OPTION_QUERY.get();
if(query.startsWith("@")) {
return performSearchFilter(query, data);
}
Expand All @@ -809,7 +804,7 @@ private class ModList extends ObjectSelectionList<ModListEntry>
};
private static final Predicate<IModData> FILTER_PREDICATE = data -> {
// We ignore filters when using special query
String query = OPTION_QUERY.getValue();
String query = OPTION_QUERY.get();
if(query.startsWith("@")) {
return true;
}
Expand Down Expand Up @@ -868,9 +863,15 @@ public void filterAndUpdateList()
.filter(SEARCH_PREDICATE)
.filter(FILTER_PREDICATE)
.map(info -> new ModListEntry(info, this))
.sorted(OPTION_SORT.getValue())
.sorted(OPTION_SORT.get())
.collect(Collectors.toList());
this.replaceEntries(entries);
if(CatalogueModListScreen.this.selectedModData != null)
{
Optional<ModListEntry> selectedEntry = this.children().stream().filter(entry -> entry.data == CatalogueModListScreen.this.selectedModData).findFirst();
selectedEntry.ifPresent(this::setSelected);
}
CatalogueModListScreen.this.updateSearchFieldSuggestion();
this.refreshScrollAmount();
}

Expand All @@ -882,12 +883,6 @@ public Optional<GuiEventListener> getChildAt(double mouseX, double mouseY)
return super.getChildAt(mouseX, mouseY);
}

@Nullable
public ModListEntry getEntryFromInfo(IModData data)
{
return this.children().stream().filter(entry -> entry.data == data).findFirst().orElse(null);
}

@Override
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks)
{
Expand Down Expand Up @@ -976,7 +971,7 @@ private static boolean performSearchFilter(String query, IModData data)

private FormattedCharSequence formatQuery(String partial, int displayPos)
{
String query = OPTION_QUERY.getValue();
String query = OPTION_QUERY.get();
if(!query.startsWith("@"))
return FormattedCharSequence.forward(partial, Style.EMPTY);

Expand Down Expand Up @@ -1021,8 +1016,8 @@ public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean
// Draws mod name and version
boolean inOptionsMenu = CatalogueModListScreen.this.menu != null;
boolean drawFavouriteIcon = !inOptionsMenu && !this.list.shouldHideFavourites() && ClientHelper.isMouseWithin(this.getX() + this.getWidth() - this.getHeight() - 4, this.getY(), this.getHeight() + 4, this.getHeight(), mouseX, mouseY) || FAVOURITES.has(this.data.getModId());
graphics.drawString(CatalogueModListScreen.this.font, this.getFormattedModName(drawFavouriteIcon), this.getX() + 24, this.getY() + 4, 0xFFFFFFFF);
graphics.drawString(CatalogueModListScreen.this.font, Component.literal(this.data.getVersion()).withStyle(ChatFormatting.GRAY), this.getX() + 24, this.getY() + 14, 0xFFFFFFFF);
graphics.drawString(CatalogueModListScreen.this.font, this.getFormattedText(this.data.getDisplayName(), drawFavouriteIcon).withStyle(this.data.getType().getStyle()), this.getX() + 24, this.getY() + 4, 0xFFFFFFFF);
graphics.drawString(CatalogueModListScreen.this.font, this.getFormattedText(this.data.getVersion(), drawFavouriteIcon).withStyle(ChatFormatting.GRAY), this.getX() + 24, this.getY() + 14, 0xFFFFFFFF);

// Draw image icon or fallback to item icon
this.drawIcon(graphics, this.getX(), this.getY());
Expand Down Expand Up @@ -1084,6 +1079,12 @@ private Item getItemIcon()
// Put grass as default item icon
ITEM_ICON_CACHE.put(this.data.getModId(), Items.GRASS_BLOCK);

// Minecraft is a grass block
if(this.data.getModId().equals("minecraft"))
{
return Items.GRASS_BLOCK;
}

// Special case for Forge to set item icon to anvil
if(this.data.getModId().equals("forge"))
{
Expand All @@ -1107,8 +1108,13 @@ private Item getItemIcon()
}
}

// If the mod has a creative tab, Catalogue will attempt to use the tab's icon
Optional<Item> optional = BuiltInRegistries.CREATIVE_MODE_TAB.stream().map(CreativeModeTab::getIconItem).map(ItemStack::getItem).filter(item -> item.builtInRegistryHolder().key().identifier().getNamespace().equals(this.data.getModId())).findFirst();
// If the mod doesn't specify an item to use, Catalogue will attempt to get an item from the mod
Optional<Item> optional = BuiltInRegistries.ITEM.stream().filter(item -> item.builtInRegistryHolder().key().identifier().getNamespace().equals(this.data.getModId())).findFirst();
if(optional.isEmpty())
{
optional = BuiltInRegistries.ITEM.stream().filter(item -> item.builtInRegistryHolder().key().identifier().getNamespace().equals(this.data.getModId())).findFirst();
}
if(optional.isPresent())
{
Item item = optional.get();
Expand All @@ -1122,9 +1128,8 @@ private Item getItemIcon()
return Items.GRASS_BLOCK;
}

private Component getFormattedModName(boolean favouriteIconVisible)
private MutableComponent getFormattedText(String text, boolean favouriteIconVisible)
{
String name = this.data.getDisplayName();
int paddingEnd = 4;
int trimWidth = this.list.getRowWidth() - 24 - paddingEnd;
IModData.Update update = this.data.getUpdate();
Expand All @@ -1136,16 +1141,11 @@ private Component getFormattedModName(boolean favouriteIconVisible)
{
trimWidth -= 18;
}
if(CatalogueModListScreen.this.font.width(name) > trimWidth)
{
name = CatalogueModListScreen.this.font.plainSubstrByWidth(name, trimWidth - 8).trim() + "...";
}
MutableComponent title = Component.literal(name);
if(this.data.isLibrary())
if(CatalogueModListScreen.this.font.width(text) > trimWidth)
{
title.withStyle(ChatFormatting.DARK_GRAY);
text = CatalogueModListScreen.this.font.plainSubstrByWidth(text, trimWidth - 8).trim() + "...";
}
return title;
return Component.literal(text);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getImageIcon()
@Override
public String getLicense()
{
return "All Rights Reserved";
return "All Rights Reserved (https://www.minecraft.net/en-us/eula)";
}

@Nullable
Expand Down Expand Up @@ -92,7 +92,7 @@ public String getHomepage()
@Override
public String getIssueTracker()
{
return "https://bugs.mojang.com/projects/MC/issues";
return "https://bugs.mojang.com/browse/MC";
}

@Nullable
Expand Down Expand Up @@ -133,12 +133,6 @@ public boolean isLogoSmooth()
return true;
}

@Override
public boolean isLibrary()
{
return true;
}

@Override
public void openConfigScreen(Screen parent)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float
{
super.renderWidget(graphics, mouseX, mouseY, deltaTick);
int offset = (this.getHeight() - 14) / 2;
graphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX() + this.getWidth() - 14 - offset, this.getY() + offset, this.isHoveredOrFocused() ? 14 : 0, this.holder.getValue() ? 14 : 0, 14, 14, 64, 64);
graphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX() + this.getWidth() - 14 - offset, this.getY() + offset, this.isHoveredOrFocused() ? 14 : 0, this.holder.get() ? 14 : 0, 14, 14, 64, 64);
}

@Override
public void onClick(MouseButtonEvent event, boolean doubleClick)
{
boolean newValue = !this.holder.getValue();
boolean newValue = !this.holder.get();
this.holder.setValue(newValue);
if(this.callback.apply(newValue))
{
Expand Down
Loading