Skip to content

Commit

Permalink
Thlassophobia fog exists
Browse files Browse the repository at this point in the history
Added:
- Thlassophobia fog
  • Loading branch information
dragonflame86 committed Dec 4, 2023
1 parent a52cf0c commit 8e6eade
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.hybridlabs.aquatic.fog;

import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.util.math.MathHelper;

public class ThalassophobiaFogModifier implements BackgroundRenderer.StatusEffectFogModifier {
@Override
public StatusEffect getStatusEffect() {
return HybridAquaticStatusEffects.INSTANCE.getTHALASSOPHOBIA();
}

@Override
public void applyStartEndModifier(BackgroundRenderer.FogData fogData, LivingEntity entity, StatusEffectInstance effect, float viewDistance, float tickDelta) {
float f = effect.isInfinite() ? 5.0F : MathHelper.lerp(Math.min(1.0F, (float)effect.getDuration() / 20.0F), viewDistance, 5.0F);
if (fogData.fogType == BackgroundRenderer.FogType.FOG_SKY) {
fogData.fogStart = 0.0F;
fogData.fogEnd = f * 0.8F;
} else {
fogData.fogStart = f * 0.25F;
fogData.fogEnd = f;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
package dev.hybridlabs.aquatic.mixin.client;

import com.google.common.collect.Lists;
import dev.hybridlabs.aquatic.fog.ThalassophobiaFogModifier;
import dev.hybridlabs.aquatic.utils.MeasurementUtils;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.BackgroundRenderer.BlindnessFogModifier;
import net.minecraft.client.render.BackgroundRenderer.DarknessFogModifier;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.CameraSubmersionType;
import net.minecraft.client.render.FogShape;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.List;

@Mixin(BackgroundRenderer.class)
public class BackgroundRendererMixin {

@Shadow private static float red, green, blue;
@Mutable @Final @Shadow private static List<BackgroundRenderer.StatusEffectFogModifier> FOG_MODIFIERS;

@Inject(method = "<clinit>", at = @At("TAIL"))
private static void hybrid$initInject(CallbackInfo ci) {
List<BackgroundRenderer.StatusEffectFogModifier> tempList = FOG_MODIFIERS;
tempList.add(new ThalassophobiaFogModifier());
FOG_MODIFIERS = tempList;
System.out.println(FOG_MODIFIERS);
}

// @Inject(method = "render", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clearColor(FFFF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
// private static void hybrid$fogColor(Camera camera, float tickDelta, ClientWorld world, int viewDistance, float skyDarkness, CallbackInfo ci, CameraSubmersionType cameraSubmersionType, Entity entity) {
Expand Down Expand Up @@ -68,41 +85,36 @@ public class BackgroundRendererMixin {
if (entity instanceof ClientPlayerEntity clientPlayerEntity) {
World world = clientPlayerEntity.getWorld();

if (clientPlayerEntity.hasStatusEffect(HybridAquaticStatusEffects.THALASSOPHOBIA)) {
fogData.fogStart = 0.0F;
fogData.fogEnd = 32.0F;
fogData.fogShape = FogShape.SPHERE;
} else {
switch (cameraSubmersionType) {
case LAVA, POWDER_SNOW -> {
switch (cameraSubmersionType) {
case LAVA, POWDER_SNOW -> {
}
case WATER -> {
fogData.fogStart = -8.0F;
int topY = world.getSeaLevel();
float fogStep = (float) (topY - camera.getPos().y) / 32.0f;
fogData.fogEnd = MathHelper.lerp(fogStep, 80.0f, 12.0f);
fogData.fogEnd *= Math.max(0.25F, clientPlayerEntity.getUnderwaterVisibility());
RegistryEntry<Biome> registryEntry = world.getBiome(clientPlayerEntity.getBlockPos());
if (registryEntry.isIn(BiomeTags.HAS_CLOSER_WATER_FOG)) {
fogData.fogEnd *= 1.0F;
}
case WATER -> {
fogData.fogStart = -8.0F;
int topY = world.getSeaLevel();
float fogStep = (float) (topY - camera.getPos().y) / 32.0f;
fogData.fogEnd = MathHelper.lerp(fogStep, 80.0f, 12.0f);
fogData.fogEnd *= Math.max(0.25F, clientPlayerEntity.getUnderwaterVisibility());
RegistryEntry<Biome> registryEntry = world.getBiome(clientPlayerEntity.getBlockPos());
if (registryEntry.isIn(BiomeTags.HAS_CLOSER_WATER_FOG)) {
fogData.fogEnd *= 1.0F;
}

if (fogData.fogEnd > viewDistance) {
fogData.fogEnd = viewDistance;
fogData.fogShape = FogShape.SPHERE;
}
fogData.fogEnd = Math.max(fogData.fogEnd, 12.0f);
if (fogData.fogEnd > viewDistance) {
fogData.fogEnd = viewDistance;
fogData.fogShape = FogShape.SPHERE;
}
case NONE -> {
RegistryEntry<Biome> biomeEntry = world.getBiome(entity.getBlockPos());
fogData.fogEnd = Math.max(fogData.fogEnd, 12.0f);
}
case NONE -> {
RegistryEntry<Biome> biomeEntry = world.getBiome(entity.getBlockPos());

if (biomeEntry.isIn(BiomeTags.IS_OCEAN) && (world.isRaining() || world.isNight())) {
fogData.fogStart = -0.8f;
fogData.fogEnd = MeasurementUtils.Block(16);
}
if (biomeEntry.isIn(BiomeTags.IS_OCEAN) && (world.isRaining() || world.isNight())) {
fogData.fogStart = -0.8f;
fogData.fogEnd = MeasurementUtils.Block(16);
}
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.hybridlabs.aquatic.effect

import net.minecraft.entity.LivingEntity
import net.minecraft.entity.effect.StatusEffect
import net.minecraft.entity.effect.StatusEffectCategory
import net.minecraft.entity.effect.StatusEffectInstance

class Thalassophobia : StatusEffect(StatusEffectCategory.HARMFUL, 0x000000) {
}
3 changes: 3 additions & 0 deletions src/main/resources/hybrid-aquatic.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ accessible method net/minecraft/block/BlockWithEntity checkType (Lnet/minecraft/
accessible field net/minecraft/block/entity/BlockEntityType blocks Ljava/util/Set;
mutable field net/minecraft/block/entity/BlockEntityType blocks Ljava/util/Set;
accessible class net/minecraft/client/render/BackgroundRenderer$FogData
accessible class net/minecraft/client/render/BackgroundRenderer$StatusEffectFogModifier
accessible class net/minecraft/client/render/BackgroundRenderer$BlindnessFogModifier
accessible class net/minecraft/client/render/BackgroundRenderer$DarknessFogModifier

0 comments on commit 8e6eade

Please sign in to comment.