2015-08-29 23:01:13 +02:00
|
|
|
/*
|
|
|
|
* This file ("BookletPage.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 23:01:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.booklet.page;
|
|
|
|
|
2015-11-29 14:30:44 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-11-11 18:51:20 +01:00
|
|
|
import ellpeck.actuallyadditions.booklet.BookletUtils;
|
2015-08-29 23:01:13 +02:00
|
|
|
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
|
|
|
import ellpeck.actuallyadditions.booklet.InitBooklet;
|
2015-11-11 18:51:20 +01:00
|
|
|
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
|
2015-08-30 01:19:03 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-08-29 23:01:13 +02:00
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
2015-08-30 01:19:03 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
2015-11-15 18:39:05 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2015-08-30 05:11:05 +02:00
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderItem;
|
2015-08-29 23:01:13 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-08-30 01:19:03 +02:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-08-30 05:11:05 +02:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
import org.lwjgl.opengl.GL12;
|
2015-08-29 23:01:13 +02:00
|
|
|
|
2015-09-12 20:35:43 +02:00
|
|
|
import java.util.HashMap;
|
2015-08-29 23:01:13 +02:00
|
|
|
import java.util.List;
|
2015-09-12 20:35:43 +02:00
|
|
|
import java.util.Map;
|
2015-08-29 23:01:13 +02:00
|
|
|
|
2015-09-10 21:25:34 +02:00
|
|
|
public class BookletPage{
|
|
|
|
|
2015-08-29 23:01:13 +02:00
|
|
|
protected int id;
|
|
|
|
protected BookletChapter chapter;
|
2015-10-03 10:16:18 +02:00
|
|
|
private HashMap<String, String> textReplacements = new HashMap<String, String>();
|
2015-09-14 11:02:16 +02:00
|
|
|
private boolean hasNoText;
|
2015-11-14 14:30:35 +01:00
|
|
|
public boolean arePageStacksWildcard;
|
2015-08-29 23:01:13 +02:00
|
|
|
|
|
|
|
public BookletPage(int id){
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2015-10-30 21:42:14 +01:00
|
|
|
public void addToPagesWithItemStackData(){
|
|
|
|
if(!InitBooklet.pagesWithItemStackData.contains(this)){
|
|
|
|
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){
|
|
|
|
InitBooklet.pagesWithItemStackData.add(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-29 14:30:44 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-11-15 18:39:05 +01:00
|
|
|
public static void renderItem(GuiScreen gui, ItemStack stack, int x, int y, float scale){
|
2015-10-03 10:16:18 +02:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
RenderHelper.enableGUIStandardItemLighting();
|
|
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
|
|
|
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
|
|
|
GL11.glTranslated(x, y, 0);
|
|
|
|
GL11.glScalef(scale, scale, scale);
|
2015-10-03 19:19:26 +02:00
|
|
|
|
|
|
|
boolean flagBefore = gui.mc.fontRenderer.getUnicodeFlag();
|
|
|
|
gui.mc.fontRenderer.setUnicodeFlag(false);
|
|
|
|
RenderItem.getInstance().renderItemAndEffectIntoGUI(gui.mc.fontRenderer, gui.mc.getTextureManager(), stack, 0, 0);
|
2015-10-03 10:16:18 +02:00
|
|
|
RenderItem.getInstance().renderItemOverlayIntoGUI(gui.mc.fontRenderer, gui.mc.getTextureManager(), stack, 0, 0);
|
2015-10-03 19:19:26 +02:00
|
|
|
gui.mc.fontRenderer.setUnicodeFlag(flagBefore);
|
|
|
|
|
2015-11-15 19:02:18 +01:00
|
|
|
//GL+MC+NEI suck
|
|
|
|
if(gui instanceof GuiBooklet){
|
|
|
|
RenderHelper.disableStandardItemLighting();
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-14 11:02:16 +02:00
|
|
|
public BookletPage setNoText(){
|
|
|
|
this.hasNoText = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-29 23:01:13 +02:00
|
|
|
public int getID(){
|
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
2015-09-10 21:25:34 +02:00
|
|
|
public final String getText(){
|
2015-09-14 11:02:16 +02:00
|
|
|
if(this.hasNoText){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-09-10 21:25:34 +02:00
|
|
|
String base = StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".chapter."+this.chapter.getUnlocalizedName()+".text."+this.id).replaceAll("<imp>", EnumChatFormatting.DARK_GREEN+"").replaceAll("<item>", EnumChatFormatting.BLUE+"").replaceAll("<r>", EnumChatFormatting.BLACK+"").replaceAll("<n>", "\n").replaceAll("<i>", EnumChatFormatting.ITALIC+"").replaceAll("<rs>", EnumChatFormatting.RESET+"");
|
2015-09-12 20:35:43 +02:00
|
|
|
for(Object o : this.textReplacements.entrySet()){
|
|
|
|
Map.Entry e = (Map.Entry)o;
|
|
|
|
base = base.replaceAll((String)e.getKey(), (String)e.getValue());
|
2015-09-10 21:25:34 +02:00
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
public BookletPage addTextReplacement(String text, int replacement){
|
|
|
|
return this.addTextReplacement(text, Integer.toString(replacement));
|
|
|
|
}
|
|
|
|
|
2015-09-10 21:25:34 +02:00
|
|
|
public BookletPage addTextReplacement(String text, String replacement){
|
2015-09-12 20:35:43 +02:00
|
|
|
this.textReplacements.put(text, replacement);
|
2015-09-10 21:25:34 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-11-29 14:30:44 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-04 13:21:07 +02:00
|
|
|
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
2015-08-29 23:01:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-29 14:30:44 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-04 13:21:07 +02:00
|
|
|
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
2015-08-29 23:01:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-29 14:30:44 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-09-29 17:42:04 +02:00
|
|
|
public void updateScreen(int ticksElapsed){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-29 23:01:13 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-11-29 14:30:44 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-04 13:21:07 +02:00
|
|
|
protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer, boolean mousePressed){
|
2015-10-03 19:19:26 +02:00
|
|
|
boolean flagBefore = gui.mc.fontRenderer.getUnicodeFlag();
|
|
|
|
gui.mc.fontRenderer.setUnicodeFlag(false);
|
|
|
|
|
2015-08-29 23:01:13 +02:00
|
|
|
List list = stack.getTooltip(gui.mc.thePlayer, gui.mc.gameSettings.advancedItemTooltips);
|
|
|
|
|
|
|
|
for(int k = 0; k < list.size(); ++k){
|
|
|
|
if(k == 0){
|
|
|
|
list.set(k, stack.getRarity().rarityColor+(String)list.get(k));
|
|
|
|
}
|
|
|
|
else{
|
2015-08-30 01:19:03 +02:00
|
|
|
list.set(k, EnumChatFormatting.GRAY+(String)list.get(k));
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(checkAndTransfer){
|
2015-11-27 16:44:39 +01:00
|
|
|
BookletPage page = BookletUtils.getFirstPageForStack(stack);
|
2015-11-28 17:53:16 +01:00
|
|
|
if(page != null && page != this){
|
2015-11-27 16:44:39 +01:00
|
|
|
list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe"));
|
|
|
|
|
|
|
|
if(mousePressed){
|
|
|
|
BookletUtils.openIndexEntry(gui, page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true);
|
|
|
|
BookletUtils.openChapter(gui, page.getChapter(), page);
|
|
|
|
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.drawHoveringText(list, x, y);
|
2015-10-03 19:19:26 +02:00
|
|
|
|
|
|
|
gui.mc.fontRenderer.setUnicodeFlag(flagBefore);
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
public ItemStack[] getItemStacksForPage(){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BookletChapter getChapter(){
|
|
|
|
return this.chapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChapter(BookletChapter chapter){
|
|
|
|
this.chapter = chapter;
|
|
|
|
}
|
2015-11-14 14:30:35 +01:00
|
|
|
|
|
|
|
public BookletPage setPageStacksWildcard(){
|
|
|
|
this.arePageStacksWildcard = true;
|
|
|
|
return this;
|
|
|
|
}
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|