Skip to content

Commit

Permalink
Added Texture support for API.
Browse files Browse the repository at this point in the history
  • Loading branch information
LordAnaku committed Aug 23, 2022
1 parent e7c6d12 commit d3b8470
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.8

# Mod Properties
mod_version = 1.1.3-1.19.2
mod_version = 1.1.4-1.19.2
maven_group = io.github.lordanaku
archives_base_name = anakus_status_bars

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,84 @@
import io.github.lordanaku.anakus_status_bars.utils.ColorUtils;
import io.github.lordanaku.anakus_status_bars.utils.TextureRecord;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Identifier;

import static io.github.lordanaku.anakus_status_bars.screen.hud.RenderHudElements.*;

@SuppressWarnings("unused")
public class RenderHudFunctions {
public static void drawDefaultBar(boolean leftSide, int posYMod, TextureRecord textureRecord) {

/**
* Draws the defalut background bar for the HUD.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param textureRecord - the texture record for the bar.
*/
public static void drawDefaultBar(boolean side, int posYMod, TextureRecord textureRecord) {
RenderSystem.setShaderTexture(0, textureRecord.texture());
int side = (leftSide) ? posXLeft : posXRight;
int finalSide = (side) ? posXLeft : posXRight;
RenderSystem.setShaderColor(1, 1, 1, 1);
DrawableHelper.drawTexture(hudMatrix, side, posY + posYMod,
DrawableHelper.drawTexture(hudMatrix, finalSide, posY + posYMod,
textureRecord.startX(), textureRecord.startY(),
textureRecord.width(), textureRecord.height(),
textureRecord.maxWidth(), textureRecord.maxHeight());
}

public static void drawExhaustBar(boolean leftSide, int posYMod, TextureRecord textureRecord, int progress, float alpha) {
/**
* Draws an overlay on the bar for an alternative way of showing info.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param textureRecord - the texture record for the bar.
* @param progress - the progress of the bar.
* @param alpha - the color of the bar. (Hex Value)
*/
public static void drawExhaustBar(boolean side, int posYMod, TextureRecord textureRecord, int progress, float alpha) {
RenderSystem.setShaderTexture(0, textureRecord.texture());
RenderSystem.setShaderColor(1, 1, 1, alpha);
drawProgress(leftSide, posYMod, textureRecord, progress);
drawProgress(side, posYMod, textureRecord, progress);
}

public static void drawProgressBar(boolean leftSide, int posYMod, TextureRecord textureRecord, int progress, int color, float alpha) {
/**
* Draws the progress bar for the HUD.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param textureRecord - the texture record for the bar.
* @param progress - the progress of the bar.
* @param color - the color of the bar. (Hex Value)
* @param alpha - the alpha of the bar.
*/
public static void drawProgressBar(boolean side, int posYMod, TextureRecord textureRecord, int progress, int color, float alpha) {
RenderSystem.setShaderTexture(0, textureRecord.texture());
RenderSystem.setShaderColor(ColorUtils.fromHex(color).getRedF(), ColorUtils.fromHex(color).getGreenF(), ColorUtils.fromHex(color).getBlueF(), alpha);
drawProgress(leftSide, posYMod, textureRecord, progress);
drawProgress(side, posYMod, textureRecord, progress);
}

public static void drawStatusEffectBar(boolean leftSide, int posYMod, TextureRecord textureRecord, int color) {
/**
* Draws Colorized bar for when status effect is applied.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param textureRecord - the texture record for the bar.
* @param color - the color of the bar. (Hex Value)
*/
public static void drawStatusEffectBar(boolean side, int posYMod, TextureRecord textureRecord, int color) {
RenderSystem.setShaderTexture(0, textureRecord.texture());
RenderSystem.setShaderColor(ColorUtils.fromHex(color).getRedF(), ColorUtils.fromHex(color).getGreenF(), ColorUtils.fromHex(color).getBlueF(), 1);
int side = (leftSide) ? posXLeft : posXRight;
DrawableHelper.drawTexture(hudMatrix, side, posY + posYMod,
int finalSide = (side) ? posXLeft : posXRight;
DrawableHelper.drawTexture(hudMatrix, finalSide, posY + posYMod,
textureRecord.startX(), textureRecord.startY(),
textureRecord.width(), textureRecord.height(),
textureRecord.maxWidth(), textureRecord.maxHeight());
}

/**
* Draws the icon for the bar.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param textureRecord - the texture record for the bar.
* @param barWidth - the width of the bar so method can determine offset.
*/
public static void drawIcon(boolean side, int posYMod, TextureRecord textureRecord, int barWidth) {
RenderSystem.setShaderTexture(0, Screen.GUI_ICONS_TEXTURE);
RenderSystem.setShaderTexture(0, textureRecord.texture());
RenderSystem.setShaderColor(1, 1, 1, 1);
if (side) {
DrawableHelper.drawTexture(hudMatrix,
Expand All @@ -62,16 +99,24 @@ public static void drawIcon(boolean side, int posYMod, TextureRecord textureReco
}
}

/**
* Sets the amount that the bars will iterate up and down as what is rendered changes. (set to height of bar + 1 for default))
* @param incrementAmount - amount Y is incremented by.
*/
public static void setYModIncrement(int incrementAmount) {
yModIncrement = incrementAmount;
}

/**
* Sets defalut texture for the bars. (only call if you wish to set your own texture for vanilla hud elements)
* @param texture - New texture for the bars.
*/
public static void setDefaultTexture(Identifier texture) {
ASBModUtils.defaultTexture = texture;
}

private static void drawProgress(boolean leftSide, int posYMod, TextureRecord textureRecord, int progress) {
if (leftSide) {
private static void drawProgress(boolean side, int posYMod, TextureRecord textureRecord, int progress) {
if (side) {
DrawableHelper.drawTexture(hudMatrix,
posXLeft, posY + posYMod,
textureRecord.startX(), textureRecord.startY(),
Expand Down

0 comments on commit d3b8470

Please sign in to comment.