RecipeBaseWidget.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package me.shedaniel.rei.gui.widget;
  2. import com.mojang.blaze3d.platform.GlStateManager;
  3. import net.minecraft.client.render.GuiLighting;
  4. import net.minecraft.util.Identifier;
  5. import java.awt.*;
  6. import java.util.Collections;
  7. import java.util.List;
  8. public class RecipeBaseWidget extends HighlightableWidget {
  9. private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
  10. private static final Color INNER_COLOR = new Color(198, 198, 198);
  11. private Rectangle bounds;
  12. public RecipeBaseWidget(Rectangle bounds) {
  13. this.bounds = bounds;
  14. if (bounds.width < 8 || bounds.height < 8)
  15. throw new IllegalArgumentException("Base too small, at least 8x8!");
  16. }
  17. @Override
  18. public Rectangle getBounds() {
  19. return bounds;
  20. }
  21. @Override
  22. public List<Widget> children() {
  23. return Collections.emptyList();
  24. }
  25. public void render() {
  26. render(0, 0, 0);
  27. }
  28. @Override
  29. public void render(int mouseX, int mouseY, float delta) {
  30. GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  31. GuiLighting.disable();
  32. minecraft.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
  33. int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
  34. int textureOffset = getTextureOffset();
  35. //Four Corners
  36. this.blit(x, y, 106, 124 + textureOffset, 4, 4);
  37. this.blit(x + width - 4, y, 252, 124 + textureOffset, 4, 4);
  38. this.blit(x, y + height - 4, 106, 186 + textureOffset, 4, 4);
  39. this.blit(x + width - 4, y + height - 4, 252, 186 + textureOffset, 4, 4);
  40. //Sides
  41. for(int xx = 4; xx < width - 4; xx += 128) {
  42. int thisWidth = Math.min(128, width - 4 - xx);
  43. this.blit(x + xx, y, 110, 124 + textureOffset, thisWidth, 4);
  44. this.blit(x + xx, y + height - 4, 110, 186 + textureOffset, thisWidth, 4);
  45. }
  46. for(int yy = 4; yy < height - 4; yy += 50) {
  47. int thisHeight = Math.min(50, height - 4 - yy);
  48. this.blit(x, y + yy, 106, 128 + textureOffset, 4, thisHeight);
  49. this.blit(x + width - 4, y + yy, 252, 128 + textureOffset, 4, thisHeight);
  50. }
  51. fillGradient(x + 4, y + 4, x + width - 4, y + height - 4, INNER_COLOR.getRGB(), INNER_COLOR.getRGB());
  52. }
  53. protected int getTextureOffset() {
  54. return 0;
  55. }
  56. }