Rework fog events (#8492)

This commit is contained in:
eerussianguy authored and GitHub committed 2022-03-23 01:43:39 +01:00
1 parent 5ac711839f
commit e1ad29edd0
3 files changed
+92 -14

No files matched your search

@@ -6,6 +6,8 @@
package net.minecraftforge.client;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.shaders.FogShape;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.datafixers.util.Either;
@@ -389,11 +391,26 @@ public class ForgeHooksClient
return -1;
}
/**
* @deprecated to be removed in 1.19, use other onFogRender hook with more params
*/
@Deprecated(forRemoval = true, since = "1.18.2")
public static void onFogRender(FogMode type, Camera camera, float partialTick, float distance)
{
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(type, camera, partialTick, distance));
}
public static void onFogRender(FogMode type, Camera camera, float partialTick, float nearDistance, float farDistance, FogShape shape)
{
EntityViewRenderEvent.RenderFogEvent event = new EntityViewRenderEvent.RenderFogEvent(type, camera, partialTick, nearDistance, farDistance, shape);
if (MinecraftForge.EVENT_BUS.post(event))
{
RenderSystem.setShaderFogStart(event.getNearPlaneDistance());
RenderSystem.setShaderFogEnd(event.getFarPlaneDistance());
RenderSystem.setShaderFogShape(event.getFogShape());
}
}
public static EntityViewRenderEvent.CameraSetup onCameraSetup(GameRenderer renderer, Camera camera, float partial)
{
EntityViewRenderEvent.CameraSetup event = new EntityViewRenderEvent.CameraSetup(renderer, camera, partial, camera.getYRot(), camera.getXRot(), 0);
@@ -11,6 +11,8 @@ import net.minecraft.client.renderer.FogRenderer.FogMode;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraftforge.eventbus.api.Cancelable;
import com.mojang.blaze3d.shaders.FogShape;
/**
* Event that hooks into GameRenderer, allowing any feature to customize visual attributes
* the player sees.
@@ -43,6 +45,7 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
return partialTicks;
}
@Deprecated(forRemoval = true, since = "1.18.2")
private static class FogEvent extends EntityViewRenderEvent
{
private final FogMode mode;
@@ -57,10 +60,13 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
}
/**
* @deprecated Use RenderFogEvent. This event will be removed as the other event has better functionality.
*
* Event that allows any feature to customize the fog density the player sees.
* NOTE: In order to make this event have an effect, you must cancel the event
*/
@Cancelable
@Deprecated(forRemoval = true, since = "1.18.2")
public static class FogDensity extends FogEvent
{
private float density;
@@ -83,23 +89,84 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
}
/**
* Event that allows any feature to customize the rendering of fog.
* This event allows for customization of parameters related to fog rendering. The plane distances are based on the player's render distance.
* For the event to have an effect, you must cancel it.
*
* The FogMode is NOT customizable. It describes the type of fog being modified.
* A FogMode of FOG_SKY is the skybox's fog.
* A FogMode of FOG_TERRAIN is what the fog induced by render distance uses. This works best for reducing the camera's visibility.
*/
@HasResult
public static class RenderFogEvent extends FogEvent
@HasResult // TODO: remove in 1.19. Setting a result for this event has no effect.
@Cancelable
public static class RenderFogEvent extends FogEvent // TODO: In 1.19, change superclass to EntityViewRenderEvent
{
private final float farPlaneDistance;
private final FogMode type;
private float farPlaneDistance;
private float nearPlaneDistance;
private FogShape fogShape;
/**
* @deprecated Use other constructor with all the params. Will be removed in 1.19
*/
@Deprecated(forRemoval = true, since = "1.18.2")
public RenderFogEvent(FogMode type, Camera camera, float partialTicks, float distance)
{
this(type, camera, partialTicks, -8f, distance, FogShape.SPHERE);
}
public RenderFogEvent(FogMode type, Camera camera, float partialTicks, float nearPlaneDistance, float farPlaneDistance, FogShape fogShape)
{
super(type, camera, partialTicks);
this.farPlaneDistance = distance;
this.type = type;
setFarPlaneDistance(farPlaneDistance);
setNearPlaneDistance(nearPlaneDistance);
setFogShape(fogShape);
}
public FogMode getMode()
{
return type;
}
public float getFarPlaneDistance()
{
return farPlaneDistance;
}
public float getNearPlaneDistance()
{
return nearPlaneDistance;
}
public FogShape getFogShape()
{
return fogShape;
}
public void setFarPlaneDistance(float distance)
{
farPlaneDistance = distance;
}
public void setNearPlaneDistance(float distance)
{
nearPlaneDistance = distance;
}
public void setFogShape(FogShape shape)
{
fogShape = shape;
}
public void scaleFarPlaneDistance(float factor)
{
farPlaneDistance *= factor;
}
public void scaleNearPlaneDistance(float factor)
{
nearPlaneDistance *= factor;
}
}
/**