darkness?
This commit is contained in:
parent
010140a36c
commit
96bb287ed6
|
@ -30,11 +30,10 @@ public abstract class LightTextureMixin {
|
|||
@Shadow protected abstract float getBrightness(Level level, int i);
|
||||
@Shadow @Final private DynamicTexture lightTexture;
|
||||
@Shadow @Final private NativeImage lightPixels;
|
||||
@Shadow protected abstract float notGamma(float f);
|
||||
@Shadow @Final private GameRenderer renderer;
|
||||
|
||||
private LocalPlayer getPlayer() {
|
||||
assert this.minecraft.player != null;
|
||||
// assert this.minecraft.player != null;
|
||||
return this.minecraft.player;
|
||||
}
|
||||
|
||||
|
@ -52,7 +51,7 @@ public abstract class LightTextureMixin {
|
|||
}
|
||||
|
||||
//TODO simplify
|
||||
@Inject(method = "updateLightTexture", at = @At("HEAD"))
|
||||
@Inject(method = "updateLightTexture(F)V", at = @At("HEAD"))
|
||||
private void updateLight(float delta, CallbackInfo ci) {
|
||||
if (this.updateLightTexture) {
|
||||
this.updateLightTexture = false;
|
||||
|
@ -130,4 +129,9 @@ public abstract class LightTextureMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float notGamma(float f) {
|
||||
float g = 1.0f - f;
|
||||
return 1.0f - g * g * g * g;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@
|
|||
"access.MobEffectAccessor",
|
||||
"access.ModelPartAccessor",
|
||||
"access.OverworldBiomesAccessor",
|
||||
"access.PersistentEntitySectionManagerAccessor",
|
||||
"access.PointedDripstoneBlockAccessor",
|
||||
"access.PressurePlateBlockAccessor",
|
||||
"access.RecordItemAccessor",
|
||||
|
@ -32,14 +31,12 @@
|
|||
"access.WoodButtonBlockAccessor",
|
||||
"access.WoodTypeAccessor",
|
||||
"common.BlockEntityTypeMixin",
|
||||
"common.EntityCallbacksMixin",
|
||||
"common.FlyNodeEvaluatorMixin",
|
||||
"common.LivingEntityMixin",
|
||||
"common.MobEffectMixin",
|
||||
"common.MobEffectMixin$MobEffectInstanceMixin",
|
||||
"common.NoteBlockMixin",
|
||||
"common.PathfinderMobMixin",
|
||||
"common.PersistentEntitySectionManagerMixin",
|
||||
"common.PlayerMixin",
|
||||
"common.PointedDripstoneBlockMixin",
|
||||
"common.SculkSensorBlockEntityMixin",
|
||||
|
@ -51,7 +48,6 @@
|
|||
"network.ServerGamePacketListenerImplMixin"
|
||||
],
|
||||
"client": [
|
||||
"client.FogRendererMixin",
|
||||
"client.LightTextureMixin",
|
||||
"client.LocalPlayerMixin",
|
||||
"client.ModelPartMixin",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.cursedcauldron.wildbackport.core.mixin.client;
|
||||
package com.cursedcauldron.wildbackport.core.mixin.fabric.client;
|
||||
|
||||
import com.cursedcauldron.wildbackport.common.effects.EffectFactor;
|
||||
import com.cursedcauldron.wildbackport.common.registry.WBMobEffects;
|
||||
|
@ -18,7 +18,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class FogRendererMixin {
|
||||
@Shadow private static float fogRed;
|
||||
@Shadow
|
||||
private static float fogRed;
|
||||
@Shadow private static float fogGreen;
|
||||
@Shadow private static float fogBlue;
|
||||
private static float fogPartialTicks;
|
||||
|
@ -58,7 +59,7 @@ public class FogRendererMixin {
|
|||
RenderSystem.clearColor(fogRed, fogGreen, fogBlue, 0.0F);
|
||||
}
|
||||
|
||||
@Inject(method = "setupFog", at = @At("TAIL"), remap = false)
|
||||
@Inject(method = "setupFog", at = @At("TAIL"))
|
||||
private static void applyDarknessFog(Camera camera, FogRenderer.FogMode mode, float viewDistance, boolean thickFog, CallbackInfo ci) {
|
||||
FogType fogtype = camera.getFluidInCamera();
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"client.FogRendererMixin",
|
||||
"client.SheetsMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package com.cursedcauldron.wildbackport.core.mixin.forge.client;
|
||||
|
||||
import com.cursedcauldron.wildbackport.common.effects.EffectFactor;
|
||||
import com.cursedcauldron.wildbackport.common.registry.WBMobEffects;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class FogRendererMixin {
|
||||
@Shadow private static float fogRed;
|
||||
@Shadow private static float fogGreen;
|
||||
@Shadow private static float fogBlue;
|
||||
|
||||
@Inject(method = "setupColor", at = @At("TAIL"))
|
||||
private static void applyDarknessColor(Camera camera, float partialTicks, ClientLevel level, int viewDistance, float skyDarkness, CallbackInfo ci) {
|
||||
FogType type = camera.getFluidInCamera();
|
||||
|
||||
double colorModifier = (camera.getPosition().y - (double)level.getMinBuildHeight()) * level.getLevelData().getClearColorScale();
|
||||
if (camera.getEntity() instanceof LivingEntity living && living.hasEffect(WBMobEffects.DARKNESS.get())) {
|
||||
MobEffectInstance effect = living.getEffect(WBMobEffects.DARKNESS.get());
|
||||
|
||||
if (effect != null) {
|
||||
EffectFactor.Instance instance = EffectFactor.Instance.of(effect);
|
||||
colorModifier = instance.getFactorCalculationData().isPresent() ? 1.0F - instance.getFactorCalculationData().get().lerp(living, partialTicks) : 0.0D;
|
||||
}
|
||||
}
|
||||
|
||||
if (colorModifier < 1.0D && type != FogType.LAVA) {
|
||||
if (colorModifier < 0.0D) {
|
||||
colorModifier = 0.0D;
|
||||
}
|
||||
|
||||
colorModifier *= colorModifier;
|
||||
fogRed = (float)((double)fogRed * colorModifier);
|
||||
fogGreen = (float)((double)fogGreen * colorModifier);
|
||||
fogBlue = (float)((double)fogBlue * colorModifier);
|
||||
}
|
||||
|
||||
if (skyDarkness > 0.0F) {
|
||||
fogRed = fogRed * (1.0F - skyDarkness) + fogRed * 0.7F * skyDarkness;
|
||||
fogGreen = fogGreen * (1.0F - skyDarkness) + fogGreen * 0.6F * skyDarkness;
|
||||
fogBlue = fogBlue * (1.0F - skyDarkness) + fogBlue * 0.6F * skyDarkness;
|
||||
}
|
||||
|
||||
RenderSystem.clearColor(fogRed, fogGreen, fogBlue, 0.0F);
|
||||
}
|
||||
|
||||
@Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", at = @At("TAIL"), remap = false)
|
||||
private static void applyDarknessFog(Camera camera, FogRenderer.FogMode mode, float viewDistance, boolean thickFog, float partialTicks, CallbackInfo ci) {
|
||||
FogType fogtype = camera.getFluidInCamera();
|
||||
|
||||
if (fogtype != FogType.WATER) {
|
||||
if (camera.getEntity() instanceof LivingEntity living && living.hasEffect(WBMobEffects.DARKNESS.get())) {
|
||||
MobEffectInstance effect = living.getEffect(WBMobEffects.DARKNESS.get());
|
||||
|
||||
if (effect != null) {
|
||||
EffectFactor.Instance instance = EffectFactor.Instance.of(effect);
|
||||
if (instance.getFactorCalculationData().isPresent()) {
|
||||
float modifier = Mth.lerp(instance.getFactorCalculationData().get().lerp(living, partialTicks), viewDistance, 15.0F);
|
||||
float start = mode == FogRenderer.FogMode.FOG_SKY ? 0.0F : modifier * 0.75F;
|
||||
|
||||
RenderSystem.setShaderFogStart(start);
|
||||
RenderSystem.setShaderFogEnd(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +1,55 @@
|
|||
package com.cursedcauldron.wildbackport.forge;
|
||||
|
||||
import com.cursedcauldron.wildbackport.WildBackport;
|
||||
import com.cursedcauldron.wildbackport.client.ClientSetup;
|
||||
import com.cursedcauldron.wildbackport.common.effects.EffectFactor;
|
||||
import com.cursedcauldron.wildbackport.common.registry.WBMobEffects;
|
||||
import com.cursedcauldron.wildbackport.core.api.forge.EventBuses;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class WildBackportForgeClient {
|
||||
public WildBackportForgeClient() {
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
IEventBus bus = EventBuses.getModEventBusOrThrow(WildBackport.MOD_ID);
|
||||
|
||||
bus.addListener(this::setup);
|
||||
bus.addListener(this::darknessFog);
|
||||
}
|
||||
|
||||
public void setup(FMLClientSetupEvent event) {
|
||||
ClientSetup.onClient();
|
||||
ClientSetup.onPostClient();
|
||||
}
|
||||
|
||||
public void darknessFog(EntityViewRenderEvent.RenderFogEvent event) {
|
||||
FogType type = event.getCamera().getFluidInCamera();
|
||||
|
||||
if (type != FogType.WATER) {
|
||||
if (event.getCamera().getEntity() instanceof LivingEntity living && living.hasEffect(WBMobEffects.DARKNESS.get())) {
|
||||
MobEffectInstance effect = living.getEffect(WBMobEffects.DARKNESS.get());
|
||||
|
||||
if (effect != null) {
|
||||
EffectFactor.Instance instance = EffectFactor.Instance.of(effect);
|
||||
if (instance.getFactorCalculationData().isPresent()) {
|
||||
float modifier = Mth.lerp(instance.getFactorCalculationData().get().lerp(living, (float)event.getPartialTicks()), event.getFarPlaneDistance(), 15.0F);
|
||||
float start = event.getMode() == FogRenderer.FogMode.FOG_SKY ? 0.0F : modifier * 0.75F;
|
||||
|
||||
RenderSystem.setShaderFogStart(start);
|
||||
RenderSystem.setShaderFogEnd(modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.cursedcauldron.wildbackport.mixin.forge",
|
||||
"package": "com.cursedcauldron.wildbackport.core.mixin.forge",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"client.FogRendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue