Guest User

GuiEBGuide.java

a guest
Dec 9th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.63 KB | None | 0 0
  1. package main.extremeblocks.client.guis;
  2.  
  3. import main.com.hk.eb.util.Info;
  4. import main.com.hk.eb.util.RecipeUtils;
  5. import main.extremeblocks.Guide;
  6. import main.extremeblocks.Init;
  7. import net.minecraft.block.Block;
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.gui.FontRenderer;
  10. import net.minecraft.client.gui.GuiButton;
  11. import net.minecraft.client.gui.GuiScreen;
  12. import net.minecraft.client.renderer.RenderHelper;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.util.EnumChatFormatting;
  16. import net.minecraft.util.ResourceLocation;
  17. import org.lwjgl.opengl.GL11;
  18. import cpw.mods.fml.relauncher.Side;
  19. import cpw.mods.fml.relauncher.SideOnly;
  20.  
  21. @SideOnly(Side.CLIENT)
  22. public class GuiEBGuide extends GuiScreen
  23. {
  24.     private static final ResourceLocation guideTexture = new ResourceLocation(Init.MODID + ":textures/gui/guide.png");
  25.     private int imageWidth = 230;
  26.     private int imageHeight = 180;
  27.     private int zeroX;
  28.     private int bookTotalPages = 1;
  29.     private int currPage;
  30.  
  31.     public GuiEBGuide()
  32.     {
  33.         bookTotalPages = Guide.size + 1;
  34.     }
  35.  
  36.     @SuppressWarnings("unchecked")
  37.     @Override
  38.     public void initGui()
  39.     {
  40.         zeroX = (width - imageWidth) / 2;
  41.         buttonList.clear();
  42.  
  43.         buttonList.add(new GuiButton(0, width / 2 - 100, 6 + imageHeight, "Done"));
  44.         buttonList.add(new NextPageButton(1, zeroX + imageWidth - 33, 156, true));
  45.         buttonList.add(new NextPageButton(2, zeroX + 8, 156, false));
  46.     }
  47.  
  48.     @Override
  49.     protected void actionPerformed(GuiButton p_146284_1_)
  50.     {
  51.         if (p_146284_1_.enabled)
  52.         {
  53.             if (p_146284_1_.id == 0)
  54.             {
  55.                 mc.displayGuiScreen((GuiScreen) null);
  56.             }
  57.             else if (p_146284_1_.id == 1)
  58.             {
  59.                 if (currPage < bookTotalPages - 1)
  60.                 {
  61.                     ++currPage;
  62.                 }
  63.                 else
  64.                 {
  65.                     currPage = 0;
  66.                 }
  67.             }
  68.             else if (p_146284_1_.id == 2)
  69.             {
  70.                 if (currPage > 0)
  71.                 {
  72.                     --currPage;
  73.                 }
  74.                 else
  75.                 {
  76.                     currPage = bookTotalPages - 1;
  77.                 }
  78.             }
  79.         }
  80.     }
  81.  
  82.     @Override
  83.     public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
  84.     {
  85.         renderPage(currPage);
  86.  
  87.         super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
  88.     }
  89.  
  90.     public void renderPage(int page)
  91.     {
  92.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  93.         mc.getTextureManager().bindTexture(guideTexture);
  94.         drawTexturedModalRect(zeroX, 2, 0, 0, imageWidth, imageHeight);
  95.         String s = isItemPage(page);
  96.         if (s != null)
  97.         {
  98.             addPageNumber(page);
  99.             drawNewLine(s);
  100.         }
  101.         else
  102.         {
  103.             page--;
  104.             Info o = Guide.infos.get(page);
  105.             addPageNumber(page + 1);
  106.             drawNewLine(getStringFor(page, o));
  107.  
  108.             if (o.getElements().showRecipe)
  109.             {
  110.                 ItemStack is = o instanceof Block ? new ItemStack((Block) o) : new ItemStack((Item) o);
  111.                 renderRecipe(is);
  112.             }
  113.         }
  114.     }
  115.  
  116.     public String getStringFor(int page, Info o)
  117.     {
  118.         String name = "";
  119.         if (o instanceof Block)
  120.         {
  121.             name = "-" + ((Block) o).getLocalizedName() + "-\n";
  122.         }
  123.         else if (o instanceof Item)
  124.         {
  125.             name = "-" + ((Item) o).getUnlocalizedName() + "-\n";
  126.         }
  127.         else if (!(o instanceof Item) && !(o instanceof Block)) return o == null ? "null" : o.getClass().getName();
  128.         return EnumChatFormatting.BOLD + name + EnumChatFormatting.RESET + o.getInfo();
  129.     }
  130.  
  131.     public String isItemPage(int page)
  132.     {
  133.         switch (page)
  134.         {
  135.             case 0:
  136.                 return "This is the Extreme Blocks Mod Guide! Here, you will find the information to every single unique item and block. What this means is if something has a special function. It will be here. Else, it won't. If you think something does have a use, and it's not here. Please Let me know! I will fix it!. \nP.S. It's Alphabetized!";
  137.         }
  138.         return null;
  139.     }
  140.  
  141.     public void renderRecipe(ItemStack stack)
  142.     {
  143.         int gridX = zeroX + imageWidth / 2 - 80;
  144.         int gridY = imageHeight - 71;
  145.         ItemStack[] recipeItems = RecipeUtils.getFirstRecipeForItem(stack);
  146.         if (recipeItems != null)
  147.         {
  148.             for (int i = 0; i < recipeItems.length; i++)
  149.             {
  150.                 if (recipeItems[i] != null)
  151.                 {
  152.                     int[] pos = getPosFor(i);
  153.                     renderItemAt(1 + gridX + pos[0], 1 + gridY + pos[1], recipeItems[i].getItem());
  154.                 }
  155.             }
  156.             stack = stack.copy();
  157.             stack.stackSize = RecipeUtils.getRecipeFor(stack).getRecipeOutput().stackSize;
  158.         }
  159.         renderItemAt(gridX + 72, gridY + 18, stack);
  160.         drawGridAt(gridX, gridY);
  161.     }
  162.  
  163.     public int[] getPosFor(int i)
  164.     {
  165.         int[] pos = new int[] { 0, 0 };
  166.         pos[0] = i == 0 || i == 3 || i == 6 ? 0 : i == 1 || i == 4 || i == 7 ? 18 : 36;
  167.         pos[1] = i == 0 || i == 1 || i == 2 ? 0 : i == 3 || i == 4 || i == 5 ? 18 : 36;
  168.         return pos;
  169.     }
  170.  
  171.     public void renderItemAt(int x, int y, Object o)
  172.     {
  173.         RenderHelper.enableGUIStandardItemLighting();
  174.         drawItemStack(o instanceof Block ? new ItemStack((Block) o) : o instanceof Item ? new ItemStack((Item) o) : o instanceof ItemStack ? ((ItemStack) o).copy() : null, x, y);
  175.         RenderHelper.disableStandardItemLighting();
  176.     }
  177.  
  178.     private void drawItemStack(ItemStack stack, int x, int y)
  179.     {
  180.         GL11.glTranslatef(0.0F, 0.0F, 32.0F);
  181.         zLevel = 200.0F;
  182.         itemRender.zLevel = 200.0F;
  183.         FontRenderer font = null;
  184.         if (stack != null)
  185.         {
  186.             font = stack.getItem().getFontRenderer(stack);
  187.         }
  188.         if (font == null)
  189.         {
  190.             font = fontRendererObj;
  191.         }
  192.         itemRender.renderItemAndEffectIntoGUI(font, mc.getTextureManager(), stack, x, y);
  193.         itemRender.renderItemOverlayIntoGUI(font, mc.getTextureManager(), stack, x, y);
  194.         zLevel = 0.0F;
  195.         itemRender.zLevel = 0.0F;
  196.     }
  197.  
  198.     public void drawGridAt(int x, int y)
  199.     {
  200.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  201.         mc.getTextureManager().bindTexture(guideTexture);
  202.         drawTexturedModalRect(x, y, 63, 187, 53, 53);
  203.     }
  204.  
  205.     public void drawNewLine(String line)
  206.     {
  207.         fontRendererObj.drawSplitString(line, zeroX + 15, 18, 200, 0);
  208.     }
  209.  
  210.     public void addPageNumber(int page)
  211.     {
  212.         page++;
  213.         String s = page + "/" + bookTotalPages;
  214.         int l = fontRendererObj.getStringWidth(s);
  215.         fontRendererObj.drawString(s, zeroX + imageWidth - 33 - l, imageHeight - 20, 0);
  216.     }
  217.  
  218.     @SideOnly(Side.CLIENT)
  219.     public static class NextPageButton extends GuiButton
  220.     {
  221.         private final boolean next;
  222.  
  223.         public NextPageButton(int id, int x, int y, boolean normal)
  224.         {
  225.             super(id, x, y, 23, 13, "");
  226.             next = normal;
  227.         }
  228.  
  229.         @Override
  230.         public void drawButton(Minecraft mc, int x, int y)
  231.         {
  232.             if (visible)
  233.             {
  234.                 boolean flag = x >= xPosition && y >= yPosition && x < xPosition + width && y < yPosition + height;
  235.                 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  236.                 mc.getTextureManager().bindTexture(guideTexture);
  237.                 int k = 3;
  238.                 int l = 194;
  239.  
  240.                 if (flag)
  241.                 {
  242.                     k += 23;
  243.                 }
  244.  
  245.                 if (next)
  246.                 {
  247.                     l += 14;
  248.                 }
  249.  
  250.                 drawTexturedModalRect(xPosition, yPosition, k, l, 17, 8);
  251.             }
  252.         }
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment