diff --git a/src/main/java/com/fuzs/aquaacrobatics/client/handler/FogHandler.java b/src/main/java/com/fuzs/aquaacrobatics/client/handler/FogHandler.java index f1ef8a9..a0aa96b 100644 --- a/src/main/java/com/fuzs/aquaacrobatics/client/handler/FogHandler.java +++ b/src/main/java/com/fuzs/aquaacrobatics/client/handler/FogHandler.java @@ -5,6 +5,7 @@ import com.fuzs.aquaacrobatics.entity.player.IPlayerResizeable; import com.fuzs.aquaacrobatics.proxy.CommonProxy; import com.fuzs.aquaacrobatics.util.math.MathHelperNew; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.MobEffects; @@ -71,6 +72,17 @@ public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @N @SubscribeEvent public void onRenderFogDensity(EntityViewRenderEvent.FogDensity event) { + switch (ConfigHandler.BlocksConfig.waterFogMode) { + case AA_EXP2: + handleExp2Fog(event); + break; + case VANILLA_LINEAR: + handleLinearFog(event); + break; + } + } + + private void handleExp2Fog(EntityViewRenderEvent.FogDensity event) { Entity eventEntity = event.getEntity(); if(eventEntity instanceof EntityLivingBase && ((EntityLivingBase)eventEntity).isPotionActive(MobEffects.BLINDNESS)) return; @@ -91,6 +103,39 @@ public void onRenderFogDensity(EntityViewRenderEvent.FogDensity event) { } } + // Based on Minecraft 1.21.7 + static final float FOG_END = 96.0F; + static final float FOG_START = -8.0F; + private void handleLinearFog(EntityViewRenderEvent.FogDensity event) { + Entity eventEntity = event.getEntity(); + if (eventEntity instanceof EntityLivingBase && ((EntityLivingBase) eventEntity).isPotionActive(MobEffects.BLINDNESS)) { + return; + } + + if (event.getState().getMaterial() == Material.WATER && !shouldSkipFogOverride(eventEntity.getEntityWorld())) { + GlStateManager.setFog(GlStateManager.FogMode.LINEAR); + + float renderDistanceInBlocks = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16.0f; + float fogEnd = Math.min(renderDistanceInBlocks, FOG_END); + + if (eventEntity instanceof EntityPlayer) { + EntityPlayer playerEntity = (EntityPlayer) eventEntity; + float waterVision = ((IPlayerResizeable) playerEntity).getWaterVision(); + fogEnd *= Math.max(0.25F, waterVision); + Biome biome = playerEntity.world.getBiome(playerEntity.getPosition()); + if (BiomeDictionary.hasType(biome, BiomeDictionary.Type.SWAMP)) { + fogEnd *= 0.85F; + } + } + + GlStateManager.setFogStart(FOG_START); + GlStateManager.setFogEnd(fogEnd); + event.setCanceled(true); + } + } + + + /* LOW to override mods like Biomes O' Plenty which force their own underwater fog color */ @SubscribeEvent(priority = EventPriority.LOW) public void onRenderFogColor(EntityViewRenderEvent.FogColors event) { @@ -135,7 +180,7 @@ public void onRenderFogColor(EntityViewRenderEvent.FogColors event) { if (playerEntity.isPotionActive(MobEffects.BLINDNESS)) { int potionDuration = playerEntity.getActivePotionEffect(MobEffects.BLINDNESS).getDuration(); if (potionDuration < 20) { - blindnessFactor *= (1.0F - (float)i / 20.0F); + blindnessFactor *= (1.0F - (float)potionDuration / 20.0F); } else { blindnessFactor = 0.0D; } diff --git a/src/main/java/com/fuzs/aquaacrobatics/config/ConfigHandler.java b/src/main/java/com/fuzs/aquaacrobatics/config/ConfigHandler.java index a87ae6e..6e1254b 100644 --- a/src/main/java/com/fuzs/aquaacrobatics/config/ConfigHandler.java +++ b/src/main/java/com/fuzs/aquaacrobatics/config/ConfigHandler.java @@ -89,6 +89,10 @@ public static class BlocksConfig { @Config.Name("New Water Fog") @Config.Comment("Use the new fog rendering in 1.13+.") public static boolean newWaterFog = true; + + @Config.Name("New Water Fog Render Mode") + @Config.Comment("Water fog render mode, available options: AA_EXP2, VANILLA_LINEAR") + public static WaterFogMode waterFogMode = WaterFogMode.AA_EXP2; } public static class MiscellaneousConfig { @@ -205,4 +209,8 @@ public enum PlayerBlockCollisions { STANDARD, APPROXIMATE, EXACT } + public enum WaterFogMode { + AA_EXP2, VANILLA_LINEAR + } + } \ No newline at end of file diff --git a/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsCore.java b/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsCore.java index f28bdc1..63a54c2 100644 --- a/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsCore.java +++ b/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsCore.java @@ -2,7 +2,6 @@ import com.fuzs.aquaacrobatics.AquaAcrobatics; import com.fuzs.aquaacrobatics.client.handler.NoMixinHandler; -import net.minecraft.launchwrapper.Launch; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.FMLCommonHandler; @@ -38,13 +37,15 @@ public class AquaAcrobaticsCore implements IFMLLoadingPlugin { private static boolean isScreenRegistered; /* Config options */ - public static boolean disableBlockUpdateMixins; + public static boolean disableBlockUpdateMixins; + public static boolean enableSkyBoxHeightOverwrite; public AquaAcrobaticsCore() { SELF = this; Configuration config = new Configuration(new File("config", "aquaacrobatics_core.cfg")); config.load(); disableBlockUpdateMixins = config.getBoolean("DisableBlockUpdateMixins", "hacks", false, "TickCentral has a buggy ASM transformer - this will disable these mixins from being applied. Make sure bubble columns are disabled if you use this."); + enableSkyBoxHeightOverwrite = config.getBoolean("EnableSkyBoxHeightOverwrite", "hacks", false, "Enable overwriting skybox renderer height, vanilla one may cause weird black edges near the chunk border."); config.save(); isFgDev = "true".equals(System.getProperty("aquaacrobatics.fghack")); diff --git a/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsMixinPlugin.java b/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsMixinPlugin.java index 67f9c2e..0622d02 100644 --- a/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsMixinPlugin.java +++ b/src/main/java/com/fuzs/aquaacrobatics/core/AquaAcrobaticsMixinPlugin.java @@ -36,6 +36,14 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { } } + if (mixinClassName.equals("com.fuzs.aquaacrobatics.core.mixin.client.RenderGlobalMixin")) { + if (!AquaAcrobaticsCore.enableSkyBoxHeightOverwrite) { + return false; + } + AquaAcrobaticsCore.LOGGER.error("Overwriting vanilla skybox height as requested in config."); + return true; + } + if(mixinClassName.equals("com.fuzs.aquaacrobatics.core.mixin.client.BlockAliasesBubbleColumnMixin")) { return doesClassExist("optifine.OptiFineForgeTweaker"); } diff --git a/src/main/java/com/fuzs/aquaacrobatics/core/mixin/client/RenderGlobalMixin.java b/src/main/java/com/fuzs/aquaacrobatics/core/mixin/client/RenderGlobalMixin.java new file mode 100644 index 0000000..ac38561 --- /dev/null +++ b/src/main/java/com/fuzs/aquaacrobatics/core/mixin/client/RenderGlobalMixin.java @@ -0,0 +1,21 @@ +package com.fuzs.aquaacrobatics.core.mixin.client; + +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.RenderGlobal; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(RenderGlobal.class) +public abstract class RenderGlobalMixin { + @Redirect( + method = "renderSky(FI)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/multiplayer/WorldClient;getHorizon()D" + ) + ) + public double getHorizon(WorldClient instance) { + return 0.0D; + } +} diff --git a/src/main/resources/META-INF/mixins.aquaacrobatics.json b/src/main/resources/META-INF/mixins.aquaacrobatics.json index d8857ea..57527f1 100644 --- a/src/main/resources/META-INF/mixins.aquaacrobatics.json +++ b/src/main/resources/META-INF/mixins.aquaacrobatics.json @@ -33,6 +33,7 @@ "client.ModelBipedMixin", "client.ModelFluidMixin", "client.RenderBoatMixin", + "client.RenderGlobalMixin", "client.RenderPlayerMixin", "client.PlayerControllerMPMixin" ],