From 66119b059c2dd0dc998e01e2bd77f81959a7e548 Mon Sep 17 00:00:00 2001 From: dragoncommands <35853220+dragonflame86@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:59:55 -0500 Subject: [PATCH] MeasurementUtils Added: - method to assist in measurement of distance render-side - added function to determine gradient for height relative to sea level. --- .../mixin/client/BackgroundRendererMixin.java | 56 +++++++++++-------- .../aquatic/utils/MeasurementUtils.java | 13 +++++ 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 src/main/java/dev/hybridlabs/aquatic/utils/MeasurementUtils.java diff --git a/src/client/java/dev/hybridlabs/aquatic/mixin/client/BackgroundRendererMixin.java b/src/client/java/dev/hybridlabs/aquatic/mixin/client/BackgroundRendererMixin.java index 792a131dc..a1ef11b2f 100644 --- a/src/client/java/dev/hybridlabs/aquatic/mixin/client/BackgroundRendererMixin.java +++ b/src/client/java/dev/hybridlabs/aquatic/mixin/client/BackgroundRendererMixin.java @@ -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; @@ -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 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 biomeEntry = world.getBiome(entity.getBlockPos()); + RegistryEntry 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; + } } diff --git a/src/main/java/dev/hybridlabs/aquatic/utils/MeasurementUtils.java b/src/main/java/dev/hybridlabs/aquatic/utils/MeasurementUtils.java new file mode 100644 index 000000000..ff78094e5 --- /dev/null +++ b/src/main/java/dev/hybridlabs/aquatic/utils/MeasurementUtils.java @@ -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; + } +}