1616import project .studio .manametalmod .event .EventFog ;
1717
1818@ Mixin (EventFog .class )
19- public class MixinEventFog {
19+ public abstract class MixinEventFog {
2020 @ Shadow private static double fogX ;
2121 @ Shadow private static double fogZ ;
2222 @ Shadow private static boolean fogInit ;
2323 @ Shadow private static float fogFarPlaneDistance ;
24+
2425 @ Unique
25- private BiomeGenBase [][] biomeCache = new BiomeGenBase [41 ][41 ];
26+ private final BiomeGenBase [][] biomeCache = new BiomeGenBase [41 ][41 ];
27+
28+ @ Unique
29+ private int cacheOriginX = Integer .MAX_VALUE ;
30+ @ Unique
31+ private int cacheOriginZ = Integer .MAX_VALUE ;
2632
2733 @ SubscribeEvent
2834 @ Overwrite (remap = false )
@@ -35,71 +41,82 @@ public void onRenderFog(EntityViewRenderEvent.RenderFogEvent event) {
3541
3642 if ((double )playerX == fogX && (double )playerZ == fogZ && fogInit ) {
3743 renderFog (event .fogMode , fogFarPlaneDistance , 0.75F );
38- } else {
39- fogInit = true ;
40- int distance = 20 ;
41- float fpDistanceBiomeFog = 0.0F ;
42- float weightBiomeFog = 0.0F ;
44+ return ;
45+ }
46+
47+ final int distance = 20 ;
48+ boolean isCacheInvalid = playerX != cacheOriginX || playerZ != cacheOriginZ ;
4349
50+ if (isCacheInvalid ) {
51+ cacheOriginX = playerX ;
52+ cacheOriginZ = playerZ ;
53+
4454 for (int x = -distance ; x <= distance ; ++x ) {
4555 for (int z = -distance ; z <= distance ; ++z ) {
46-
4756 int cacheX = x + distance ;
4857 int cacheZ = z + distance ;
58+
59+ BiomeGenBase biome = world .getBiomeGenForCoords (playerX + x , playerZ + z );
60+ biomeCache [cacheX ][cacheZ ] = biome ;
61+ }
62+ }
63+ }
4964
50- BiomeGenBase biome = biomeCache [cacheX ][cacheZ ];
51- if (biome == null ) {
52- biome = world .getBiomeGenForCoords (playerX + x , playerZ + z );
53- biomeCache [cacheX ][cacheZ ] = biome ;
54- }
65+ fogInit = true ;
66+ float fpDistanceBiomeFog = 0.0F ;
67+ float weightBiomeFog = 0.0F ;
5568
56- if (biome instanceof IBiomeFogM3 ) {
57- float distancePart = ((IBiomeFogM3 )biome ).getFogDensity (playerX + x , playerY , playerZ + z );
58- float weightPart = 1.0F ;
59-
60- if (x == -distance ) {
61- double xDiff = (double )1.0F - (entity .posX - (double )playerX );
62- distancePart = (float )((double )distancePart * xDiff );
63- weightPart = (float )((double )weightPart * xDiff );
64- } else if (x == distance ) {
65- double xDiff = entity .posX - (double )playerX ;
66- distancePart = (float )((double )distancePart * xDiff );
67- weightPart = (float )((double )weightPart * xDiff );
68- }
69+ for (int x = -distance ; x <= distance ; ++x ) {
70+ for (int z = -distance ; z <= distance ; ++z ) {
71+ int cacheX = x + distance ;
72+ int cacheZ = z + distance ;
6973
70- if (z == -distance ) {
71- double zDiff = (double )1.0F - (entity .posZ - (double )playerZ );
72- distancePart = (float )((double )distancePart * zDiff );
73- weightPart = (float )((double )weightPart * zDiff );
74- } else if (z == distance ) {
75- double zDiff = entity .posZ - (double )playerZ ;
76- distancePart = (float )((double )distancePart * zDiff );
77- weightPart = (float )((double )weightPart * zDiff );
78- }
74+ BiomeGenBase biome = biomeCache [cacheX ][cacheZ ];
7975
80- fpDistanceBiomeFog += distancePart ;
81- weightBiomeFog += weightPart ;
82- } else {
83- biomeCache [cacheX ][cacheZ ] = null ;
76+ if (biome instanceof IBiomeFogM3 ) {
77+ float distancePart = ((IBiomeFogM3 )biome ).getFogDensity (playerX + x , playerY , playerZ + z );
78+ float weightPart = 1.0F ;
79+
80+ if (x == -distance ) {
81+ double xDiff = (double )1.0F - (entity .posX - (double )playerX );
82+ distancePart = (float )((double )distancePart * xDiff );
83+ weightPart = (float )((double )weightPart * xDiff );
84+ } else if (x == distance ) {
85+ double xDiff = entity .posX - (double )playerX ;
86+ distancePart = (float )((double )distancePart * xDiff );
87+ weightPart = (float )((double )weightPart * xDiff );
8488 }
85- }
86- }
8789
88- float weightMixed = (float )(distance * 2 * distance * 2 );
89- float weightDefault = weightMixed - weightBiomeFog ;
90- float fpDistanceBiomeFogAvg = weightBiomeFog == 0.0F ? 0.0F : fpDistanceBiomeFog / weightBiomeFog ;
91- float farPlaneDistance = (fpDistanceBiomeFog * 240.0F + event .farPlaneDistance * weightDefault ) / weightMixed ;
92- float farPlaneDistanceScaleBiome = 0.1F * (1.0F - fpDistanceBiomeFogAvg ) + 0.75F * fpDistanceBiomeFogAvg ;
93- float farPlaneDistanceScale = (farPlaneDistanceScaleBiome * weightBiomeFog + 0.75F * weightDefault ) / weightMixed ;
94- fogX = entity .posX ;
95- fogZ = entity .posZ ;
96- fogFarPlaneDistance = Math .min (farPlaneDistance , event .farPlaneDistance );
97- renderFog (event .fogMode , fogFarPlaneDistance , farPlaneDistanceScale );
90+ if (z == -distance ) {
91+ double zDiff = (double )1.0F - (entity .posZ - (double )playerZ );
92+ distancePart = (float )((double )distancePart * zDiff );
93+ weightPart = (float )((double )weightPart * zDiff );
94+ } else if (z == distance ) {
95+ double zDiff = entity .posZ - (double )playerZ ;
96+ distancePart = (float )((double )distancePart * zDiff );
97+ weightPart = (float )((double )weightPart * zDiff );
98+ }
99+
100+ fpDistanceBiomeFog += distancePart ;
101+ weightBiomeFog += weightPart ;
102+ }
103+ }
98104 }
105+
106+ float weightMixed = (float )(distance * 2 * distance * 2 );
107+ float weightDefault = weightMixed - weightBiomeFog ;
108+ float fpDistanceBiomeFogAvg = weightBiomeFog == 0.0F ? 0.0F : fpDistanceBiomeFog / weightBiomeFog ;
109+ float farPlaneDistance = (fpDistanceBiomeFog * 240.0F + event .farPlaneDistance * weightDefault ) / weightMixed ;
110+ float farPlaneDistanceScaleBiome = 0.1F * (1.0F - fpDistanceBiomeFogAvg ) + 0.75F * fpDistanceBiomeFogAvg ;
111+ float farPlaneDistanceScale = (farPlaneDistanceScaleBiome * weightBiomeFog + 0.75F * weightDefault ) / weightMixed ;
112+
113+ fogX = entity .posX ;
114+ fogZ = entity .posZ ;
115+ fogFarPlaneDistance = Math .min (farPlaneDistance , event .farPlaneDistance );
116+
117+ renderFog (event .fogMode , fogFarPlaneDistance , farPlaneDistanceScale );
99118 }
100119
101120 @ Shadow
102- private static void renderFog (int fogMode , float farPlaneDistance , float farPlaneDistanceScale ) {
103- }
104-
105- }
121+ private static void renderFog (int fogMode , float farPlaneDistance , float farPlaneDistanceScale ) {}
122+ }
0 commit comments