Skip to content

Commit

Permalink
1.20.1 changes everything works smoothly
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jun 14, 2023
1 parent a15f579 commit 9a61bf0
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 141 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void onInitializeClient() {
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> {
dynamicutil.getWidgetManager().saveWidgets(WIDGETS_FILE);
});
HudRenderCallback.EVENT.register((matrices, tickDelta) -> {
dynamicutil.render(matrices, tickDelta);
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
dynamicutil.render(drawContext, tickDelta);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;

public class DrawHelper extends DrawContext {
Expand All @@ -16,19 +15,19 @@ public DrawHelper(MinecraftClient client, VertexConsumerProvider.Immediate verte
/**
* Fills a box on the screen with a specified color.
*
* @param matrices The matrix stack used for rendering
* @param drawContext The matrix stack used for rendering
* @param x The x position of the rectangle
* @param y The y position of the rectangle
* @param width The width of the rectangle
* @param height The height of the rectangle
* @param color The color to fill the rectangle with
*/
public static void drawBox(MatrixStack matrices, int x, int y, int width, int height, int color) {
public static void drawBox(DrawContext drawContext, int x, int y, int width, int height, int color) {
int x1 = x - width / 2 - 2;
int y1 = y - height / 2 - 2;
int x2 = x + width / 2 + 2;
int y2 = y + height / 2 + 2;
fill(matrices, x1, y1, x2, y2, color);
drawContext.fill(x1, y1, x2, y2, color);
}

/**
Expand All @@ -40,46 +39,27 @@ public static void drawBox(MatrixStack matrices, int x, int y, int width, int he
* @param y2 The y position of the bottom right corner of the rectangle
* @param color The color to fill the rectangle with
*/
public void fill(int x1, int y1, int x2, int y2, int color) {
this.fill(RenderLayer.getGui(), x1, y1, x2, y2, color);
}

/**
* Draws text on the screen with a shadow.
*
* @param matrices The matrix stack used for rendering
* @param textRenderer The text renderer instance used for rendering the text
* @param text The text to draw
* @param x The x position to draw the text at
* @param y The y position to draw the text at
* @param color The color to draw the text with
*/
public static void drawTextWithShadow(MatrixStack matrices,
TextRenderer textRenderer,
String text,
int x,
int y,
int color) {
textRenderer.drawWithShadow(matrices, text, x, y, color);
public static void fill(DrawContext drawContext, int x1, int y1, int x2, int y2, int color) {
drawContext.fill(x1, y1, x2, y2, color);
}

/**
* Draws text on screen.
* TODO: Also fix this
*
* @param textRenderer - TextRenderer instance used for rendering.
* @param text - Text to be drawn.
* @param x - X position to draw at.
* @param y - Y position to draw at.
* @param color - Color to draw with.
*/
public static void drawText(TextRenderer textRenderer,
public static void drawText(DrawContext drawContext,
TextRenderer textRenderer,
String text,
int x,
int y,
int color,
boolean shadow) {
textRenderer.draw(text, x, y, color, shadow);
drawContext.drawText(textRenderer,text, x, y, color, shadow);
}

/**
Expand Down Expand Up @@ -137,12 +117,12 @@ public static void fillRoundedRect(Matrix4f matrix4f, int x1, int y1, int x2, in
RenderSystem.disableBlend();
}

public void fillRoundedRect(MatrixStack matrices, int left, int top, int right, int bottom, int color) {
fill(RenderLayer.getGui(), left + 1, top, right - 1, top + 1, color);
fill(RenderLayer.getGui(), left + 1, bottom - 1, right - 1, bottom, color);
fill(RenderLayer.getGui(), left, top + 1, left + 1, bottom - 1, color);
fill(RenderLayer.getGui(), right - 1, top + 1, right, bottom - 1, color);
fill(RenderLayer.getGui(), left + 1, top + 1, right - 1, bottom - 1, color);
public static void fillRoundedRect(DrawContext drawContext, int left, int top, int right, int bottom, int color) {
drawContext.fill( left + 1, top, right - 1, top + 1, color);
drawContext.fill( left + 1, bottom - 1, right - 1, bottom, color);
drawContext.fill(left, top + 1, left + 1, bottom - 1, color);
drawContext.fill(right - 1, top + 1, right, bottom - 1, color);
drawContext.fill(left + 1, top + 1, right - 1, bottom - 1, color);
}

/**
Expand Down Expand Up @@ -181,18 +161,17 @@ public static void fillGradient(Matrix4f matrix4f, int x1, int y1, int x2, int y
/**
* Draws an outlined box on the screen.
*
* @param matrices The matrix stack used for rendering
* @param x1 The x position of the top left corner of the box
* @param y1 The y position of the top left corner of the box
* @param x2 The x position of the bottom right corner of the box
* @param y2 The y position of the bottom right corner of the box
* @param color The color to draw the box with
*/
public void drawOutlinedBox(MatrixStack matrices, int x1, int y1, int x2, int y2, int color) {
fill(RenderLayer.getGui(), x1, y1, x2, y1 + 1, color);
fill(RenderLayer.getGui(), x1, y2 - 1, x2, y2, color);
fill(RenderLayer.getGui(), x1, y1 + 1, x1 + 1, y2 - 1, color);
fill(RenderLayer.getGui(), x2 - 1, y1 + 1, x2, y2 - 1, color);
public static void drawOutlinedBox(DrawContext drawContext, int x1, int y1, int x2, int y2, int color) {
drawContext.fill( x1, y1, x2, y1 + 1, color);
drawContext.fill( x1, y2 - 1, x2, y2, color);
drawContext.fill( x1, y1 + 1, x1 + 1, y2 - 1, color);
drawContext.fill( x2 - 1, y1 + 1, x2, y2 - 1, color);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,53 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

/**
* This class provides helper methods for drawing textures on the screen.
*/
public class TextureHelper {
public class TextureHelper extends DrawContext {
public TextureHelper(MinecraftClient client, VertexConsumerProvider.Immediate vertexConsumers) {
super(client, vertexConsumers);
}

/**
* Draws an item texture on the screen.
*
* @param matrices The matrix stack used for rendering
* @param itemRenderer The item renderer instance used for rendering the item texture
* @param itemStack The item stack to render the texture for
* @param x The x position to draw the texture at
* @param y The y position to draw the texture at
*/
public static void drawItemTexture(MatrixStack matrices,
ItemRenderer itemRenderer,
public static void drawItemTexture(DrawContext drawContext,
ItemStack itemStack,
int x,
int y) {
itemRenderer.renderInGui(matrices,itemStack, x, y);
drawContext.drawItem(itemStack,x,y);
}

/**
* Draws the texture of the item in the player's main hand on the screen.
*
* @param matrices The matrix stack used for rendering
* @param itemRenderer The item renderer instance used for rendering the item texture
* @param client The Minecraft client instance
* @param x The x position to draw the texture at
* @param y The y position to draw the texture at
*/
public static void drawMainHandTexture(MatrixStack matrices,
ItemRenderer itemRenderer,
public static void drawMainHandTexture(DrawContext drawContext,
MinecraftClient client,
int x,
int y) {
assert client.player != null;
ItemStack mainHandItem = client.player.getMainHandStack();
drawItemTexture(matrices, itemRenderer, mainHandItem, x, y);
drawItemTexture(drawContext,mainHandItem, x, y);
}
/**
* Draws a textured rectangle on the screen.
*
* @param matrices The matrix stack used for rendering
* @param x The x position of the top left corner of the rectangle
* @param y The y position of the top left corner of the rectangle
* @param u The x position of the texture within the texture image
Expand All @@ -60,14 +59,13 @@ public static void drawMainHandTexture(MatrixStack matrices,
* @param textureWidth The width of the texture image
* @param textureHeight The height of the texture image
*/
public static void drawTexture(MatrixStack matrices, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight) {
DrawableHelper.drawTexture(matrices, x, y, u, v, width, height, textureWidth, textureHeight);
public static void drawTexture(DrawContext drawContext, Identifier texture, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight) {
drawContext.drawTexture(texture, x, y, u, v, width, height, textureWidth, textureHeight);
}

/**
* Draws a textured rectangle on the screen with a specified color.
*
* @param matrices The matrix stack used for rendering
* @param x The x position of the top left corner of the rectangle
* @param y The y position of the top left corner of the rectangle
* @param u The x position of the texture within the texture image
Expand All @@ -76,12 +74,12 @@ public static void drawTexture(MatrixStack matrices, int x, int y, int u, int v,
* @param height The height of the rectangle
* @param color The color to draw the rectangle with
*/
public static void drawTexturedRect(MatrixStack matrices, int x, int y, int u, int v, int width, int height, int color) {
public static void drawTexturedRect(DrawContext drawContext,Identifier texture, int x, int y, int u, int v, int width, int height, int color) {
RenderSystem.setShaderColor((color >> 16 & 255) / 255.0F,
(color >> 8 & 255) / 255.0F,
(color & 255) / 255.0F,
(color >> 24 & 255) / 255.0F);
DrawableHelper.drawTexture(matrices, x, y, u, v, width, height);
drawContext.drawTexture(texture, x, y, u, v, width, height);
}
/**
* Draws an item texture on the screen with text at a specified position relative to it.
Expand All @@ -98,6 +96,7 @@ public static void drawTexturedRect(MatrixStack matrices, int x, int y, int u, i
* @param scale The scale factor to apply to the text (1.0 is normal size)
*/
public static void drawItemTextureWithText(MatrixStack matrices,
DrawContext drawContext,
ItemRenderer itemRenderer,
TextRenderer textRenderer,
ItemStack itemStack,
Expand Down Expand Up @@ -136,11 +135,11 @@ public static void drawItemTextureWithText(MatrixStack matrices,
matrices.scale(scale, scale, 1.0f);
float scaledX = textX / scale;
float scaledY = textY / scale;
textRenderer.draw(matrices, text, scaledX, scaledY, color);
drawContext.drawText(textRenderer, text, (int) scaledX, (int) scaledY, color,false);
matrices.pop();

// Draw the item texture
itemRenderer.renderInGui(matrices,itemStack, x, y);
drawContext.drawItem(itemStack, x, y);
}

public enum Position {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

public abstract class AbstractMoveableScreen extends Screen {
Expand Down Expand Up @@ -143,18 +142,18 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)

// Draw each widget
for (Widget widget : dynamicutil.getWidgetManager().getWidgets()) {
widget.render(drawContext.getMatrices());
widget.render(drawContext);
}

// Draw the slider and other stuff
if (Slider != null) {
Slider.render(drawContext.getMatrices());
Slider.render(drawContext);
}
if (contextMenu != null) {
contextMenu.render(drawContext.getMatrices());
contextMenu.render(drawContext);
}
if (colorPicker != null) {
colorPicker.render(drawContext.getMatrices());
colorPicker.render(drawContext);
}
updateMouseHandler(colorPicker, contextMenu, Slider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.tanishisherewith.dynamichud.widget.text.TextWidget;
import com.tanishisherewith.dynamichud.widget.Widget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

import java.awt.*;
Expand All @@ -31,9 +31,9 @@ public MoveableScreen(Text title, DynamicUtil dynamicutil) {
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
super.render(matrices, mouseX, mouseY, delta);
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, "Editor Screen", MinecraftClient.getInstance().getWindow().getScaledWidth() / 2f - textRenderer.getWidth("Editor Screen") / 2f, 5, ColorHelper.ColorToInt(Color.WHITE), false);
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
super.render(drawContext, mouseX, mouseY, delta);
drawContext.drawTextWithShadow(textRenderer,"Editors Screen", (int) (MinecraftClient.getInstance().getWindow().getScaledWidth() / 2f - textRenderer.getWidth("Editor Screen") / 2f),5,ColorHelper.ColorToInt(Color.WHITE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.VertexConsumerProvider;

/**
* This class provides utility methods for working with the DynamicHUD mod.
*/
public class DynamicUtil extends DrawHelper {
public class DynamicUtil extends DrawContext {
private final WidgetManager widgetManager; // The WidgetManager instance used by this class
public boolean WidgetAdded = false;
public boolean WidgetLoaded = false;
Expand All @@ -26,6 +28,7 @@ public class DynamicUtil extends DrawHelper {
* @param client The Minecraft client instance
*/
public DynamicUtil(MinecraftClient client) {
super(client, VertexConsumerProvider.immediate(new BufferBuilder(3)));
this.widgetManager = new WidgetManager();
}

Expand All @@ -52,17 +55,17 @@ public void render(DrawContext context, float delta) {
for (Widget widget : widgetManager.getWidgets()) {
if (!MinecraftClient.getInstance().options.debugEnabled || MinecraftClient.getInstance().currentScreen instanceof AbstractMoveableScreen) {
if (MinecraftClient.getInstance().currentScreen instanceof AbstractMoveableScreen) {
widget.render(context.getMatrices());
widget.render(context);
} else if (widget.isEnabled()) {
widget.render(context.getMatrices());
widget.render(context);
}
}

// Draw a red box around the widget if the HUD is disabled
if (MinecraftClient.getInstance().currentScreen instanceof AbstractMoveableScreen) {
int backgroundColor = widget.isEnabled() ? ColorHelper.getColor(0, 0, 0, 128) : ColorHelper.getColor(255, 0, 0, 128);
WidgetBox box = widget.getWidgetBox();
DrawHelper.fill(context.getMatrices(), box.x1, box.y1, box.x2, box.y2, backgroundColor);
context.fill(box.x1, box.y1, box.x2, box.y2, backgroundColor);
}
}
}
Expand Down
Loading

0 comments on commit 9a61bf0

Please sign in to comment.