| 1 | package net.minecraft.client.gui.components;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.gui.ComponentPath;
|
| 6 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 7 | import net.minecraft.client.gui.narration.NarrationElementOutput;
|
| 8 | import net.minecraft.client.gui.navigation.FocusNavigationEvent;
|
| 9 | import net.minecraft.client.renderer.RenderPipelines;
|
| 10 | import net.minecraft.client.sounds.SoundManager;
|
| 11 | import net.minecraft.network.chat.CommonComponents;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public abstract class ImageWidget extends AbstractWidget {
|
| 17 | private ImageWidget(final int x, final int y, final int width, final int height) {
|
| 18 | super(x, y, width, height, CommonComponents.EMPTY);
|
| 19 | }
|
| 20 |
|
| 21 | public static ImageWidget texture(final int width, final int height, final Identifier texture, final int textureWidth, final int textureHeight) {
|
| 22 | return new ImageWidget.Texture(0, 0, width, height, texture, textureWidth, textureHeight);
|
| 23 | }
|
| 24 |
|
| 25 | public static ImageWidget sprite(final int width, final int height, final Identifier sprite) {
|
| 26 | return new ImageWidget.Sprite(0, 0, width, height, sprite);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | protected void updateWidgetNarration(final NarrationElementOutput output) {
|
| 31 | }
|
| 32 |
|
| 33 | @Override
|
| 34 | public void playDownSound(final SoundManager soundManager) {
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | public boolean isActive() {
|
| 39 | return false;
|
| 40 | }
|
| 41 |
|
| 42 | public abstract void updateResource(Identifier identifier);
|
| 43 |
|
| 44 | @Override
|
| 45 | public @Nullable ComponentPath nextFocusPath(final FocusNavigationEvent navigationEvent) {
|
| 46 | return null;
|
| 47 | }
|
| 48 |
|
| 49 | @Environment(EnvType.CLIENT)
|
| 50 | private static class Sprite extends ImageWidget {
|
| 51 | private Identifier sprite;
|
| 52 |
|
| 53 | public Sprite(final int x, final int y, final int width, final int height, final Identifier sprite) {
|
| 54 | super(x, y, width, height);
|
| 55 | this.sprite = sprite;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public void extractWidgetRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 60 | graphics.blitSprite(RenderPipelines.GUI_TEXTURED, this.sprite, this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public void updateResource(final Identifier identifier) {
|
| 65 | this.sprite = identifier;
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | @Environment(EnvType.CLIENT)
|
| 70 | private static class Texture extends ImageWidget {
|
| 71 | private Identifier texture;
|
| 72 | private final int textureWidth;
|
| 73 | private final int textureHeight;
|
| 74 |
|
| 75 | public Texture(final int x, final int y, final int width, final int height, final Identifier texture, final int textureWidth, final int textureHeight) {
|
| 76 | super(x, y, width, height);
|
| 77 | this.texture = texture;
|
| 78 | this.textureWidth = textureWidth;
|
| 79 | this.textureHeight = textureHeight;
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | protected void extractWidgetRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 84 | graphics.blit(
|
| 85 | RenderPipelines.GUI_TEXTURED, this.texture, this.getX(), this.getY(), 0.0F, 0.0F, this.getWidth(), this.getHeight(), this.textureWidth, this.textureHeight
|
| 86 | );
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | public void updateResource(final Identifier identifier) {
|
| 91 | this.texture = identifier;
|
| 92 | }
|
| 93 | }
|
| 94 | }
|
| 95 |
|