diff options
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/client/AlchemicalChestScreen.java | 26 | ||||
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/client/ChestLikeScreen.java | 46 |
2 files changed, 57 insertions, 15 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/client/AlchemicalChestScreen.java b/src/main/java/lv/enes/mc/eris_alchemy/client/AlchemicalChestScreen.java index 319dea8..0e0f029 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/client/AlchemicalChestScreen.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/client/AlchemicalChestScreen.java | |||
| @@ -2,13 +2,11 @@ package lv.enes.mc.eris_alchemy.client; | |||
| 2 | 2 | ||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; |
| 4 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | 4 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; |
| 5 | import net.minecraft.client.gui.GuiGraphics; | ||
| 6 | import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
| 7 | import net.minecraft.network.chat.Component; | 5 | import net.minecraft.network.chat.Component; |
| 8 | import net.minecraft.resources.ResourceLocation; | 6 | import net.minecraft.resources.ResourceLocation; |
| 9 | import net.minecraft.world.entity.player.Inventory; | 7 | import net.minecraft.world.entity.player.Inventory; |
| 10 | 8 | ||
| 11 | public class AlchemicalChestScreen extends AbstractContainerScreen<AlchemicalChestMenu> { | 9 | public class AlchemicalChestScreen extends ChestLikeScreen<AlchemicalChestMenu> { |
| 12 | public static final ResourceLocation TEXTURE = | 10 | public static final ResourceLocation TEXTURE = |
| 13 | new ResourceLocation(ErisAlchemy.ID, "textures/gui/container/alchemical_chest.png"); | 11 | new ResourceLocation(ErisAlchemy.ID, "textures/gui/container/alchemical_chest.png"); |
| 14 | 12 | ||
| @@ -17,27 +15,25 @@ public class AlchemicalChestScreen extends AbstractContainerScreen<AlchemicalChe | |||
| 17 | 15 | ||
| 18 | public AlchemicalChestScreen(AlchemicalChestMenu menu, Inventory inventory, Component title) { | 16 | public AlchemicalChestScreen(AlchemicalChestMenu menu, Inventory inventory, Component title) { |
| 19 | super(menu, inventory, title); | 17 | super(menu, inventory, title); |
| 18 | } | ||
| 20 | 19 | ||
| 21 | imageWidth = TEXTURE_WIDTH; | 20 | @Override |
| 22 | imageHeight = TEXTURE_HEIGHT; | 21 | protected ResourceLocation getTexture() { |
| 22 | return TEXTURE; | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { | 26 | protected int getTextureWidth() { |
| 27 | renderBackground(graphics); | 27 | return TEXTURE_WIDTH; |
| 28 | super.render(graphics, mouseX, mouseY, delta); | ||
| 29 | renderTooltip(graphics, mouseX, mouseY); | ||
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | @Override | 30 | @Override |
| 33 | protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { | 31 | protected int getTextureHeight() { |
| 34 | int x = (width - imageWidth) / 2; | 32 | return TEXTURE_HEIGHT; |
| 35 | int y = (height - imageHeight) / 2; | ||
| 36 | graphics.blit(TEXTURE, x, y, 0, 0, imageWidth, imageHeight); | ||
| 37 | } | 33 | } |
| 38 | 34 | ||
| 39 | @Override | 35 | @Override |
| 40 | protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { | 36 | protected boolean shouldRenderLabels() { |
| 41 | // Don't render any labels, there's no space for them lol | 37 | return false; |
| 42 | } | 38 | } |
| 43 | } | 39 | } |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/client/ChestLikeScreen.java b/src/main/java/lv/enes/mc/eris_alchemy/client/ChestLikeScreen.java new file mode 100644 index 0000000..c98b356 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/client/ChestLikeScreen.java | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.client; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.menu.ChestLikeBlockMenu; | ||
| 4 | import net.minecraft.client.gui.GuiGraphics; | ||
| 5 | import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
| 6 | import net.minecraft.network.chat.Component; | ||
| 7 | import net.minecraft.resources.ResourceLocation; | ||
| 8 | import net.minecraft.world.entity.player.Inventory; | ||
| 9 | |||
| 10 | public abstract class ChestLikeScreen<M extends ChestLikeBlockMenu> extends AbstractContainerScreen<M> { | ||
| 11 | public ChestLikeScreen(M menu, Inventory inventory, Component title) { | ||
| 12 | super(menu, inventory, title); | ||
| 13 | |||
| 14 | imageWidth = getTextureWidth(); | ||
| 15 | imageHeight = getTextureHeight(); | ||
| 16 | } | ||
| 17 | |||
| 18 | protected abstract ResourceLocation getTexture(); | ||
| 19 | protected abstract int getTextureWidth(); | ||
| 20 | protected abstract int getTextureHeight(); | ||
| 21 | |||
| 22 | protected boolean shouldRenderLabels() { | ||
| 23 | return true; | ||
| 24 | } | ||
| 25 | |||
| 26 | @Override | ||
| 27 | public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { | ||
| 28 | renderBackground(graphics); | ||
| 29 | super.render(graphics, mouseX, mouseY, delta); | ||
| 30 | renderTooltip(graphics, mouseX, mouseY); | ||
| 31 | } | ||
| 32 | |||
| 33 | @Override | ||
| 34 | protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { | ||
| 35 | int x = (width - imageWidth) / 2; | ||
| 36 | int y = (height - imageHeight) / 2; | ||
| 37 | graphics.blit(getTexture(), x, y, 0, 0, imageWidth, imageHeight); | ||
| 38 | } | ||
| 39 | |||
| 40 | @Override | ||
| 41 | protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { | ||
| 42 | if (shouldRenderLabels()) { | ||
| 43 | super.renderLabels(graphics, mouseX, mouseY); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||