|
| 1 | +package fr.iamacat.optimizationsandtweaks.mixins.client.manametal; |
| 2 | + |
| 3 | +import cpw.mods.fml.common.eventhandler.SubscribeEvent; |
| 4 | +import net.minecraft.entity.EntityLivingBase; |
| 5 | +import net.minecraft.util.MathHelper; |
| 6 | +import net.minecraft.world.World; |
| 7 | +import net.minecraft.world.biome.BiomeGenBase; |
| 8 | +import net.minecraftforge.client.event.EntityViewRenderEvent; |
| 9 | + |
| 10 | +import org.lwjgl.opengl.GL11; |
| 11 | +import org.spongepowered.asm.mixin.Mixin; |
| 12 | +import org.spongepowered.asm.mixin.Overwrite; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import project.studio.manametalmod.core.IBiomeFogM3; |
| 16 | +import project.studio.manametalmod.event.EventFog; |
| 17 | + |
| 18 | +@Mixin(EventFog.class) |
| 19 | +public class MixinEventFog { |
| 20 | + @Shadow private static double fogX; |
| 21 | + @Shadow private static double fogZ; |
| 22 | + @Shadow private static boolean fogInit; |
| 23 | + @Shadow private static float fogFarPlaneDistance; |
| 24 | + @Unique |
| 25 | + private BiomeGenBase[][] biomeCache = new BiomeGenBase[41][41]; |
| 26 | + |
| 27 | + @SubscribeEvent |
| 28 | + @Overwrite(remap = false) |
| 29 | + public void onRenderFog(EntityViewRenderEvent.RenderFogEvent event) { |
| 30 | + EntityLivingBase entity = event.entity; |
| 31 | + World world = entity.worldObj; |
| 32 | + int playerX = MathHelper.floor_double(entity.posX); |
| 33 | + int playerY = MathHelper.floor_double(entity.posY); |
| 34 | + int playerZ = MathHelper.floor_double(entity.posZ); |
| 35 | + |
| 36 | + if ((double)playerX == fogX && (double)playerZ == fogZ && fogInit) { |
| 37 | + 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; |
| 43 | + |
| 44 | + for (int x = -distance; x <= distance; ++x) { |
| 45 | + for (int z = -distance; z <= distance; ++z) { |
| 46 | + |
| 47 | + int cacheX = x + distance; |
| 48 | + int cacheZ = z + distance; |
| 49 | + |
| 50 | + BiomeGenBase biome = biomeCache[cacheX][cacheZ]; |
| 51 | + if (biome == null) { |
| 52 | + biome = world.getBiomeGenForCoords(playerX + x, playerZ + z); |
| 53 | + biomeCache[cacheX][cacheZ] = biome; |
| 54 | + } |
| 55 | + |
| 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 | + |
| 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 | + } |
| 79 | + |
| 80 | + fpDistanceBiomeFog += distancePart; |
| 81 | + weightBiomeFog += weightPart; |
| 82 | + } else { |
| 83 | + biomeCache[cacheX][cacheZ] = null; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 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); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + @Shadow |
| 102 | + private static void renderFog(int fogMode, float farPlaneDistance, float farPlaneDistanceScale) { |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments