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

116 lines
3.7 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.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.internal.IBookletGui;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
import org.apache.commons.lang3.ArrayUtils;
2016-01-05 14:57:50 +01:00
import java.util.HashMap;
import java.util.Map;
public class BookletPageAA extends BookletPage{
2016-05-19 20:05:12 +02:00
protected final int localizationKey;
private final HashMap<String, String> textReplacements = new HashMap<String, String>();
2016-01-05 14:57:50 +01:00
private boolean hasNoText;
public BookletPageAA(int localizationKey){
this.localizationKey = localizationKey;
}
@Override
public int getID(){
return this.chapter.getPageId(this);
2016-01-05 14:57:50 +01:00
}
@Override
public final String getText(){
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
for(Object o : this.textReplacements.entrySet()){
Map.Entry e = (Map.Entry)o;
base = base.replaceAll((String)e.getKey(), (String)e.getValue());
}
return base;
}
@Override
2016-02-01 17:49:55 +01:00
public void renderPre(IBookletGui gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
2016-01-05 14:57:50 +01:00
}
@Override
2016-02-01 17:49:55 +01:00
public void render(IBookletGui gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
2016-01-05 14:57:50 +01:00
}
@Override
public void updateScreen(int ticksElapsed){
}
2016-02-01 17:49:55 +01:00
@Override
public ItemStack[] getItemStacksForPage(){
return null;
}
@Override
public String getClickToSeeRecipeString(){
2016-04-20 21:39:03 +02:00
return TextFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID+".clickToSeeRecipe");
2016-02-01 17:49:55 +01:00
}
public BookletPage setNoText(){
this.hasNoText = true;
return this;
}
2016-01-05 14:57:50 +01:00
public BookletPageAA addTextReplacement(String text, int replacement){
return this.addTextReplacement(text, Integer.toString(replacement));
}
public BookletPageAA addTextReplacement(String text, String replacement){
this.textReplacements.put(text, replacement);
return this;
}
public void addToPagesWithItemStackData(){
2016-05-19 20:05:12 +02:00
if(!ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_DATA.contains(this)){
2016-01-05 14:57:50 +01:00
ItemStack[] stacks = this.getItemStacksForPage();
if(stacks != null && stacks.length > 0){
//Ensure that there is at least one ItemStack
for(ItemStack stack : stacks){
if(stack != null){
ActuallyAdditionsAPI.addPageWithItemStackData(this);
break;
}
}
}
}
}
}