2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.entry;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2016-01-05 14:57:50 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
2016-11-12 12:26:36 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
2016-11-12 12:26:36 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2017-06-17 00:48:49 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2016-11-12 12:26:36 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-11-12 12:26:36 +01:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2016-11-12 15:48:24 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class BookletEntry implements IBookletEntry {
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2016-08-02 00:36:14 +02:00
|
|
|
private final String identifier;
|
2016-11-22 22:54:35 +01:00
|
|
|
private final int priority;
|
2019-02-27 19:53:05 +01:00
|
|
|
private final List<IBookletChapter> chapters = new ArrayList<>();
|
2016-03-18 23:47:22 +01:00
|
|
|
private TextFormatting color;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public BookletEntry(String identifier) {
|
2016-11-22 22:54:35 +01:00
|
|
|
this(identifier, 0);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public BookletEntry(String identifier, int prio) {
|
2016-08-02 00:36:14 +02:00
|
|
|
this.identifier = identifier;
|
2016-11-22 22:54:35 +01:00
|
|
|
this.priority = prio;
|
2016-01-05 14:57:50 +01:00
|
|
|
ActuallyAdditionsAPI.addBookletEntry(this);
|
2015-10-23 19:05:02 +02:00
|
|
|
|
2016-03-18 23:47:22 +01:00
|
|
|
this.color = TextFormatting.RESET;
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 20:31:16 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
private static boolean fitsFilter(IBookletPage page, String searchBarText) {
|
2016-11-16 20:31:16 +01:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
List<ItemStack> items = new ArrayList<>();
|
2016-11-16 20:31:16 +01:00
|
|
|
page.getItemStacksForPage(items);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!items.isEmpty()) {
|
|
|
|
for (ItemStack stack : items) {
|
|
|
|
if (StackUtil.isValid(stack)) {
|
2017-06-17 00:48:49 +02:00
|
|
|
List<String> tooltip = stack.getTooltip(mc.player, mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
|
2019-05-02 09:10:29 +02:00
|
|
|
for (String strg : tooltip) {
|
|
|
|
if (strg != null && strg.toLowerCase(Locale.ROOT).contains(searchBarText)) { return true; }
|
2016-11-16 20:31:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
List<FluidStack> fluids = new ArrayList<>();
|
2016-11-16 20:31:16 +01:00
|
|
|
page.getFluidStacksForPage(fluids);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!fluids.isEmpty()) {
|
|
|
|
for (FluidStack stack : fluids) {
|
|
|
|
if (stack != null) {
|
2016-11-16 20:31:16 +01:00
|
|
|
String strg = stack.getLocalizedName();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (strg != null && strg.toLowerCase(Locale.ROOT).contains(searchBarText)) { return true; }
|
2016-11-16 20:31:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:57:50 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public List<IBookletChapter> getAllChapters() {
|
2016-01-05 14:57:50 +01:00
|
|
|
return this.chapters;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public String getIdentifier() {
|
2016-08-02 00:36:14 +02:00
|
|
|
return this.identifier;
|
2016-01-05 14:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public String getLocalizedName() {
|
|
|
|
return StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".indexEntry." + this.getIdentifier() + ".name");
|
2015-10-28 14:46:04 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public String getLocalizedNameWithFormatting() {
|
|
|
|
return this.color + this.getLocalizedName();
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void addChapter(IBookletChapter chapter) {
|
2016-02-01 17:49:55 +01:00
|
|
|
this.chapters.add(chapter);
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
@Override
|
2016-11-12 15:48:24 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public List<IBookletChapter> getChaptersForDisplay(String searchBarText) {
|
|
|
|
if (searchBarText != null && !searchBarText.isEmpty()) {
|
2016-11-12 12:26:36 +01:00
|
|
|
String search = searchBarText.toLowerCase(Locale.ROOT);
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
List<IBookletChapter> fittingChapters = new ArrayList<>();
|
2019-05-02 09:10:29 +02:00
|
|
|
for (IBookletChapter chapter : this.getAllChapters()) {
|
|
|
|
if (chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(search)) {
|
2016-11-12 12:26:36 +01:00
|
|
|
fittingChapters.add(chapter);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
|
|
|
for (IBookletPage page : chapter.getAllPages()) {
|
|
|
|
if (fitsFilter(page, search)) {
|
2016-11-12 12:26:36 +01:00
|
|
|
fittingChapters.add(chapter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fittingChapters;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-12 12:26:36 +01:00
|
|
|
return this.getAllChapters();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 22:54:35 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getSortingPriority() {
|
2016-11-22 22:54:35 +01:00
|
|
|
return this.priority;
|
|
|
|
}
|
|
|
|
|
2017-02-18 00:54:58 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean visibleOnFrontPage() {
|
2017-02-18 00:54:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public BookletEntry setImportant() {
|
2016-03-18 23:47:22 +01:00
|
|
|
this.color = TextFormatting.DARK_GREEN;
|
2015-10-23 19:05:02 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public BookletEntry setSpecial() {
|
2016-03-18 23:47:22 +01:00
|
|
|
this.color = TextFormatting.DARK_PURPLE;
|
2015-10-23 19:05:02 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|