ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java

139 lines
4.4 KiB
Java
Raw Normal View History

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
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 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;
2016-11-10 21:07:15 +01:00
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2016-11-12 12:26:36 +01:00
import net.minecraft.client.Minecraft;
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;
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
private final String identifier;
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
public BookletEntry(String identifier){
this.identifier = identifier;
2016-01-05 14:57:50 +01:00
ActuallyAdditionsAPI.addBookletEntry(this);
2016-03-18 23:47:22 +01:00
this.color = TextFormatting.RESET;
2015-08-28 21:17:09 +02:00
}
2016-01-05 14:57:50 +01:00
@Override
public List<IBookletChapter> getAllChapters(){
2016-01-05 14:57:50 +01:00
return this.chapters;
}
@Override
public String getIdentifier(){
return this.identifier;
2016-01-05 14:57:50 +01:00
}
@Override
2015-10-28 14:46:04 +01:00
public String getLocalizedName(){
return StringUtil.localize("booklet."+ModUtil.MOD_ID+".indexEntry."+this.getIdentifier()+".name");
2015-10-28 14:46:04 +01:00
}
2016-02-01 17:49:55 +01:00
@Override
public String getLocalizedNameWithFormatting(){
return this.color+this.getLocalizedName();
}
@Override
public void addChapter(IBookletChapter chapter){
this.chapters.add(chapter);
}
@Override
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();
}
}
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(stack != null){
List<String> tooltip = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
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;
}
public BookletEntry setImportant(){
2016-03-18 23:47:22 +01:00
this.color = TextFormatting.DARK_GREEN;
return this;
}
public BookletEntry setSpecial(){
2016-03-18 23:47:22 +01:00
this.color = TextFormatting.DARK_PURPLE;
return this;
}
2015-08-28 21:17:09 +02:00
}