Skip to content

Commit

Permalink
Update to use DrawContext properly instead of MatrixStack
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonerd-04 committed Jun 8, 2023
1 parent 7c56048 commit f39bcd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/main/java/me/Ieonerd/simplehud/gui/SimpleHUDDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SimpleHUDDisplay(MinecraftClient client){
//Rendering algorithm based off of the one used to render the left side of the F3 screen
//With the exception that instead of rendering one string as a row, this mod renders one array of strings as a row
//To allow for individual sections of a given row to be different colors.
public void render(MatrixStack matrices){
public void render(DrawContext context){
int fps = MinecraftClientAccessor.getCurrentFPS();

ArrayList<String[]> text = this.getText(fps, minFps);
Expand All @@ -49,28 +49,28 @@ public void render(MatrixStack matrices){
Objects.requireNonNull(this.client.textRenderer);

int height = 2 + 9 * i;
renderRow(matrices, height, row, rowColors);
renderRow(context, height, row, rowColors);
}
}

//Renders an array of strings as a row in the HUD
//colors is allowed to be shorter than row.
//If this happens, the last color in the array of colors will be used to render the rest of the row.
private void renderRow(MatrixStack matrices, int height, String[] row, int[] colors){
private void renderRow(DrawContext context, int height, String[] row, int[] colors){
int position = 0; //Stores the position to render a particular string in the row
String str;
int color = colors[0];

for(String string : row) position += this.client.textRenderer.getWidth(string);

DrawContext.fill(matrices, 1, height - 1, 3 + position, height + 8, HUD_BACKGROUND);
context.fill(1, height - 1, 3 + position, height + 8, HUD_BACKGROUND);
position = 0;

for(int i = 0; i < row.length; i++){
str = row[i];
if(i < colors.length) color = colors[i];

this.client.textRenderer.draw(matrices, str, 2.0F + position, (float)height, color);
context.drawText(this.client.textRenderer, str, 2 + position, height, color, false);
position += this.client.textRenderer.getWidth(str);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/Ieonerd/simplehud/mixin/MixinInGameHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@Environment(EnvType.CLIENT)
@Mixin(InGameHud.class)
public class MixinInGameHud extends DrawContext {
public class MixinInGameHud {

@Shadow @Final private MinecraftClient client;
SimpleHUDDisplay simpleHUD;
Expand All @@ -35,8 +35,8 @@ public void addSimpleHudToHUD(MinecraftClient client, ItemRenderer itemRenderer,
//It is rendered last, so it would appear above anything that the vanilla HUD would render.
//It only renders when the F3 menu is closed.
@Inject(method = "render", at = @At("TAIL"))
public void renderSimpleHud(MatrixStack matrices, float tickDelta, CallbackInfo ci){
if(!this.client.options.debugEnabled) simpleHUD.render(matrices);
public void renderSimpleHud(DrawContext context, float tickDelta, CallbackInfo ci){
if(!this.client.options.debugEnabled) simpleHUD.render(context);
}

}

0 comments on commit f39bcd2

Please sign in to comment.