Skip to content

Commit

Permalink
MeasurementUtils
Browse files Browse the repository at this point in the history
Added:
- method to assist in measurement of distance render-side
- added function to determine gradient for height relative to sea level.
  • Loading branch information
dragonflame86 committed Dec 1, 2023
1 parent c9673e9 commit 66119b0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
Expand Down Expand Up @@ -69,44 +70,55 @@ public class BackgroundRendererMixin {
@Inject(method = "applyFog", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderFogStart(F)V"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void hybrid$renderFog(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, float tickDelta, CallbackInfo ci, CameraSubmersionType cameraSubmersionType, Entity entity, BackgroundRenderer.FogData fogData) {

World world = entity.getWorld();
if (entity instanceof ClientPlayerEntity clientPlayerEntity) {

World world = clientPlayerEntity.getWorld();

switch (cameraSubmersionType) {
switch (cameraSubmersionType) {

case LAVA, POWDER_SNOW -> {
// Empty cause no real need.
}
case WATER -> {
fogData.fogStart = -8.0F;
case LAVA, POWDER_SNOW -> {
// Empty cause no real need.
}
case WATER -> {
fogData.fogStart = -8.0F;

int topY = world.getSeaLevel();
float fogStep = (float) (topY - camera.getPos().y) / 32.0f; // as usual modify this end variable for when water fog should reach maximum darkness
// arg after start is the default fog starting point
// arg after that one is where the fog ends distance wise
fogData.fogEnd = MathHelper.lerp(fogStep, 80.0f, 12.0f);
if (entity instanceof ClientPlayerEntity clientPlayerEntity) {
int topY = world.getSeaLevel();
float fogStep = (float) (topY - camera.getPos().y) / 32.0f; // as usual modify this end variable for when water fog should reach maximum darkness
// arg after start is the default fog starting point
// arg after that one is where the fog ends distance wise
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.CYLINDER;
if (fogData.fogEnd > viewDistance) {
fogData.fogEnd = viewDistance;
fogData.fogShape = FogShape.CYLINDER;
}
fogData.fogEnd = Math.max(fogData.fogEnd, 12.0f);
}
fogData.fogEnd = Math.max(fogData.fogEnd, 12.0f);
}
case NONE -> {
case NONE -> {

RegistryEntry<Biome> biomeEntry = world.getBiome(entity.getBlockPos());
RegistryEntry<Biome> biomeEntry = world.getBiome(entity.getBlockPos());

if(entity instanceof ClientPlayerEntity player && biomeEntry.isIn(BiomeTags.IS_OCEAN)) {
if (biomeEntry.isIn(BiomeTags.IS_OCEAN)) {

}
}
}
}
}

/**
*
* @param height
* @param gradientBegin
* @param gradientEnd
* @return
*/
@Unique private float getSeaLevelGradient(float height, float gradientBegin, float gradientEnd) {
return 1.0f;
}
}
13 changes: 13 additions & 0 deletions src/main/java/dev/hybridlabs/aquatic/utils/MeasurementUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.hybridlabs.aquatic.utils;

public class MeasurementUtils {

/**
* Gets blocks in render-distance scale of measurement
* @param distance the distance you want.
* @return distances * 4 which turns into real-world block measurements
*/
public static float Block(float distance) {
return distance * 4;
}
}

0 comments on commit 66119b0

Please sign in to comment.