1+ package team .steelcode .awakenings .mixin ;
2+
3+ import com .mojang .blaze3d .resource .CrossFrameResourcePool ;
4+ import net .minecraft .client .DeltaTracker ;
5+ import net .minecraft .client .Minecraft ;
6+ import net .minecraft .client .renderer .GameRenderer ;
7+ import net .minecraft .client .renderer .LevelTargetBundle ;
8+ import net .minecraft .client .renderer .PostChain ;
9+ import net .minecraft .resources .ResourceLocation ;
10+ import net .minecraft .world .entity .player .Player ;
11+ import org .spongepowered .asm .mixin .Final ;
12+ import org .spongepowered .asm .mixin .Mixin ;
13+ import org .spongepowered .asm .mixin .Shadow ;
14+ import org .spongepowered .asm .mixin .Unique ;
15+ import org .spongepowered .asm .mixin .injection .At ;
16+ import org .spongepowered .asm .mixin .injection .Inject ;
17+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
18+ import team .steelcode .awakenings .Awakenings ;
19+ import team .steelcode .awakenings .data .ModAttributes ;
20+
21+ import java .util .Set ;
22+
23+ //Credits to Startraveler on Discord!
24+ @ Mixin (GameRenderer .class )
25+ public class GameRendererAddPostShadersMixin {
26+
27+ @ Shadow
28+ @ Final
29+ private static ResourceLocation BLUR_POST_CHAIN_ID ;
30+ @ Final
31+ @ Shadow
32+ private Minecraft minecraft ;
33+ @ Final
34+ @ Shadow
35+ private CrossFrameResourcePool resourcePool ;
36+
37+ @ Inject (method = "render" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/renderer/LevelRenderer;doEntityOutline()V" , shift = At .Shift .AFTER ))
38+ private void verdant$addColorblindFilter (DeltaTracker deltaTracker , boolean renderLevel , CallbackInfo ci ) {
39+ Player player = this .minecraft .player ;
40+ // Make sure there is actually a player. (This should never fail, but it's good to be safe I guess).
41+ if (player != null ) {
42+ // Check if the player has the colorblind effect. Do other checks here as needed.
43+
44+ double breaths = player .getAttribute (ModAttributes .BREATHS ).getBaseValue ();
45+
46+ if (breaths <= 0 ) {
47+ ResourceLocation RL = ResourceLocation .fromNamespaceAndPath (
48+ Awakenings .MODID , "without_elevation" );
49+
50+ // If the player has the colorblind effect, get the post shader.
51+
52+ PostChain postchain = this .minecraft .getShaderManager ()
53+ .getPostChain (RL , LevelTargetBundle .MAIN_TARGETS );
54+
55+ if (postchain != null ) {
56+ // If the post shader was found, then apply it. If not, we probably have bigger problems; don't bother doing anything.
57+ postchain .process (this .minecraft .getMainRenderTarget (), this .resourcePool );
58+ }
59+ } else if (breaths > 0 && breaths < 200 ) {
60+ ResourceLocation RL = ResourceLocation .fromNamespaceAndPath (
61+ Awakenings .MODID , "decolored_vision" );
62+ PostChain postchain = this .minecraft .getShaderManager ()
63+ .getPostChain (RL , LevelTargetBundle .MAIN_TARGETS );
64+
65+ if (postchain != null ) {
66+ // If the post shader was found, then apply it. If not, we probably have bigger problems; don't bother doing anything.
67+ postchain .process (this .minecraft .getMainRenderTarget (), this .resourcePool );
68+ }
69+ }
70+
71+
72+ }
73+ }
74+ }
0 commit comments