153 lines
4.6 KiB
Java
153 lines
4.6 KiB
Java
package net.minecraft.client.renderer;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
|
import net.minecraft.world.level.dimension.DimensionType;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public abstract class DimensionSpecialEffects {
|
|
private static final Object2ObjectMap<ResourceLocation, DimensionSpecialEffects> EFFECTS = Util.make(new Object2ObjectArrayMap<>(), object2ObjectArrayMap -> {
|
|
DimensionSpecialEffects.OverworldEffects overworldEffects = new DimensionSpecialEffects.OverworldEffects();
|
|
object2ObjectArrayMap.defaultReturnValue(overworldEffects);
|
|
object2ObjectArrayMap.put(BuiltinDimensionTypes.OVERWORLD_EFFECTS, overworldEffects);
|
|
object2ObjectArrayMap.put(BuiltinDimensionTypes.NETHER_EFFECTS, new DimensionSpecialEffects.NetherEffects());
|
|
object2ObjectArrayMap.put(BuiltinDimensionTypes.END_EFFECTS, new DimensionSpecialEffects.EndEffects());
|
|
});
|
|
private final float[] sunriseCol = new float[4];
|
|
private final float cloudLevel;
|
|
private final boolean hasGround;
|
|
private final DimensionSpecialEffects.SkyType skyType;
|
|
private final boolean forceBrightLightmap;
|
|
private final boolean constantAmbientLight;
|
|
|
|
public DimensionSpecialEffects(
|
|
float cloudLevel, boolean hasGround, DimensionSpecialEffects.SkyType skyType, boolean forceBrightLightmap, boolean constantAmbientLight
|
|
) {
|
|
this.cloudLevel = cloudLevel;
|
|
this.hasGround = hasGround;
|
|
this.skyType = skyType;
|
|
this.forceBrightLightmap = forceBrightLightmap;
|
|
this.constantAmbientLight = constantAmbientLight;
|
|
}
|
|
|
|
public static DimensionSpecialEffects forType(DimensionType dimensionType) {
|
|
return EFFECTS.get(dimensionType.effectsLocation());
|
|
}
|
|
|
|
@Nullable
|
|
public float[] getSunriseColor(float timeOfDay, float partialTicks) {
|
|
float f = 0.4F;
|
|
float g = Mth.cos(timeOfDay * (float) (Math.PI * 2)) - 0.0F;
|
|
float h = -0.0F;
|
|
if (g >= -0.4F && g <= 0.4F) {
|
|
float i = (g - -0.0F) / 0.4F * 0.5F + 0.5F;
|
|
float j = 1.0F - (1.0F - Mth.sin(i * (float) Math.PI)) * 0.99F;
|
|
j *= j;
|
|
this.sunriseCol[0] = i * 0.3F + 0.7F;
|
|
this.sunriseCol[1] = i * i * 0.7F + 0.2F;
|
|
this.sunriseCol[2] = i * i * 0.0F + 0.2F;
|
|
this.sunriseCol[3] = j;
|
|
return this.sunriseCol;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public float getCloudHeight() {
|
|
return this.cloudLevel;
|
|
}
|
|
|
|
public boolean hasGround() {
|
|
return this.hasGround;
|
|
}
|
|
|
|
public abstract Vec3 getBrightnessDependentFogColor(Vec3 fogColor, float brightness);
|
|
|
|
public abstract boolean isFoggyAt(int x, int y);
|
|
|
|
public DimensionSpecialEffects.SkyType skyType() {
|
|
return this.skyType;
|
|
}
|
|
|
|
public boolean forceBrightLightmap() {
|
|
return this.forceBrightLightmap;
|
|
}
|
|
|
|
public boolean constantAmbientLight() {
|
|
return this.constantAmbientLight;
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class EndEffects extends DimensionSpecialEffects {
|
|
public EndEffects() {
|
|
super(Float.NaN, false, DimensionSpecialEffects.SkyType.END, true, false);
|
|
}
|
|
|
|
@Override
|
|
public Vec3 getBrightnessDependentFogColor(Vec3 fogColor, float brightness) {
|
|
return fogColor.scale(0.15F);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFoggyAt(int x, int y) {
|
|
return false;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public float[] getSunriseColor(float timeOfDay, float partialTicks) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class NetherEffects extends DimensionSpecialEffects {
|
|
public NetherEffects() {
|
|
super(Float.NaN, true, DimensionSpecialEffects.SkyType.NONE, false, true);
|
|
}
|
|
|
|
@Override
|
|
public Vec3 getBrightnessDependentFogColor(Vec3 fogColor, float brightness) {
|
|
return fogColor;
|
|
}
|
|
|
|
@Override
|
|
public boolean isFoggyAt(int x, int y) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static class OverworldEffects extends DimensionSpecialEffects {
|
|
public static final int CLOUD_LEVEL = 192;
|
|
|
|
public OverworldEffects() {
|
|
super(192.0F, true, DimensionSpecialEffects.SkyType.NORMAL, false, false);
|
|
}
|
|
|
|
@Override
|
|
public Vec3 getBrightnessDependentFogColor(Vec3 fogColor, float brightness) {
|
|
return fogColor.multiply(brightness * 0.94F + 0.06F, brightness * 0.94F + 0.06F, brightness * 0.91F + 0.09F);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFoggyAt(int x, int y) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static enum SkyType {
|
|
NONE,
|
|
NORMAL,
|
|
END;
|
|
}
|
|
}
|