RecipeBaseWidget.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.gui.widget;
  6. import me.shedaniel.math.api.Rectangle;
  7. import me.shedaniel.math.compat.RenderHelper;
  8. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  9. import me.shedaniel.rei.gui.config.RecipeScreenType;
  10. import me.shedaniel.rei.impl.ScreenHelper;
  11. import net.minecraft.client.render.GuiLighting;
  12. import net.minecraft.util.Identifier;
  13. import java.util.Collections;
  14. import java.util.List;
  15. public class RecipeBaseWidget extends WidgetWithBounds {
  16. private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
  17. private static final Identifier CHEST_GUI_TEXTURE_DARK = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer_dark.png");
  18. private Rectangle bounds;
  19. public RecipeBaseWidget(Rectangle bounds) {
  20. this.bounds = bounds;
  21. }
  22. public int getBlitOffset() {
  23. return this.blitOffset;
  24. }
  25. public void setBlitOffset(int offset) {
  26. this.blitOffset = offset;
  27. }
  28. @Override
  29. public Rectangle getBounds() {
  30. return bounds;
  31. }
  32. @Override
  33. public List<Widget> children() {
  34. return Collections.emptyList();
  35. }
  36. public void render() {
  37. render(0, 0, 0);
  38. }
  39. @Override
  40. public void render(int mouseX, int mouseY, float delta) {
  41. if (!isRendering())
  42. return;
  43. RenderHelper.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  44. GuiLighting.disable();
  45. minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? CHEST_GUI_TEXTURE_DARK : CHEST_GUI_TEXTURE);
  46. int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
  47. int textureOffset = getTextureOffset();
  48. //Four Corners
  49. this.blit(x, y, 106, 124 + textureOffset, 4, 4);
  50. this.blit(x + width - 4, y, 252, 124 + textureOffset, 4, 4);
  51. this.blit(x, y + height - 4, 106, 186 + textureOffset, 4, 4);
  52. this.blit(x + width - 4, y + height - 4, 252, 186 + textureOffset, 4, 4);
  53. //Sides
  54. for (int xx = 4; xx < width - 4; xx += 128) {
  55. int thisWidth = Math.min(128, width - 4 - xx);
  56. this.blit(x + xx, y, 110, 124 + textureOffset, thisWidth, 4);
  57. this.blit(x + xx, y + height - 4, 110, 186 + textureOffset, thisWidth, 4);
  58. }
  59. for (int yy = 4; yy < height - 4; yy += 50) {
  60. int thisHeight = Math.min(50, height - 4 - yy);
  61. this.blit(x, y + yy, 106, 128 + textureOffset, 4, thisHeight);
  62. this.blit(x + width - 4, y + yy, 252, 128 + textureOffset, 4, thisHeight);
  63. }
  64. fillGradient(x + 4, y + 4, x + width - 4, y + height - 4, getInnerColor(), getInnerColor());
  65. }
  66. protected boolean isRendering() {
  67. return RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() != RecipeScreenType.VILLAGER;
  68. }
  69. protected int getInnerColor() {
  70. return ScreenHelper.isDarkModeEnabled() ? -13750738 : -3750202;
  71. }
  72. protected int getTextureOffset() {
  73. return RoughlyEnoughItemsCore.getConfigManager().getConfig().isUsingLightGrayRecipeBorder() ? 0 : 66;
  74. }
  75. }