Added the ability to add text replacements via the API

This commit is contained in:
Ellpeck 2016-08-02 01:22:50 +02:00
parent 3b3d28c3fc
commit 1e00615aaa
2 changed files with 19 additions and 17 deletions

View file

@ -16,10 +16,14 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.HashMap;
public abstract class BookletPage{ public abstract class BookletPage{
public boolean arePageStacksWildcard; public boolean arePageStacksWildcard;
protected IBookletChapter chapter; protected IBookletChapter chapter;
protected final HashMap<String, String> textReplacements = new HashMap<String, String>();
protected boolean hasNoText;
public void onOpened(IBookletGui gui){ public void onOpened(IBookletGui gui){
@ -88,4 +92,18 @@ public abstract class BookletPage{
this.arePageStacksWildcard = true; this.arePageStacksWildcard = true;
return this; return this;
} }
public BookletPage setNoText(){
this.hasNoText = true;
return this;
}
public BookletPage addTextReplacement(String text, int replacement){
return this.addTextReplacement(text, Integer.toString(replacement));
}
public BookletPage addTextReplacement(String text, String replacement){
this.textReplacements.put(text, replacement);
return this;
}
} }

View file

@ -26,8 +26,6 @@ import java.util.Map;
public class BookletPageAA extends BookletPage{ public class BookletPageAA extends BookletPage{
protected final int localizationKey; protected final int localizationKey;
private final HashMap<String, String> textReplacements = new HashMap<String, String>();
private boolean hasNoText;
public BookletPageAA(int localizationKey){ public BookletPageAA(int localizationKey){
this.localizationKey = localizationKey; this.localizationKey = localizationKey;
@ -39,7 +37,7 @@ public class BookletPageAA extends BookletPage{
} }
@Override @Override
public final String getText(){ public String getText(){
if(this.hasNoText){ if(this.hasNoText){
return null; return null;
} }
@ -83,20 +81,6 @@ public class BookletPageAA extends BookletPage{
return TextFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID+".clickToSeeRecipe"); return TextFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID+".clickToSeeRecipe");
} }
public BookletPage setNoText(){
this.hasNoText = true;
return this;
}
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(){ public void addToPagesWithItemStackData(){
if(!ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_DATA.contains(this)){ if(!ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_DATA.contains(this)){
ItemStack[] stacks = this.getItemStacksForPage(); ItemStack[] stacks = this.getItemStacksForPage();