Advertisement
CreativeMasterBonin

BaseCobbleMakerScreen

Mar 23rd, 2025
419
0
3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package net.bcm.cmatd.gui;
  2.  
  3. import net.bcm.cmatd.Utility;
  4. import net.bcm.cmatd.blockentity.BaseEnergyMakerBE;
  5. import net.minecraft.client.gui.GuiGraphics;
  6. import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
  7. import net.minecraft.network.chat.Component;
  8. import net.minecraft.resources.ResourceLocation;
  9. import net.minecraft.world.entity.player.Inventory;
  10.  
  11. import java.util.List;
  12.  
  13. public class BaseCobbleMakerScreen extends AbstractContainerScreen<BaseCobbleMakerMenu> {
  14.     private static final ResourceLocation BG = ResourceLocation.parse("cmatd:textures/gui/cobble_generator.png");
  15.     private static final int ENERGY_LEFT = 8;
  16.     private static final int ENERGY_WIDTH = 126;
  17.     private static final int ENERGY_TOP = 59;
  18.     private static final int ENERGY_HEIGHT = 5;
  19.  
  20.     public BaseCobbleMakerScreen(BaseCobbleMakerMenu menu, Inventory playerInventory, Component title) {
  21.         super(menu, playerInventory, title);
  22.         this.inventoryLabelY = this.imageHeight - 110;
  23.     }
  24.  
  25.     @Override
  26.     protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
  27.         guiGraphics.blit(BG, leftPos, topPos, 0, 0, this.imageWidth, this.imageHeight);
  28.         int power = menu.getEnergy();
  29.         int p = (int) ((power / (float) BaseEnergyMakerBE.CAPACITY) * ENERGY_WIDTH);
  30.         guiGraphics.fillGradient(leftPos + ENERGY_LEFT, topPos + ENERGY_TOP, leftPos + ENERGY_LEFT + p, topPos + ENERGY_TOP + ENERGY_HEIGHT, Utility.BRIGHT_LIGHT_BLUE, Utility.DARKER_BLUE);
  31.         guiGraphics.fill(leftPos + ENERGY_LEFT + p, topPos + ENERGY_TOP, leftPos + ENERGY_LEFT + ENERGY_WIDTH, topPos + ENERGY_TOP + ENERGY_HEIGHT, Utility.DARKEST_GRAYER_BLUE);
  32.     }
  33.  
  34.     @Override
  35.     public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
  36.         super.render(guiGraphics, mouseX, mouseY, partialTick);
  37.         // Render tooltip with power if in the energy box
  38.         if (mouseX >= leftPos + ENERGY_LEFT && mouseX < leftPos + ENERGY_LEFT + ENERGY_WIDTH && mouseY >= topPos + ENERGY_TOP && mouseY < topPos + ENERGY_TOP + ENERGY_HEIGHT) {
  39.             int power = menu.getEnergy();
  40.             List<Component> components = List.of(
  41.                     Component.translatable("title.energy_fe_with_max",power,menu.getBlockEntity().getMaxEnergy())
  42.             );
  43.             guiGraphics.renderComponentTooltip(this.font,components,mouseX,mouseY);
  44.         }
  45.         else{
  46.             this.renderTooltip(guiGraphics, mouseX, mouseY);
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement