Skip to content

Commit

Permalink
fix text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pupbrained committed Sep 16, 2024
1 parent 9ed6fe5 commit 350b99c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/main/java/xyz/pupbrained/mixin/ItemDropMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ private void onItemDrop(boolean dropFullStack, CallbackInfo ci) {

new Thread(() -> {
try {
Thread.sleep(1000);
Thread.sleep(2000);

synchronized (DropConfirmUtil.class) {
DropConfirmUtil.confirmed = false;
DropConfirmUtil.showConfirmationPrompt = false;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/xyz/pupbrained/mixin/RenderMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ private void onRender(CallbackInfo ci) {
long currentTime = System.currentTimeMillis();
long elapsedTime = currentTime - DropConfirmUtil.promptStartTime;

// Calculate alpha value based on elapsed time (fade out over 1000ms)
float alpha = 1.0f - (elapsedTime / 1000.0f); // Alpha decreases over time
if (alpha < 0.0f) {
alpha = 0.0f; // Ensure alpha doesn't go below 0
float alpha = 1.0f;

if (elapsedTime > 2000)
alpha = 1.0f - ((elapsedTime - 2000) / 500.0f);

// Make sure alpha doesn't go into negatives
alpha = Math.max(0.0f, alpha);

// Prevents flashing
if (alpha <= 0.01f) {
DropConfirmUtil.showConfirmationPrompt = false;
return;
}

// Convert alpha to a hex value (between 0 and 255) and incorporate it into the color
// Convert alpha to a hex value (between 0 and 255)
int alphaHex = (int) (alpha * 255) << 24;
int color = 0xFFFFFF | alphaHex; // Combine white color with alpha

// Weird GL stuff
// Add it to the RGB value
int color = alphaHex | 0xFFFFFF;

GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND); // Enable blending for alpha transparency
Expand All @@ -46,17 +55,11 @@ private void onRender(CallbackInfo ci) {
"Press Q again to drop this item.",
mc.resolution.scaledWidth / 2, // Complete center of the screen horizontally
mc.resolution.scaledHeight - 60, // A little above the hotbar
color // Color with alpha
color
);

// Undo weird GL stuff
GL11.glDisable(GL11.GL_BLEND); // Disable blending after rendering
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();

// Stop showing the prompt after it has fully faded out
if (alpha == 0.0f) {
DropConfirmUtil.showConfirmationPrompt = false;
}
}
}

0 comments on commit 350b99c

Please sign in to comment.