so I have a code that is not working properly, which every tick with the main event handler checks if it is raining or not, if it is raining then the code in the body is executed, but it is executed 20 times per second (every tick), if I don’t interpolate then the color of the fog will change instantly, I don’t want that.
I want a smooth transition, as you can see in the code I tried to make the transition using many methods, interpolation (lerp), and by simply increasing the value of the number on the red channel (channel optional), etc. etc. but each of these methods does not work properly, I even wrote a small code that every tick gets the current value of the fog, rounds it to thousandths and translates it to double to avoid data loss, then it is added to it 0.1 and again translated into float, but the transition is sharp, then the color does not change, then the transition is smooth but 0.1 just stops adding to the value of color in the channel, as I understand here also interferes with minecraft itself interrupting my code with its own, in general I have long searched and I am tired of searching.
minecraft 1.12.2
forge api 2859
java
here is the code:
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class RustWaterFog {
static public double lerp(double fromValue, double toValue, double progress) {
return fromValue + (toValue - fromValue) * progress;
}
double[] dod = {0.0, 0.0, 0.0};
float[] progcon = {0.0001f, 0.0001f, 0.0001f};
@SubscribeEvent
public void onEntityViewRender(EntityViewRenderEvent.FogColors event) {
double[] BLOOD_COLOR = {event.getRed(), event.getGreen(), event.getBlue()};
if (Minecraft.getMinecraft().world.isRaining()) {
/*
event.setBlue(lerp(BLOOD_COLOR[2], 0.02f, progcon[2]));
event.setGreen(lerp(BLOOD_COLOR[1], 0.02f, progcon[1]));
event.setRed(lerp(BLOOD_COLOR[0], 0.50f, progcon[0]));
dod[0] = Math.round(lerp(BLOOD_COLOR[0], 0.50f, progcon[0]) * 100.0) / 100.0;
dod[1] = Math.round(lerp(BLOOD_COLOR[1], 0.02f, progcon[1]) * 100.0) / 100.0;
dod[2] = Math.round(lerp(BLOOD_COLOR[2], 0.02f, progcon[2]) * 100.0) / 100.0;
if (dod[0] < 0.50)
{
progcon[0] += 0.0009f;
} else {
}
if (dod[1] < 0.02)
{
progcon[1] += 0.0009f;
}
if (dod[2] < 0.02)
{
progcon[2] += 0.0009f;
}
System.out.println(dod[1]);
double dolboeb = 0.001;
//dolboeb+=0.001;
double red = event.getRed();
float red1 = (float)Math.round(lerp(event.getRed()*100, 58, dolboeb) * 1000.0) / 1000;
event.setRed(red1);
/*event.setGreen();
event.setBlue();*/
dod[0] = (Math.round(BLOOD_COLOR[0] * 100.0) / 100.0)+0.1;
float dodred = (float)dod[0];
event.setRed(dodred);
System.out.println(dodred);
}
}
}
in my console every tick the value on channel red is displayed, here’s how this class behaves:
0.2
0.22
0.22
0.22
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.23
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.24
0.25
after 0.25, nothing changes.
I apologize in advance if the structure of the question is wrong.
thanks