135 lines
		
	
	
	
		
			4.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
	
		
			4.1 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.ARGB;
 | |
| 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;
 | |
| 
 | |
| @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 DimensionSpecialEffects.SkyType skyType;
 | |
| 	private final boolean forceBrightLightmap;
 | |
| 	private final boolean constantAmbientLight;
 | |
| 
 | |
| 	public DimensionSpecialEffects(DimensionSpecialEffects.SkyType skyType, boolean forceBrightLightmap, boolean constantAmbientLight) {
 | |
| 		this.skyType = skyType;
 | |
| 		this.forceBrightLightmap = forceBrightLightmap;
 | |
| 		this.constantAmbientLight = constantAmbientLight;
 | |
| 	}
 | |
| 
 | |
| 	public static DimensionSpecialEffects forType(DimensionType dimensionType) {
 | |
| 		return EFFECTS.get(dimensionType.effectsLocation());
 | |
| 	}
 | |
| 
 | |
| 	public boolean isSunriseOrSunset(float timeOfDay) {
 | |
| 		return false;
 | |
| 	}
 | |
| 
 | |
| 	public int getSunriseOrSunsetColor(float timeOfDay) {
 | |
| 		return 0;
 | |
| 	}
 | |
| 
 | |
| 	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(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;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	@Environment(EnvType.CLIENT)
 | |
| 	public static class NetherEffects extends DimensionSpecialEffects {
 | |
| 		public NetherEffects() {
 | |
| 			super(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 {
 | |
| 		private static final float SUNRISE_AND_SUNSET_TIMESPAN = 0.4F;
 | |
| 
 | |
| 		public OverworldEffects() {
 | |
| 			super(DimensionSpecialEffects.SkyType.OVERWORLD, false, false);
 | |
| 		}
 | |
| 
 | |
| 		@Override
 | |
| 		public boolean isSunriseOrSunset(float timeOfDay) {
 | |
| 			float f = Mth.cos(timeOfDay * (float) (Math.PI * 2));
 | |
| 			return f >= -0.4F && f <= 0.4F;
 | |
| 		}
 | |
| 
 | |
| 		@Override
 | |
| 		public int getSunriseOrSunsetColor(float timeOfDay) {
 | |
| 			float f = Mth.cos(timeOfDay * (float) (Math.PI * 2));
 | |
| 			float g = f / 0.4F * 0.5F + 0.5F;
 | |
| 			float h = Mth.square(1.0F - (1.0F - Mth.sin(g * (float) Math.PI)) * 0.99F);
 | |
| 			return ARGB.colorFromFloat(h, g * 0.3F + 0.7F, g * g * 0.7F + 0.2F, 0.2F);
 | |
| 		}
 | |
| 
 | |
| 		@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,
 | |
| 		OVERWORLD,
 | |
| 		END;
 | |
| 	}
 | |
| }
 |