From fafa8d04a02efca99d5a1f610cc432741103b70e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 1 Jun 2023 15:49:52 +0100 Subject: [PATCH] More sprites! --- .../java/reborncore/client/gui/GuiBase.java | 13 -- .../reborncore/client/gui/GuiBuilder.java | 81 +++------ .../gui/{config/elements => }/GuiSprites.java | 47 ++++- .../gui/config/elements/ButtonElement.java | 1 + .../gui/config/elements/CheckBoxElement.java | 1 + .../config/elements/ConfigFluidElement.java | 1 + .../config/elements/ConfigSlotElement.java | 1 + .../gui/config/elements/ElementBase.java | 3 +- .../elements/FluidConfigPopupElement.java | 1 + .../elements/SlotConfigPopupElement.java | 1 + .../client/gui/config/elements/SlotType.java | 1 + .../client/gui/widget/GuiButtonUpDown.java | 6 +- .../src/main/java/reborncore/RebornCore.java | 1 - .../common/powerSystem/PowerSystem.java | 52 +----- .../textures/gui/sprites/power_bar_base.png | Bin 0 -> 670 bytes .../gui/sprites/power_bar_overlay.png | Bin 0 -> 831 bytes .../gui/sprites/progress_down_base.png | Bin 0 -> 119 bytes .../gui/sprites/progress_down_overlay.png | Bin 0 -> 316 bytes .../gui/sprites/progress_left_base.png | Bin 0 -> 94 bytes .../gui/sprites/progress_left_overlay.png | Bin 0 -> 305 bytes .../gui/sprites/progress_right_base.png | Bin 0 -> 92 bytes .../gui/sprites/progress_right_overlay.png | Bin 0 -> 302 bytes .../textures/gui/sprites/progress_up_base.png | Bin 0 -> 121 bytes .../gui/sprites/progress_up_overlay.png | Bin 0 -> 316 bytes .../client/compat/rei/ReiPlugin.java | 170 ++++++++---------- .../java/techreborn/client/gui/GuiAESU.java | 2 +- .../java/techreborn/client/gui/GuiIDSU.java | 2 +- .../java/techreborn/client/gui/GuiLESU.java | 2 +- 28 files changed, 165 insertions(+), 221 deletions(-) rename RebornCore/src/client/java/reborncore/client/gui/{config/elements => }/GuiSprites.java (74%) create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_base.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_overlay.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_base.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_overlay.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_left_base.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_left_overlay.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_base.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_overlay.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_base.png create mode 100644 RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_overlay.png diff --git a/RebornCore/src/client/java/reborncore/client/gui/GuiBase.java b/RebornCore/src/client/java/reborncore/client/gui/GuiBase.java index 6e34c4189..2f43689cf 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/GuiBase.java +++ b/RebornCore/src/client/java/reborncore/client/gui/GuiBase.java @@ -389,17 +389,4 @@ public class GuiBase extends HandledScreen { public static Sprite getSprite(SpriteIdentifier spriteIdentifier) { return GuiSpriteAtlasHolder.INSTANCE.getSprite(spriteIdentifier.getTextureId()); } - - public void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y) { - final Sprite sprite = getSprite(spriteIdentifier); - - drawContext.drawSprite( - x, - y, - 0, - sprite.getContents().getWidth(), - sprite.getContents().getHeight(), - sprite - ); - } } diff --git a/RebornCore/src/client/java/reborncore/client/gui/GuiBuilder.java b/RebornCore/src/client/java/reborncore/client/gui/GuiBuilder.java index 6a547c77f..c64305130 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/GuiBuilder.java +++ b/RebornCore/src/client/java/reborncore/client/gui/GuiBuilder.java @@ -40,18 +40,19 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import reborncore.api.IListInfoProvider; import reborncore.client.gui.config.GuiTab; -import reborncore.client.gui.config.elements.GuiSprites; import reborncore.common.fluid.FluidUtils; import reborncore.common.fluid.FluidValue; import reborncore.common.fluid.container.FluidInstance; import reborncore.common.powerSystem.PowerSystem; -import reborncore.common.powerSystem.PowerSystem.EnergySystem; import reborncore.common.util.StringUtils; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; +import static reborncore.client.gui.GuiSprites.drawSprite; + /** * Created by Gigabit101 on 08/08/2016. */ @@ -67,19 +68,6 @@ public class GuiBuilder { height / 2); } - public void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y) { - final Sprite sprite = GuiBase.getSprite(spriteIdentifier); - - drawContext.drawSprite( - x, - y, - 0, - sprite.getContents().getWidth(), - sprite.getContents().getHeight(), - sprite - ); - } - public void drawPlayerSlots(DrawContext drawContext, Screen gui, int posX, int posY, boolean center) { if (center) { posX -= 81; @@ -420,7 +408,7 @@ public class GuiBuilder { if (gui.hideGuiElements()) return; Text text = Text.literal(PowerSystem.getLocalizedPowerNoSuffix(maxOutput)) .append(SPACE_TEXT) - .append(PowerSystem.getDisplayPower().abbreviation) + .append(PowerSystem.ABBREVIATION) .append("\t"); int width = gui.getTextRenderer().getWidth(text); @@ -452,30 +440,20 @@ public class GuiBuilder { y += gui.getGuiTop(); } - drawContext.drawTexture(resourceLocation, x, y, direction.x, direction.y, direction.width, direction.height); + drawSprite(drawContext, direction.baseSprite, x, y); int j = (int) ((double) progress / (double) maxProgress * 16); if (j < 0) { j = 0; } switch (direction) { - case RIGHT: - drawContext.drawTexture(resourceLocation, x, y, direction.xActive, direction.yActive, j, 10); - break; - case LEFT: - drawContext.drawTexture(resourceLocation, x + 16 - j, y, direction.xActive + 16 - j, direction.yActive, j, 10); - break; - case UP: - drawContext.drawTexture(resourceLocation, x, y + 16 - j, direction.xActive, direction.yActive + 16 - j, 10, j); - break; - case DOWN: - drawContext.drawTexture(resourceLocation, x, y, direction.xActive, direction.yActive, 10, j); - break; - default: - return; + case RIGHT, LEFT -> drawSprite(drawContext, direction.overlaySprite, x, y, j, 10, gui); + case UP, DOWN -> drawSprite(drawContext, direction.overlaySprite, x, y, 10, j, gui); } - if (gui.isPointInRect(x, y, direction.width, direction.height, mouseX, mouseY)) { + final Sprite sprite = GuiBase.getSprite(direction.baseSprite); + + if (gui.isPointInRect(x, y, sprite.getContents().getWidth(), sprite.getContents().getHeight(), mouseX, mouseY)) { int percentage = percentage(maxProgress, progress); List list = new ArrayList<>(); list.add( @@ -512,13 +490,15 @@ public class GuiBuilder { y += gui.getGuiTop(); } - EnergySystem displayPower = PowerSystem.getDisplayPower(); - drawContext.drawTexture(resourceLocation, x, y, displayPower.xBar - 15, displayPower.yBar - 1, 14, 50); - int draw = (int) ((double) energyStored / (double) maxEnergyStored * (48)); + drawSprite(drawContext, GuiSprites.POWER_BAR_BASE, x, y); + + int barHeight = 48; + int draw = (int) ((double) energyStored / (double) maxEnergyStored * (barHeight)); if (energyStored > maxEnergyStored) { - draw = 48; + draw = barHeight; } - drawContext.drawTexture(resourceLocation, x + 1, y + 49 - draw, displayPower.xBar, 48 + displayPower.yBar - draw, 12, draw); + drawSprite(drawContext, GuiSprites.POWER_BAR_OVERLAY, x + 1, y + 49 - draw, 12, draw, gui); + int percentage = percentage(maxEnergyStored, energyStored); if (gui.isPointInRect(x + 1, y + 1, 11, 48, mouseX, mouseY)) { List list = Lists.newArrayList(); @@ -729,24 +709,17 @@ public class GuiBuilder { } public enum ProgressDirection { - RIGHT(58, 150, 74, 150, 16, 10), - LEFT(74, 160, 58, 160, 16, 10), - DOWN(78, 170, 88, 170, 10, 16), - UP(58, 170, 68, 170, 10, 16); - public int x; - public int y; - public int xActive; - public int yActive; - public int width; - public int height; + RIGHT, + LEFT, + DOWN, + UP; - ProgressDirection(int x, int y, int xActive, int yActive, int width, int height) { - this.x = x; - this.y = y; - this.xActive = xActive; - this.yActive = yActive; - this.width = width; - this.height = height; + public final SpriteIdentifier baseSprite; + public final SpriteIdentifier overlaySprite; + + ProgressDirection() { + baseSprite = GuiSprites.create("progress_%s_base".formatted(name().toLowerCase(Locale.ROOT))); + overlaySprite = GuiSprites.create("progress_%s_overlay".formatted(name().toLowerCase(Locale.ROOT))); } } } diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/GuiSprites.java b/RebornCore/src/client/java/reborncore/client/gui/GuiSprites.java similarity index 74% rename from RebornCore/src/client/java/reborncore/client/gui/config/elements/GuiSprites.java rename to RebornCore/src/client/java/reborncore/client/gui/GuiSprites.java index da9b7c704..a8054ce27 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/GuiSprites.java +++ b/RebornCore/src/client/java/reborncore/client/gui/GuiSprites.java @@ -22,10 +22,15 @@ * SOFTWARE. */ -package reborncore.client.gui.config.elements; +package reborncore.client.gui; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.texture.SpriteAtlasHolder; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.util.Identifier; +import reborncore.client.gui.config.elements.GuiSpriteAtlasHolder; public final class GuiSprites { public static final SpriteIdentifier CHARGE_SLOT_ICON = create("charge_slot_icon"); @@ -62,6 +67,8 @@ public final class GuiSprites { public static final SpriteIdentifier SLOT_BAR_RIGHT = create("slot_bar_right"); public static final SpriteIdentifier SLOT_BAR_CENTER = create("slot_bar_center"); public static final SpriteIdentifier SLOT_BAR_LEFT = create("slot_bar_left"); + public static final SpriteIdentifier POWER_BAR_BASE = create("power_bar_base"); + public static final SpriteIdentifier POWER_BAR_OVERLAY = create("power_bar_overlay"); public static final SpriteIdentifier EXIT_BUTTON_NORMAL = create("exit_button_normal"); public static final SpriteIdentifier EXIT_BUTTON_HOVERED = create("exit_button_hovered"); @@ -75,13 +82,45 @@ public final class GuiSprites { public static final SpriteIdentifier LIGHT_CHECK_BOX_TICKED = create("light_check_box_ticked"); public static final CheckBox LIGHT_CHECK_BOX = new CheckBox(LIGHT_CHECK_BOX_NORMAL, LIGHT_CHECK_BOX_TICKED); - private static SpriteIdentifier create(String name) { + public static SpriteIdentifier create(String name) { return new SpriteIdentifier(GuiSpriteAtlasHolder.ATLAS_ID, new Identifier("reborncore", name)); } - record Button(SpriteIdentifier normal, SpriteIdentifier hovered) { + public static void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y) { + final Sprite sprite = GuiBase.getSprite(spriteIdentifier); + + drawContext.drawSprite( + x, + y, + 0, + sprite.getContents().getWidth(), + sprite.getContents().getHeight(), + sprite + ); } - record CheckBox(SpriteIdentifier normal, SpriteIdentifier ticked) { + public static void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y, int width, int height) { + drawSprite(drawContext, spriteIdentifier, x, y, width, height, 0, 0); + } + + public static void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y, int width, int height, GuiBase gui) { + drawSprite(drawContext, spriteIdentifier, x, y, width, height, gui.getGuiLeft(), gui.getGuiTop()); + } + + public static void drawSprite(DrawContext drawContext, SpriteIdentifier spriteIdentifier, int x, int y, int width, int height, int sx, int sy) { + drawContext.enableScissor(x + sx, y + sy, x + width+ sx, y + height+ sy); + drawSprite( + drawContext, + spriteIdentifier, + x, + y + ); + drawContext.disableScissor(); + } + + public record Button(SpriteIdentifier normal, SpriteIdentifier hovered) { + } + + public record CheckBox(SpriteIdentifier normal, SpriteIdentifier ticked) { } } diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ButtonElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ButtonElement.java index e529b6c90..aeaee392f 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ButtonElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ButtonElement.java @@ -26,6 +26,7 @@ package reborncore.client.gui.config.elements; import net.minecraft.client.gui.DrawContext; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; public class ButtonElement extends ElementBase { private final GuiSprites.Button buttonSprite; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/CheckBoxElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/CheckBoxElement.java index 55a6f78a3..ebaa25d5f 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/CheckBoxElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/CheckBoxElement.java @@ -28,6 +28,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.text.Text; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; import java.util.function.Predicate; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigFluidElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigFluidElement.java index 95fe29be8..13bfd4b34 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigFluidElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigFluidElement.java @@ -27,6 +27,7 @@ package reborncore.client.gui.config.elements; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; public class ConfigFluidElement extends ParentElement { private final SlotType type; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigSlotElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigSlotElement.java index 1273f039b..2ef3a9fcf 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigSlotElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ConfigSlotElement.java @@ -29,6 +29,7 @@ import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; import reborncore.common.blockentity.SlotConfiguration; import reborncore.common.screen.slot.BaseSlot; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ElementBase.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ElementBase.java index ee9fa2c5d..3e021f5d7 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/ElementBase.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/ElementBase.java @@ -30,6 +30,7 @@ import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.text.Text; import reborncore.client.gui.GuiBase; import reborncore.client.gui.GuiBuilder; +import reborncore.client.gui.GuiSprites; public class ElementBase { private final int x; @@ -93,7 +94,7 @@ public class ElementBase { } public void drawSprite(DrawContext drawContext, GuiBase gui, SpriteIdentifier spriteIdentifier, int x, int y) { - gui.drawSprite(drawContext, spriteIdentifier, x + gui.getGuiLeft(), y + gui.getGuiTop()); + GuiSprites.drawSprite(drawContext, spriteIdentifier, x + gui.getGuiLeft(), y + gui.getGuiTop()); } public void drawDefaultBackground(DrawContext drawContext, Screen gui, int x, int y, int width, int height) { diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/FluidConfigPopupElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/FluidConfigPopupElement.java index d7f10dd23..0980edccd 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/FluidConfigPopupElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/FluidConfigPopupElement.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.Direction; import reborncore.RebornCore; import reborncore.client.ClientNetworkManager; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; import reborncore.common.blockentity.FluidConfiguration; import reborncore.common.network.IdentifiedPacket; import reborncore.common.network.ServerBoundPackets; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotConfigPopupElement.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotConfigPopupElement.java index ada32af61..e0c2cd12d 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotConfigPopupElement.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotConfigPopupElement.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.Direction; import reborncore.RebornCore; import reborncore.client.ClientNetworkManager; import reborncore.client.gui.GuiBase; +import reborncore.client.gui.GuiSprites; import reborncore.common.blockentity.SlotConfiguration; import reborncore.common.network.IdentifiedPacket; import reborncore.common.network.ServerBoundPackets; diff --git a/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotType.java b/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotType.java index 68826be08..c6d9b4e7c 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotType.java +++ b/RebornCore/src/client/java/reborncore/client/gui/config/elements/SlotType.java @@ -25,6 +25,7 @@ package reborncore.client.gui.config.elements; import net.minecraft.client.util.SpriteIdentifier; +import reborncore.client.gui.GuiSprites; public enum SlotType { NORMAL(1, 1, GuiSprites.SLOT, GuiSprites.BUTTON_SLOT_NORMAL, GuiSprites.BUTTON_HOVER_OVERLAY_SLOT_NORMAL); diff --git a/RebornCore/src/client/java/reborncore/client/gui/widget/GuiButtonUpDown.java b/RebornCore/src/client/java/reborncore/client/gui/widget/GuiButtonUpDown.java index 896f9b5ec..fb5e5eeed 100644 --- a/RebornCore/src/client/java/reborncore/client/gui/widget/GuiButtonUpDown.java +++ b/RebornCore/src/client/java/reborncore/client/gui/widget/GuiButtonUpDown.java @@ -29,7 +29,9 @@ import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.text.Text; import reborncore.client.gui.GuiBase; -import reborncore.client.gui.config.elements.GuiSprites; +import reborncore.client.gui.GuiSprites; + +import static reborncore.client.gui.GuiSprites.drawSprite; /** * @author drcrazy @@ -47,7 +49,7 @@ public class GuiButtonUpDown extends GuiButtonExtended { @Override public void renderButton(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) { if (gui.hideGuiElements()) return; - gui.drawSprite(drawContext, type.spriteIdentifier, getX(), getY()); + drawSprite(drawContext, type.spriteIdentifier, getX(), getY()); } public enum UpDownButtonType { diff --git a/RebornCore/src/main/java/reborncore/RebornCore.java b/RebornCore/src/main/java/reborncore/RebornCore.java index ac8e0c527..0d3f9c465 100644 --- a/RebornCore/src/main/java/reborncore/RebornCore.java +++ b/RebornCore/src/main/java/reborncore/RebornCore.java @@ -71,7 +71,6 @@ public class RebornCore implements ModInitializer { @Override public void onInitialize() { new Configuration(RebornCoreConfig.class, MOD_ID); - PowerSystem.init(); CalenderUtils.loadCalender(); // Done early as some features need this ToolManager.INSTANCE.customToolHandlerList.add(new GenericWrenchHelper(new Identifier("ic2:wrench"), true)); diff --git a/RebornCore/src/main/java/reborncore/common/powerSystem/PowerSystem.java b/RebornCore/src/main/java/reborncore/common/powerSystem/PowerSystem.java index c627812f7..824712a9c 100644 --- a/RebornCore/src/main/java/reborncore/common/powerSystem/PowerSystem.java +++ b/RebornCore/src/main/java/reborncore/common/powerSystem/PowerSystem.java @@ -25,20 +25,17 @@ package reborncore.common.powerSystem; import reborncore.RebornCore; -import reborncore.common.RebornCoreConfig; import java.text.DecimalFormat; -import java.util.Arrays; -import java.util.function.Supplier; public class PowerSystem { - private static EnergySystem selectedSystem = EnergySystem.values()[0]; + public static final String ABBREVIATION = "E"; private static final char[] magnitude = new char[] { 'k', 'M', 'G', 'T' }; public static String getLocalizedPower(double power) { - return getRoundedString(power, selectedSystem.abbreviation, true); + return getRoundedString(power, ABBREVIATION, true); } public static String getLocalizedPowerNoSuffix(double power) { @@ -46,7 +43,7 @@ public class PowerSystem { } public static String getLocalizedPowerNoFormat(double power){ - return getRoundedString(power, selectedSystem.abbreviation, false); + return getRoundedString(power, ABBREVIATION, false); } public static String getLocalizedPowerNoSuffixNoFormat(double power){ @@ -54,7 +51,7 @@ public class PowerSystem { } public static String getLocalizedPowerFull(double power){ - return getFullPower(power, selectedSystem.abbreviation); + return getFullPower(power, ABBREVIATION); } public static String getLocalizedPowerFullNoSuffix(double power){ @@ -131,45 +128,4 @@ public class PowerSystem { return ret; } - - public static EnergySystem getDisplayPower() { - if(!selectedSystem.enabled.get()){ - bumpPowerConfig(); - } - return selectedSystem; - } - - public static void bumpPowerConfig() { - int value = selectedSystem.ordinal() + 1; - if (value == EnergySystem.values().length) { - value = 0; - } - selectedSystem = EnergySystem.values()[value]; - } - - public static void init(){ - selectedSystem = Arrays.stream(EnergySystem.values()).filter(energySystem -> energySystem.abbreviation.equalsIgnoreCase(RebornCoreConfig.selectedSystem)).findFirst().orElse(EnergySystem.values()[0]); - if(!selectedSystem.enabled.get()){ - bumpPowerConfig(); - } - } - - public enum EnergySystem { - EU(0xFF800600, "E", 141, 151, 0xFF670000); - - public int colour; - public int altColour; - public String abbreviation; - public int xBar; - public int yBar; - public Supplier enabled = () -> true; - - EnergySystem(int colour, String abbreviation, int xBar, int yBar, int altColour) { - this.colour = colour; - this.abbreviation = abbreviation; - this.xBar = xBar; - this.yBar = yBar; - this.altColour = altColour; - } - } } diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_base.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_base.png new file mode 100644 index 0000000000000000000000000000000000000000..4ed2e1912fa1bf80a50dcdf0cc1900312632afc2 GIT binary patch literal 670 zcmV;P0%84$P)SEIP9w|r8hK_O5$_chjZYfCOk*LUkw7644G?b%k#VbsZ$$g7 z`H+YaUSmfzS2h1(S0jy$t42g4x?V+Mn5)yoz*Xi#S68^I2XL+?W>-tCvZ~fqP1HoI zRZk2xc6lsBbCo&VX6cg}3B=%@xh{`-wnxm};a%16#L>!`(nw`Bl|wYkV^5>*jo7-X zC=k)n5sOBvoUBnV^@v0ns+_Jn^j}LX8jT3WTs4iMs}T`>MjY3u39s=(#Lm@HtLAD= z9L(b+5m!Tvii(4^tDeZ}LLxacSM#1TrV*lPG-BiGR32+0JKiYKH1;Y-R~$AXfqEM0 zYM)2;QX^VF(m4&0uJ(EKu6kmaM|#cIs_o?U4lt`VdZK+BJ(1mk<@fVg`jIZLUCl)Q z?T9q8laa@eSh}NiwGd4sff`rqTJ^4aB3JKfL$rPzBx*j)Bd+o#>T1AIk{HHTqUA+l@kYFWuHd^aSH2cw92XTXx$NNY>4a9k6z=DtNFy?Dkre$d|7XSbN07*qoM6N<$ Ef literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_overlay.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/power_bar_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..a519326be49cb59773550bb787f4f49eb6a59e59 GIT binary patch literal 831 zcmV-F1Hk-=P)OGHI-7V=k zJx^(SoYVH)Vm(gV8;gfY+HNfF?fTl{!eVCe(texv?c57bLm5a57Hpn}kGnBuf$xw5#&1FQRCa0Ex6N0p)v zWc`|U9OQK8gL(-LXkVOm#ePiO>FiE(>M$Un5}X99L`2HTjPKax!yx1 zylV5HZlzx820`5lD$n3qIB<&kP-$&hZ$0~FuX;i+!EZYHg9F_vA2e~%=}sjOx{2HK zZXN2x@oXM_K!M1C>~H`1bfSYA&sFzS_aHrjehM;+vJ3`z`QmM@Yr$8tivU6~R zxR>VkO*I7pA8;B3O&nfu%{?KsZY@6Gs(c8$6<&Wijf?CaO`JHKq@529fr-=B&`g)@ zZAd@;9?zJ{!Xa*NvI&8i&^&Yq)K#{IXG8nATiF^#rEx%z)3KL80b!AL6Ste`QFRkV z%GPi%Pz z_<$mMPxF3=PQ$a!15Q&X(}haRv$|Ci*Y8%Zv;7l*16w24dqt(_Lv$JhoK`RK{{wVp zhPPGyuVJUZSeC1icdO6C4c?%jBXqq)oz#m;D8x*2%{}=5!fy#g5VvqJ!NLFl002ov JPDHLkV1lI4f)W4# literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_base.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_base.png new file mode 100644 index 0000000000000000000000000000000000000000..678c34227671fd488dc73f328239eb152daf8dea GIT binary patch literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^AhrMp8<5nmf9C+C>^xl@Ln`8u6C9ZD-o5+ZQ6g4` zxku{=cY&6R_>pA-XWXYBIN5HPFzLpPg5DEMHw?~{?CA;=Imi&$mB27viQ%E_WX1*G S=ePk)V(@hJb6Mw<&;$UX`zCe( literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_overlay.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_down_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..4e385a0523ebab7762c1adbc2331186c25168a8b GIT binary patch literal 316 zcmV-C0mJ@@P)* zKm$T5J^wkSTmGYqV*m-Q$^Uue+KEu8Jsqg9hZu!(|MSRCBtoIiqW?S!Q;AThyZk?o z;%p)m>aG3HqdcDoh58$S3YQR}&|n)-;VMjpqI!o>1SJf1|L0Lzk0Qn-v*|yBqSfjD zAPf_fGCurYP-_>Q&!@5TKdb!4{|s^#=l^RtU;M9VeE}?~Y*cRJ6VZRDAuvy5sf#Dt6cYE7)BAFK&1OsA$K3Cb=D`?p3tD{a@Yb_J1k!>;L(* zPygpo-Ul>kAEu{3K+59Ie-XnA|5=p|{b!Ilgk2E~aHyUC&!lh)LlFS~sBTo2gl=H~ O0000* zKm&Z52mZ6lZ}`t3x$Zx@96=zcbNoNI%I5z}GHXfKEMPg^8XS# zi~dV!&jsS?{{@wM|FcRo{AZA}c?vc_!sN<-LER(&`80O@=TX@L#Owd_D6azIB|tp? zKab+<|2zs)|MSRC{LdrT^PfYyU4Axr1(pi`gaW00000NkvXXu0mjf D%1N1j literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_base.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_base.png new file mode 100644 index 0000000000000000000000000000000000000000..5dea4288009870cf9f7af898570271879ae4d049 GIT binary patch literal 92 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~g!3HGv?z=Y!NGW@|IEGZjB_}8_m6VtNZ%-_- qTy#*uj3u%`#%CwvlBUEJk_^*SCNrAeStAEj&fw|l=d#Wzp$P!y7#R!z literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_overlay.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_right_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..817018175ddbd785d63f1fa446e1476b16f82f2e GIT binary patch literal 302 zcmV+}0nz@6P)NklCsvhsR60vSnE(I)07*qoM6N<$g8H3> AasU7T literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_base.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_base.png new file mode 100644 index 0000000000000000000000000000000000000000..3484bc1b0e2e9d1bb007c34c0d304ba0bb9329ab GIT binary patch literal 121 zcmeAS@N?(olHy`uVBq!ia0vp^AhrMp8<5nmf9C+C96VhdLn`9lc02MhC~zG9Vc&nP z;y_Q+o&%~f*F=qv+`Vr3Y03n*nL*mcPeeVdZ(b5Vaz(T($>6Q{Hs;Sq4fP9|=iZsj U=(Sm8D$pzjPgg&ebxsLQ0AgM#Q2+n{ literal 0 HcmV?d00001 diff --git a/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_overlay.png b/RebornCore/src/main/resources/assets/reborncore/textures/gui/sprites/progress_up_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..03758a2f3537999e1e3b5f05b464556a3a89c6e2 GIT binary patch literal 316 zcmV-C0mJ@@P)* zKm&5tPyWldzpIc?~e^!O9U;!zU zWB>Uyc7fT7)))ROSe^XOqqgrq1FQUo|4cG#;Z{f(9Qe, ItemConvertible> iconMap = new HashMap<>(); @@ -270,17 +270,15 @@ public class ReiPlugin implements REIClientPlugin { public static Widget createProgressBar(int x, int y, double animationDuration, GuiBuilder.ProgressDirection direction) { return Widgets.createDrawableWidget((drawContext, mouseX, mouseY, delta) -> { - drawContext.drawTexture(GuiBuilder.resourceLocation, x, y, direction.x, direction.y, direction.width, direction.height); + drawSprite(drawContext, direction.baseSprite, x, y); int j = (int) ((System.currentTimeMillis() / animationDuration) % 1.0 * 16.0); if (j < 0) { j = 0; } switch (direction) { - case RIGHT -> drawContext.drawTexture(GuiBuilder.resourceLocation, x, y, direction.xActive, direction.yActive, j, 10); - case LEFT -> drawContext.drawTexture(GuiBuilder.resourceLocation, x + 16 - j, y, direction.xActive + 16 - j, direction.yActive, j, 10); - case UP -> drawContext.drawTexture(GuiBuilder.resourceLocation, x, y + 16 - j, direction.xActive, direction.yActive + 16 - j, 10, j); - case DOWN -> drawContext.drawTexture(GuiBuilder.resourceLocation, x, y, direction.xActive, direction.yActive, 10, j); + case RIGHT, LEFT -> drawSprite(drawContext, direction.overlaySprite, x, y, j, 10); + case UP, DOWN -> drawSprite(drawContext, direction.overlaySprite, x, y, 10, j); } }); } @@ -297,105 +295,87 @@ public class ReiPlugin implements REIClientPlugin { return Widgets.createSlot(bounds).entry(copy); } - private static class EnergyEntryRenderer implements Renderer { - private final EntryAnimation animation; - private final Function tooltipBuilder; - - protected EnergyEntryRenderer(EntryAnimation animation, Function tooltipBuilder) { - this.animation = animation; - this.tooltipBuilder = tooltipBuilder; - } - + private record EnergyEntryRenderer(EntryAnimation animation, Function tooltipBuilder) implements Renderer { @Override - public void render(DrawContext drawContext, Rectangle bounds, int mouseX, int mouseY, float delta) { - int width = bounds.width + 2; - int height = bounds.height + 2; - int innerHeight = height - 2; + public void render(DrawContext drawContext, Rectangle bounds, int mouseX, int mouseY, float delta) { + int width = bounds.width + 2; + int height = bounds.height + 2; + int innerHeight = height - 2; - PowerSystem.EnergySystem displayPower = PowerSystem.getDisplayPower(); - drawContext.drawTexture(GuiBuilder.resourceLocation, bounds.x - 1, bounds.y - 1, displayPower.xBar - 15, displayPower.yBar - 1, width, height); - int innerDisplayHeight; - if (animation.animationType != EntryAnimationType.NONE) { - innerDisplayHeight = MathHelper.ceil((System.currentTimeMillis() / (animation.duration / (float) innerHeight) % innerHeight)); - if (animation.animationType == EntryAnimationType.DOWNWARDS) - innerDisplayHeight = innerHeight - innerDisplayHeight; - } else innerDisplayHeight = innerHeight; - drawContext.drawTexture(GuiBuilder.resourceLocation, bounds.x, bounds.y + innerHeight - innerDisplayHeight, displayPower.xBar, innerHeight + displayPower.yBar - innerDisplayHeight, width - 2, innerDisplayHeight); - } - - @Override - @Nullable - public Tooltip getTooltip(TooltipContext context) { - return this.tooltipBuilder.apply(context); - } - } - - private static class FluidStackRenderer implements EntryRenderer { - private final EntryAnimation animation; - private final EntryRenderer parent; - - public FluidStackRenderer(EntryAnimation animation, EntryRenderer parent) { - this.animation = animation; - this.parent = parent; - } - - @Override - public void render(EntryStack entry, DrawContext drawContext, Rectangle bounds, int mouseX, int mouseY, float delta) { - int width = bounds.width; - int height = bounds.height; - - drawContext.drawTexture(GuiBuilder.resourceLocation, bounds.x - 4, bounds.y - 4, 194, 26, width + 8, height + 8); - drawContext.drawTexture(GuiBuilder.resourceLocation, bounds.x - 1, bounds.y - 1, 194, 82, width + 2, height + 2); - int innerDisplayHeight; - if (animation.animationType != EntryAnimationType.NONE) { - innerDisplayHeight = MathHelper.ceil((System.currentTimeMillis() / (animation.duration / (float) height) % height)); - if (animation.animationType == EntryAnimationType.DOWNWARDS) - innerDisplayHeight = height - innerDisplayHeight; - } else innerDisplayHeight = height; - drawFluid(drawContext, entry.getValue().getFluid(), innerDisplayHeight, bounds.x, bounds.y, width, height); - } - - public void drawFluid(DrawContext drawContext, Fluid fluid, int drawHeight, int x, int y, int width, int height) { - RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE); - y += height; - - FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluid); - - // If registry can't find it, don't render. - if (handler == null) { - return; + drawSprite(drawContext, GuiSprites.POWER_BAR_BASE, bounds.x - 1, bounds.y - 1); + int innerDisplayHeight; + if (animation.animationType != EntryAnimationType.NONE) { + innerDisplayHeight = MathHelper.ceil((System.currentTimeMillis() / (animation.duration / (float) innerHeight) % innerHeight)); + if (animation.animationType == EntryAnimationType.DOWNWARDS) + innerDisplayHeight = innerHeight - innerDisplayHeight; + } else innerDisplayHeight = innerHeight; + drawSprite(drawContext, GuiSprites.POWER_BAR_OVERLAY, bounds.x, bounds.y + innerHeight - innerDisplayHeight, width - 2, innerDisplayHeight); } - final Sprite sprite = handler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0]; - int color = FluidRenderHandlerRegistry.INSTANCE.get(fluid).getFluidColor(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState()); + @Override + @Nullable + public Tooltip getTooltip(TooltipContext context) { + return this.tooltipBuilder.apply(context); + } + } - final int iconHeight = sprite.getContents().getHeight(); - int offsetHeight = drawHeight; + private record FluidStackRenderer(EntryAnimation animation, EntryRenderer parent) implements EntryRenderer { + @Override + public void render(EntryStack entry, DrawContext drawContext, Rectangle bounds, int mouseX, int mouseY, float delta) { + int width = bounds.width; + int height = bounds.height; - RenderSystem.setShaderColor((color >> 16 & 255) / 255.0F, (float) (color >> 8 & 255) / 255.0F, (float) (color & 255) / 255.0F, 1F); + drawSprite(drawContext, GuiSprites.TANK_BACKGROUND, bounds.x - 4, bounds.y - 4); + int innerDisplayHeight; + if (animation.animationType != EntryAnimationType.NONE) { + innerDisplayHeight = MathHelper.ceil((System.currentTimeMillis() / (animation.duration / (float) height) % height)); + if (animation.animationType == EntryAnimationType.DOWNWARDS) + innerDisplayHeight = height - innerDisplayHeight; + } else innerDisplayHeight = height; + drawFluid(drawContext, entry.getValue().getFluid(), innerDisplayHeight, bounds.x, bounds.y, width, height); + drawSprite(drawContext, GuiSprites.TANK_FOREGROUND, bounds.x - 1, bounds.y - 1); + } - int iteration = 0; - while (offsetHeight != 0) { - final int curHeight = Math.min(offsetHeight, iconHeight); + public void drawFluid(DrawContext drawContext, Fluid fluid, int drawHeight, int x, int y, int width, int height) { + y += height; - drawContext.drawSprite(x, y - offsetHeight, 0, width, curHeight, sprite); - offsetHeight -= curHeight; - iteration++; - if (iteration > 50) { - break; + FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluid); + + // If registry can't find it, don't render. + if (handler == null) { + return; } + + final Sprite sprite = handler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0]; + int color = FluidRenderHandlerRegistry.INSTANCE.get(fluid).getFluidColor(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState()); + + final int iconHeight = sprite.getContents().getHeight(); + int offsetHeight = drawHeight; + + drawContext.setShaderColor((color >> 16 & 255) / 255.0F, (float) (color >> 8 & 255) / 255.0F, (float) (color & 255) / 255.0F, 1F); + + int iteration = 0; + while (offsetHeight != 0) { + final int curHeight = Math.min(offsetHeight, iconHeight); + + drawContext.drawSprite(x, y - offsetHeight, 0, width, curHeight, sprite); + offsetHeight -= curHeight; + iteration++; + if (iteration > 50) { + break; + } + } + drawContext.setShaderColor(1, 1, 1, 1); + } + + @Override + @Nullable + public Tooltip getTooltip(EntryStack entry, TooltipContext context) { + return parent.getTooltip(entry, context); } } - @Override - @Nullable - public Tooltip getTooltip(EntryStack entry, TooltipContext context) { - return parent.getTooltip(entry, context); - } - } - public record EntryAnimation(EntryAnimationType animationType, long duration) { - public static EntryAnimation upwards(long duration) { return new EntryAnimation(EntryAnimationType.UPWARDS, duration); } diff --git a/src/client/java/techreborn/client/gui/GuiAESU.java b/src/client/java/techreborn/client/gui/GuiAESU.java index 08ad3fb17..5805da55d 100644 --- a/src/client/java/techreborn/client/gui/GuiAESU.java +++ b/src/client/java/techreborn/client/gui/GuiAESU.java @@ -79,7 +79,7 @@ public class GuiAESU extends GuiBase { .append("/") .append(PowerSystem.getLocalizedPowerNoSuffix(blockEntity.getMaxStoredPower())) .append(" ") - .append(PowerSystem.getDisplayPower().abbreviation); + .append(PowerSystem.ABBREVIATION); drawCentredText(drawContext, text, 35, 0, 58, layer); matrices.pop(); diff --git a/src/client/java/techreborn/client/gui/GuiIDSU.java b/src/client/java/techreborn/client/gui/GuiIDSU.java index 50fc58c73..f442399f6 100644 --- a/src/client/java/techreborn/client/gui/GuiIDSU.java +++ b/src/client/java/techreborn/client/gui/GuiIDSU.java @@ -66,7 +66,7 @@ public class GuiIDSU extends GuiBase { .append("/") .append(PowerSystem.getLocalizedPowerNoSuffix(idsu.getMaxStoredPower())) .append(" ") - .append(PowerSystem.getDisplayPower().abbreviation); + .append(PowerSystem.ABBREVIATION); drawCentredText(drawContext, text, 35, 0, 58, layer); diff --git a/src/client/java/techreborn/client/gui/GuiLESU.java b/src/client/java/techreborn/client/gui/GuiLESU.java index 30432de10..fd9af87f4 100644 --- a/src/client/java/techreborn/client/gui/GuiLESU.java +++ b/src/client/java/techreborn/client/gui/GuiLESU.java @@ -63,7 +63,7 @@ public class GuiLESU extends GuiBase { .append("/") .append(PowerSystem.getLocalizedPowerNoSuffix(blockEntity.getMaxStoredPower())) .append(" ") - .append(PowerSystem.getDisplayPower().abbreviation), + .append(PowerSystem.ABBREVIATION), 35, 0, 58, layer); matrices.pop();