2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BookletEntry.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.booklet.entry;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
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;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.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
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2016-01-05 14:57:50 +01:00
|
|
|
import java.util.List;
|
2016-11-12 12:26:36 +01:00
|
|
|
import java.util.Locale;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2016-01-05 14:57:50 +01: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;
|
2016-11-11 15:21:57 +01:00
|
|
|
private final List<IBookletChapter> chapters = new ArrayList<IBookletChapter>();
|
2016-03-18 23:47:22 +01:00
|
|
|
private TextFormatting color;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2016-08-02 00:36:14 +02:00
|
|
|
public BookletEntry(String identifier){
|
2016-11-22 22:54:35 +01:00
|
|
|
this(identifier, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
private static boolean fitsFilter(IBookletPage page, String searchBarText){
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
|
|
|
List<ItemStack> items = new ArrayList<ItemStack>();
|
|
|
|
page.getItemStacksForPage(items);
|
|
|
|
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);
|
2016-11-16 20:31:16 +01:00
|
|
|
for(String strg : tooltip){
|
|
|
|
if(strg != null && strg.toLowerCase(Locale.ROOT).contains(searchBarText)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<FluidStack> fluids = new ArrayList<FluidStack>();
|
|
|
|
page.getFluidStacksForPage(fluids);
|
|
|
|
if(!fluids.isEmpty()){
|
|
|
|
for(FluidStack stack : fluids){
|
|
|
|
if(stack != null){
|
|
|
|
String strg = stack.getLocalizedName();
|
|
|
|
if(strg != null && strg.toLowerCase(Locale.ROOT).contains(searchBarText)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:57:50 +01:00
|
|
|
@Override
|
2016-11-10 19:50:01 +01:00
|
|
|
public List<IBookletChapter> getAllChapters(){
|
2016-01-05 14:57:50 +01:00
|
|
|
return this.chapters;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-02 00:36:14 +02:00
|
|
|
public String getIdentifier(){
|
|
|
|
return this.identifier;
|
2016-01-05 14:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-28 14:46:04 +01:00
|
|
|
public String getLocalizedName(){
|
2018-05-10 11:38:58 +02:00
|
|
|
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)
|
2016-02-01 17:49:55 +01:00
|
|
|
public String getLocalizedNameWithFormatting(){
|
|
|
|
return this.color+this.getLocalizedName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addChapter(IBookletChapter chapter){
|
|
|
|
this.chapters.add(chapter);
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
@Override
|
2016-11-12 15:48:24 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-11-12 12:26:36 +01:00
|
|
|
public List<IBookletChapter> getChaptersForDisplay(String searchBarText){
|
|
|
|
if(searchBarText != null && !searchBarText.isEmpty()){
|
|
|
|
String search = searchBarText.toLowerCase(Locale.ROOT);
|
|
|
|
|
|
|
|
List<IBookletChapter> fittingChapters = new ArrayList<IBookletChapter>();
|
|
|
|
for(IBookletChapter chapter : this.getAllChapters()){
|
|
|
|
if(chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(search)){
|
|
|
|
fittingChapters.add(chapter);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for(IBookletPage page : chapter.getAllPages()){
|
|
|
|
if(fitsFilter(page, search)){
|
|
|
|
fittingChapters.add(chapter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fittingChapters;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return this.getAllChapters();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 22:54:35 +01:00
|
|
|
@Override
|
|
|
|
public int getSortingPriority(){
|
|
|
|
return this.priority;
|
|
|
|
}
|
|
|
|
|
2017-02-18 00:54:58 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public boolean visibleOnFrontPage(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:51:20 +01: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;
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:51:20 +01: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
|
|
|
}
|