Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.98 KB | None | 0 0
  1. @OnlyIn(Dist.CLIENT)
  2. public class GuiCarpentersTable extends GuiContainer implements IRecipeShownListener
  3. {
  4.  
  5.     private static final ResourceLocation CARPENTERS_TABLE_TEXTURES = new ResourceLocation(Constants.MODID, "textures/gui/container/carpenters_table.png");
  6.     private static final ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation("textures/gui/recipe_button.png");
  7.  
  8.     private final GuiRecipeBook recipeBook = new GuiRecipeBook();
  9.     private boolean widthTooNarrow;
  10.  
  11.     public GuiCarpentersTable(InventoryPlayer playerInv, World worldIn)
  12.     {
  13.         this(playerInv, worldIn, BlockPos.ORIGIN);
  14.     }
  15.  
  16.     public GuiCarpentersTable(InventoryPlayer playerInv, World worldIn, BlockPos pos)
  17.     {
  18.         super(new ContainerCarpentersTable(playerInv, worldIn, pos));
  19.         this.ySize = 200;
  20.     }
  21.  
  22.     @Override
  23.     public void initGui()
  24.     {
  25.         super.initGui();
  26.         this.widthTooNarrow = this.width < 379;
  27.         this.recipeBook.func_201520_a(this.width, this.height, this.mc, this.widthTooNarrow, (ContainerRecipeBook) this.inventorySlots);
  28.         this.guiLeft = this.recipeBook.updateScreenPosition(this.widthTooNarrow, this.width, this.xSize);
  29.         this.children.add(this.recipeBook);
  30.         this.addButton(new GuiButtonImage(10, this.guiLeft + 5, this.height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE)
  31.         {
  32.             @Override
  33.             public void onClick(double mouseX, double mouseY)
  34.             {
  35.                 GuiCarpentersTable.this.recipeBook.func_201518_a(GuiCarpentersTable.this.widthTooNarrow);
  36.                 GuiCarpentersTable.this.recipeBook.toggleVisibility();
  37.                 GuiCarpentersTable.this.guiLeft = GuiCarpentersTable.this.recipeBook.updateScreenPosition(GuiCarpentersTable.this.widthTooNarrow, GuiCarpentersTable.this.width, GuiCarpentersTable.this.xSize);
  38.                 this.setPosition(GuiCarpentersTable.this.guiLeft + 5, GuiCarpentersTable.this.height / 2 - 49);
  39.             }
  40.         });
  41.     }
  42.  
  43.     @Override
  44.     public void tick()
  45.     {
  46.         super.tick();
  47.         this.recipeBook.tick();
  48.     }
  49.  
  50.     @Override
  51.     public void render(int mouseX, int mouseY, float partialTicks)
  52.     {
  53.         this.drawDefaultBackground();
  54.  
  55.         if (this.recipeBook.isVisible() && this.widthTooNarrow)
  56.         {
  57.             this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
  58.             this.recipeBook.render(mouseX, mouseY, partialTicks);
  59.         }
  60.         else
  61.         {
  62.             this.recipeBook.render(mouseX, mouseY, partialTicks);
  63.             super.render(mouseX, mouseY, partialTicks);
  64.             this.recipeBook.renderGhostRecipe(this.guiLeft, this.guiTop, true, partialTicks);
  65.         }
  66.  
  67.         this.renderHoveredToolTip(mouseX, mouseY);
  68.         this.recipeBook.renderTooltip(this.guiLeft, this.guiTop, mouseX, mouseY);
  69.     }
  70.  
  71.     @Override
  72.     protected boolean isPointInRegion(int p_195359_1_, int p_195359_2_, int p_195359_3_, int p_195359_4_, double p_195359_5_, double p_195359_7_)
  73.     {
  74.         return (!this.widthTooNarrow || !this.recipeBook.isVisible()) && super.isPointInRegion(p_195359_1_, p_195359_2_, p_195359_3_, p_195359_4_, p_195359_5_, p_195359_7_);
  75.     }
  76.  
  77.     @Override
  78.     public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_)
  79.     {
  80.         if (this.recipeBook.mouseClicked(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_))
  81.         {
  82.             return true;
  83.         }
  84.         else
  85.         {
  86.             return this.widthTooNarrow && this.recipeBook.isVisible() || super.mouseClicked(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_);
  87.         }
  88.     }
  89.  
  90.     @Override
  91.     protected boolean func_195361_a(double p_195361_1_, double p_195361_3_, int p_195361_5_, int p_195361_6_, int p_195361_7_)
  92.     {
  93.         boolean flag = p_195361_1_ < (double) p_195361_5_ || p_195361_3_ < (double) p_195361_6_ || p_195361_1_ >= (double) (p_195361_5_ + this.xSize) || p_195361_3_ >= (double) (p_195361_6_ + this.ySize);
  94.         return this.recipeBook.func_195604_a(p_195361_1_, p_195361_3_, this.guiLeft, this.guiTop, this.xSize, this.ySize, p_195361_7_) && flag;
  95.     }
  96.  
  97.     @Override
  98.     protected void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type)
  99.     {
  100.         super.handleMouseClick(slotIn, slotId, mouseButton, type);
  101.         this.recipeBook.slotClicked(slotIn);
  102.     }
  103.  
  104.     @Override
  105.     protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
  106.     {
  107.         String text = I18n.format(MEBlocks.CARPENTERS_TABLE.getTranslationKey());
  108.         MEUtils.renderText(text, this.xSize, 5, 0x404040);
  109.         MEUtils.renderText(I18n.format("container.inventory"), 64, this.ySize - 93, 0x404040);
  110.     }
  111.  
  112.     @Override
  113.     protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
  114.     {
  115.         GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  116.         this.mc.getTextureManager().bindTexture(CARPENTERS_TABLE_TEXTURES);
  117.         int i = this.guiLeft;
  118.         int j = (this.height - this.ySize) / 2;
  119.         this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
  120.     }
  121.  
  122.     @Nullable
  123.     @Override
  124.     public IGuiEventListener getFocused()
  125.     {
  126.         return this.recipeBook;
  127.     }
  128.  
  129.     @Override
  130.     public void recipesUpdated()
  131.     {
  132.         this.recipeBook.recipesUpdated();
  133.     }
  134.  
  135.     @Override
  136.     public void onGuiClosed()
  137.     {
  138.         this.recipeBook.removed();
  139.         super.onGuiClosed();
  140.     }
  141.  
  142.     @Override
  143.     public GuiRecipeBook func_194310_f()
  144.     {
  145.         return this.recipeBook;
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement