Skip to content

Commit

Permalink
Fix fast vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Aug 3, 2024
1 parent 8e39b6c commit c4c405e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/main/java/dev/tr7zw/exordium/mixin/VignetteMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.tr7zw.exordium.mixin;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
Expand All @@ -13,16 +15,22 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.border.WorldBorder;

@Mixin(Gui.class)
public class VignetteMixin {

@Shadow
@Final
private Minecraft minecraft;

private static ResourceLocation FAST_VIGNETTE_LOCATION = new ResourceLocation("exordium",
"textures/misc/fast_vignette.png");
private static ResourceLocation FAST_VIGNETTE_DARK_LOCATION = new ResourceLocation("exordium",
"textures/misc/fast_vignette_dark.png");

@WrapOperation(method = "renderCameraOverlays", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;renderVignette(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/entity/Entity;)V"), })
Expand All @@ -33,32 +41,44 @@ private void renderVignetteWrapper(Gui gui, GuiGraphics guiGraphics, Entity enti
float brightness = ((Gui) (Object) this).vignetteBrightness;
if (!buffer.renderBuffer(0, brightness)) {
if (ExordiumModBase.instance.config.vignetteSettings.isEnabled()) {
renderCustomVignette(guiGraphics, brightness);
renderCustomVignette(guiGraphics);
} else {
operation.call(gui, guiGraphics, entity);
}
}
buffer.postRender(brightness);
}

public void renderCustomVignette(GuiGraphics guiGraphics, float brightness) {
public void renderCustomVignette(GuiGraphics guiGraphics) {
WorldBorder worldBorder = minecraft.level.getWorldBorder();
float f = 0.0F;
float g = (float) worldBorder.getDistanceToBorder(minecraft.player);
double d = Math.min(worldBorder.getLerpSpeed() * (double) worldBorder.getWarningTime() * 1000.0,
Math.abs(worldBorder.getLerpTarget() - worldBorder.getSize()));
double e = Math.max((double) worldBorder.getWarningBlocks(), d);
if ((double) g < e) {
f = 1.0F - (float) ((double) g / e);
}
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
// RenderSystem.blendFuncSeparate(SourceFactor.ZERO,
// DestFactor.ONE_MINUS_SRC_COLOR, SourceFactor.ONE,
// DestFactor.ZERO);
ExordiumModBase.correctBlendMode();
float f = brightness;
ResourceLocation texture = FAST_VIGNETTE_DARK_LOCATION;
float brightness = ((Gui) (Object) this).vignetteBrightness;
g = Mth.clamp(brightness, 0.0F, 1.0F);
if (f > 0.0F) {
// red tint
f = Mth.clamp(f, 0.0F, 1.0F);
guiGraphics.setColor(f, 0.0F, 0.0F, 1.0F);
g = Math.max(g, f);
guiGraphics.setColor(f, 0.0F, 0.0F, g);
texture = FAST_VIGNETTE_LOCATION;
} else {
float g = ((Gui) (Object) this).vignetteBrightness;
g = Mth.clamp(g, 0.0F, 1.0F);
guiGraphics.setColor(0, 0, 0, ((Gui) (Object) this).vignetteBrightness);
guiGraphics.setColor(1.0F, 1.0F, 1.0F, g);
}

guiGraphics.blit(FAST_VIGNETTE_LOCATION, 0, 0, -90, 0.0F, 0.0F, guiGraphics.guiWidth(), guiGraphics.guiHeight(),
guiGraphics.blit(texture, 0, 0, -90, 0.0F, 0.0F, guiGraphics.guiWidth(), guiGraphics.guiHeight(),
guiGraphics.guiWidth(), guiGraphics.guiHeight());

RenderSystem.depthMask(true);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c4c405e

Please sign in to comment.