ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPage.java

97 lines
3.1 KiB
Java
Raw Normal View History

2016-01-05 14:57:50 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BookletPageAA.java") is part of the Actually Additions mod for Minecraft.
2016-01-05 14:57:50 +01: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
2016-01-05 14:57:50 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2016-01-05 14:57:50 +01:00
*/
package de.ellpeck.actuallyadditions.mod.booklet.page;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.api.booklet.internal.IPageGui;
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
2016-01-05 14:57:50 +01:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
2016-01-05 14:57:50 +01:00
import java.util.Map;
public class BookletPage implements IBookletPage{
protected IBookletChapter chapter;
2016-01-05 14:57:50 +01:00
2016-10-31 19:05:29 +01:00
protected List<FluidStack> fluidsForPage = new ArrayList<FluidStack>();
protected List<ItemStack> itemsForPage = new ArrayList<ItemStack>();
2016-01-05 14:57:50 +01:00
protected boolean hasNoText;
protected final HashMap<String, String> textReplacements = new HashMap<String, String>();
protected final int localizationKey;
public BookletPage(int localizationKey){
2016-01-05 14:57:50 +01:00
this.localizationKey = localizationKey;
}
@Override
public ItemStack[] getItemStacksForPage(){
return this.itemsForPage.toArray(new ItemStack[this.itemsForPage.size()]);
}
@Override
public FluidStack[] getFluidStacksForPage(){
return this.fluidsForPage.toArray(new FluidStack[this.fluidsForPage.size()]);
2016-01-05 14:57:50 +01:00
}
@Override
public IBookletChapter getChapter(){
return this.chapter;
}
@Override
public void setChapter(IBookletChapter chapter){
this.chapter = chapter;
}
@Override
public IPageGui createGui(){
return null;
}
@Override
public String getInfoText(){
2016-01-05 14:57:50 +01:00
if(this.hasNoText){
return null;
}
String base = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getIdentifier()+".text."+this.localizationKey);
2016-03-18 23:47:22 +01:00
base = base.replaceAll("<imp>", TextFormatting.DARK_GREEN+"");
base = base.replaceAll("<item>", TextFormatting.BLUE+"");
base = base.replaceAll("<r>", TextFormatting.BLACK+"");
2016-01-05 14:57:50 +01:00
base = base.replaceAll("<n>", "\n");
2016-03-18 23:47:22 +01:00
base = base.replaceAll("<i>", TextFormatting.ITALIC+"");
base = base.replaceAll("<tifisgrin>", TextFormatting.DARK_RED+""+TextFormatting.UNDERLINE); //This is fucking important so go read it now
2016-01-05 14:57:50 +01:00
2016-08-02 01:06:21 +02:00
for(Map.Entry<String, String> entry : this.textReplacements.entrySet()){
base = base.replaceAll(entry.getKey(), entry.getValue());
2016-01-05 14:57:50 +01:00
}
return base;
}
public BookletPage addFluidToPage(Fluid fluid){
this.fluidsForPage.add(new FluidStack(fluid, 1));
return this;
2016-02-01 17:49:55 +01:00
}
public BookletPage addItemToPage(ItemStack stack){
this.itemsForPage.add(stack);
return this;
2016-02-01 17:49:55 +01:00
}
}