Skip to content

Commit

Permalink
1.21 -> 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Nov 14, 2024
1 parent 68fb32e commit 31ef675
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 161 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ reckon {
}

repositories {
mavenLocal()
maven { name 'modmenu'; url 'https://maven.terraformersmc.com/releases' }
maven { name 'minelp'; url 'https://repo.minelittlepony-mod.com/maven/snapshot' }
maven { name 'minelp-release'; url 'https://repo.minelittlepony-mod.com/maven/release' }
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.4
fabric_version=0.102.0+1.21.1
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
fabric_version=0.106.1+1.21.3

# Mod Properties
group=com.tamaized
Expand All @@ -15,10 +15,10 @@ org.gradle.daemon=false
description=Brings back the old Void Fog

# Publishing
minecraft_version_range=>=1.21
minecraft_version_range=>=1.21.3
modrinth_loader_type=fabric
modrinth_project_id=JRC9aXm9

# Dependencies
modmenu_version=11.0.0-beta.1
kirin_version=1.19.2+1.21
modmenu_version=12.0.0-beta.1
kirin_version=1.19.3+1.21.3
6 changes: 3 additions & 3 deletions src/main/java/com/tamaized/voidfog/FogColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class FogColor {
private double brightness;

public double getFogBrightness(ClientWorld world, Entity entity, float delta) {
public float getFogBrightness(ClientWorld world, Entity entity, float delta) {
if (entity.hasVehicle()) {
entity = entity.getRootVehicle();
}
Expand All @@ -24,12 +24,12 @@ public double getFogBrightness(ClientWorld world, Entity entity, float delta) {

double prevBrightness = brightness;
brightness = computeBrightness(world, entity, delta);
return MathHelper.lerp(delta / (brightness > prevBrightness ? 10 : 2), prevBrightness, brightness);
return (float)MathHelper.lerp(delta / (brightness > prevBrightness ? 10 : 2), prevBrightness, brightness);
}

private double computeBrightness(ClientWorld world, Entity entity, float delta) {

if (!VoidFog.config.enabled) {
if (!VoidFog.config.enabled.get()) {
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tamaized/voidfog/FogParticleSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ private BlockPos randomPos(Random rand) {

public void update(World world, Entity entity, Voidable dimension) {

int maxParticleHeight = VoidFog.config.maxFogHeight - PARTICLE_INSET_HEIGHT;
int maxParticleHeight = VoidFog.config.maxFogHeight.get() - PARTICLE_INSET_HEIGHT;

if (FogRenderer.getAltitude(dimension, world, entity) > maxParticleHeight) {
return;
}

int particleCount = (int)(VoidFog.config.voidParticleDensity * (1 - FogRenderer.getFogBlendingDelta(entity)));
int particleCount = (int)(VoidFog.config.voidParticleDensity.get() * (1 - FogRenderer.getFogBlendingDelta(entity)));
int difficultyMultiplier = (int)(8 * FogRenderer.getDifficultyMultiplier(world));
Random rand = world.getRandom();

Expand Down
41 changes: 23 additions & 18 deletions src/main/java/com/tamaized/voidfog/FogRenderer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.tamaized.voidfog;

import com.mojang.blaze3d.systems.RenderSystem;
import com.tamaized.voidfog.api.Voidable;

import net.minecraft.block.enums.CameraSubmersionType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Fog;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.render.BackgroundRenderer.FogType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -20,68 +21,72 @@ public class FogRenderer {

private float lastFogDistance = 1000;

public void render(Camera camera, FogType type, float viewDistance, boolean thickFog, float delta) {
public Fog render(Fog fog, Camera camera, FogType type, float viewDistance, boolean thickFog, float tickDelta) {

if (!canRenderDepthFog(camera)) {
return;
return fog;
}

Entity entity = camera.getFocusedEntity();
World world = entity.getEntityWorld();
Voidable voidable = Voidable.of(world);

if (!voidable.hasDepthFog(entity, world)) {
return;
return fog;
}

float distance = getFogDistance(world, entity);

if (entity instanceof LivingEntity l && l.hasStatusEffect(StatusEffects.NIGHT_VISION)) {
distance *= 4 * GameRenderer.getNightVisionStrength(l, delta);
distance *= 4 * GameRenderer.getNightVisionStrength(l, tickDelta);
}

distance = MathHelper.lerp(delta / (distance > lastFogDistance ? 20 : 10), lastFogDistance, distance);
distance = MathHelper.lerp(tickDelta / (distance > lastFogDistance ? 20 : 10), lastFogDistance, distance);
lastFogDistance = distance;

float blendDelta = getFogBlendingDelta(entity);
float density = MathHelper.clamp(VoidFog.config.fogDensity / 100F, 0, 1);
float density = MathHelper.clamp(VoidFog.config.fogDensity.get() / 100F, 0, 1);

RenderSystem.setShaderFogStart(MathHelper.lerp(blendDelta, getFogStart(distance, density, type, world, thickFog), RenderSystem.getShaderFogStart()));
RenderSystem.setShaderFogEnd(MathHelper.lerp(blendDelta, getFogEnd(distance, density, type, world, thickFog), RenderSystem.getShaderFogEnd()));
float darkenAmount = VoidFog.FOG_COLOR.getFogBrightness((ClientWorld)world, camera.getFocusedEntity(), tickDelta);

float start = MathHelper.lerp(blendDelta, getFogStart(distance, density, type, world, thickFog), fog.start());
float end = MathHelper.lerp(blendDelta, getFogEnd(distance, density, type, world, thickFog), fog.end());

return new Fog(start, end, fog.shape(), fog.red() * darkenAmount, fog.green() * darkenAmount, fog.blue() * darkenAmount, fog.alpha());
}

private boolean canRenderDepthFog(Camera camera) {
return VoidFog.config.enabled
return VoidFog.config.enabled.get()
&& camera.getSubmersionType() == CameraSubmersionType.NONE
&& !(camera.getFocusedEntity() instanceof LivingEntity l && l.hasStatusEffect(StatusEffects.BLINDNESS));
}

public static float getFogBlendingDelta(Entity entity) {
if (VoidFog.config.prettyFog) {
if (VoidFog.config.prettyFog.get()) {
return 0;
}
float entityAltitude = (float)getAltitude(Voidable.of(entity.getWorld()), entity.getWorld(), entity);
float fogHeight = VoidFog.config.fadeStartOffset;
float maxFogAltitude = VoidFog.config.maxFogHeight - fogHeight;
return MathHelper.clamp((entityAltitude - maxFogAltitude) / fogHeight, 0, 1);
float fogTransitionDistance = Math.max(0, VoidFog.config.fogTransitionDistance.get());
float maxFogAltitude = VoidFog.config.maxFogHeight.get() - fogTransitionDistance;
return MathHelper.clamp((entityAltitude - maxFogAltitude) / fogTransitionDistance, 0, 1);
}

public static float getDifficultyMultiplier(World world) {
return (VoidFog.config.scaleWithDifficulty ? world.getDifficulty().getId() + 1 : 1);
return (VoidFog.config.scaleWithDifficulty.get() ? world.getDifficulty().getId() + 1 : 1);
}

public static int getLight(Entity entity) {
entity = getCorrectEntity(entity);
BlockPos pos = BlockPos.ofFloored(entity.getEyePos());
if (VoidFog.config.respectTorches) {
if (VoidFog.config.respectTorches.get()) {
return entity.getWorld().getLightLevel(pos);
}
return entity.getWorld().getLightLevel(LightType.SKY, pos);
}

public static double getAltitude(Voidable voidable, World world, Entity entity) {
entity = getCorrectEntity(entity);
return voidable.isVoidFogDisabled(entity, world) ? VoidFog.config.maxFogHeight + 1 : (entity.getY() - world.getBottomY());
return voidable.isVoidFogDisabled(entity, world) ? VoidFog.config.maxFogHeight.get() + 1 : (entity.getY() - world.getBottomY());
}

public static Entity getCorrectEntity(Entity entity) {
Expand All @@ -96,7 +101,7 @@ private float getFogDistance(World world, Entity entity) {

float viewDistance = MinecraftClient.getInstance().gameRenderer.getViewDistance();
double fogDistance = getLight(entity) / 16D
+ getAltitude(voidable, world, entity) / (VoidFog.config.maxFogHeight * getDifficultyMultiplier(world));
+ getAltitude(voidable, world, entity) / (VoidFog.config.maxFogHeight.get() * getDifficultyMultiplier(world));

if (fogDistance >= 1) {
return viewDistance;
Expand Down
121 changes: 42 additions & 79 deletions src/main/java/com/tamaized/voidfog/Settings.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
package com.tamaized.voidfog;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;

public class Settings {

private static final Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();

public boolean enabled = true;

public boolean scaleWithDifficulty = true;

public boolean disableInCreative = true;

public boolean respectTorches = true;

public boolean prettyFog = false;

public int voidParticleDensity = 1000;

public int fogDensity = 100;

public int maxFogHeight = 32;

public float fadeStartOffset = 15F; //additive to maxFogHeight, not an absolute height.

public boolean imABigBoi = false;

private transient Path path;
import com.minelittlepony.common.util.settings.Config;
import com.minelittlepony.common.util.settings.Setting;

public class Settings extends Config {
public final Setting<Boolean> enabled = value("enabled", true);
public final Setting<Boolean> scaleWithDifficulty = value("scaleWithDifficulty", true)
.addComment("Default: true")
.addComment("Makes fog start at shallower depths as difficulty increases");
public final Setting<Boolean> disableInCreative = value("disableInCreative", true)
.addComment("Default: true")
.addComment("Disables all void fog effects when in creative mode");
public final Setting<Boolean> respectTorches = value("respectTorches", true)
.addComment("Default: true")
.addComment("Fog will retreat from areas lit by torches and other light sources");
public final Setting<Boolean> prettyFog = value("prettyFog", false)
.addComment("Default: false")
.addComment("Enables an alternate method of rendering fog that gives softed edges that some may find more visually pleasing");
public final Setting<Integer> voidParticleDensity = value("voidParticleDensity", 1000)
.addComment("Default: 1000")
.addComment("The particle density when near the void");
public final Setting<Integer> fogDensity = value("fogDensity", 100)
.addComment("Default: 100")
.addComment("Min: 0, Max: 1")
.addComment("The percentage particle density not near the void. voidParticleDensity is MULTIPLIED by this value/100");
public final Setting<Integer> maxFogHeight = value("maxFogHeight", 32)
.addComment("Default: 32")
.addComment("Maximum height in blocks from the bottom of the world that fog will reach.")
.addComment("If scaleWithDifficulty is enabled, this value is MULTIPLIED by the current area's difficulty");
public final Setting<Float> fogTransitionDistance = value("maxFogHeight", 15F)
.addComment("Default: 15")
.addComment("Distance in blocks that you have to approach to the border defined by maxFogHeight for the game to start transitioning from regular to void fog");
public final Setting<Boolean> imABigBoi = value("imABigBoi", false)
.addComment("Default: false")
.addComment("Adds minimal jumpscares hanging around in dark areas for long amounts of time.");

protected Settings(Path path) {
super(HEIRARCHICAL_JSON_ADAPTER, path);
}

public float setParticleDensity(float density) {
density = density > 9997 ? 10000 : density < 3 ? 0 : density;
Expand All @@ -44,59 +47,19 @@ public float setParticleDensity(float density) {
density = 1000;
}

voidParticleDensity = (int)density;

return voidParticleDensity;
return voidParticleDensity.set(Math.max(0, (int)density));
}

public float setFogHeight(float height) {
maxFogHeight = (int)height;
return maxFogHeight;
return maxFogHeight.set((int)height);
}

public float setFogDensity(float density) {
density = density > 97 ? 100 : density < 3 ? 0 : density;
fogDensity = (int)density;
return fogDensity;
return fogDensity.set((int)density);
}

public float setFadeStart(float value) {
fadeStartOffset = value;
return maxFogHeight;
}

public static Settings load(Path path) {
if (Files.isReadable(path)) {
try (BufferedReader s = Files.newBufferedReader(path)) {
Settings result = gson.fromJson(s, Settings.class);

if (result != null) {
return result.save(path);
}
} catch (IOException | JsonParseException e) {
VoidFog.LOGGER.warn("Erorr whilst loading json config", e);
}
}
return new Settings().save(path);
}

protected void validate() {
voidParticleDensity = Math.max(0, voidParticleDensity);
fadeStartOffset = Math.max(0, fadeStartOffset);
}

private Settings save(Path path) {
this.path = path;
validate();
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
gson.toJson(this, writer);
} catch (IOException e) {
VoidFog.LOGGER.warn("Error whilst saving Json config", e);
}
return this;
}

public void save() {
save(path);
return fogTransitionDistance.set(Math.max(0, value));
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/tamaized/voidfog/VoidFog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public class VoidFog implements ClientModInitializer {
public static final FogRenderer RENDERER = new FogRenderer();
public static final InsanityEngine INSANITY = new InsanityEngine();

public static Settings config = new Settings();
public static Settings config;

@Override
public void onInitializeClient() {
config = Settings.load(GamePaths.getConfigDirectory().resolve("voidfog.json"));
config = new Settings(GamePaths.getConfigDirectory().resolve("voidfog.json"));
ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
}

private void onTick(MinecraftClient client) {
if (!config.enabled || client.isPaused() || client.world == null || client.getCameraEntity() == null) {
if (!config.enabled.get() || client.isPaused() || client.world == null || client.getCameraEntity() == null) {
return;
}

Expand All @@ -43,7 +43,7 @@ private void onTick(MinecraftClient client) {

PARTICLE_SPAWNER.update(client.world, entity, dimension);

if (config.imABigBoi) {
if (config.imABigBoi.get()) {
INSANITY.update(client.world, entity, dimension);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tamaized/voidfog/api/Voidable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ default boolean hasInsanity(BlockPos pos, World world) {
default boolean hasDepthFog(Entity entity, World world) {

if (entity.isSpectator() || (
VoidFog.config.disableInCreative
VoidFog.config.disableInCreative.get()
&& entity instanceof PlayerEntity p
&& p.isCreative())) {
return false;
Expand Down
Loading

0 comments on commit 31ef675

Please sign in to comment.