From 2422938dabab1428ac4649bd54afd0484cc5d435 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 2 Oct 2024 23:32:27 +0100 Subject: [PATCH] Remove unneccessary injection --- .../unicopia/client/BatEyesApplicator.java | 16 +++++++++++----- .../unicopia/client/UnicopiaClient.java | 7 ------- .../unicopia/mixin/client/MixinGameRenderer.java | 14 +------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java b/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java index a3191d17..f9f26c79 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java +++ b/src/main/java/com/minelittlepony/unicopia/client/BatEyesApplicator.java @@ -3,9 +3,9 @@ package com.minelittlepony.unicopia.client; import com.minelittlepony.unicopia.EquinePredicates; import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.player.PlayerEntity; public class BatEyesApplicator { @@ -15,11 +15,17 @@ public class BatEyesApplicator { private final MinecraftClient client = MinecraftClient.getInstance(); + public float getWorldBrightness(float initial, LivingEntity entity, float tickDelta) { + if (!EquinePredicates.PLAYER_BAT.test(entity)) { + return initial; + } + return 0.6F; + } + public void enable() { - if (client.world != null) { - PlayerEntity player = client.player; - if (!player.hasStatusEffect(StatusEffects.NIGHT_VISION) && EquinePredicates.PLAYER_BAT.test(player)) { - player.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 1, 1, false, false)); + if (client.world != null && client.player != null) { + if (!client.player.hasStatusEffect(StatusEffects.NIGHT_VISION) && EquinePredicates.PLAYER_BAT.test(client.player)) { + client.player.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, -1, 1, false, false)); batEyesApplied = true; } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java index 4e2a8ac4..8fb1e403 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java @@ -53,9 +53,6 @@ public class UnicopiaClient implements ClientModInitializer { return Pony.of(MinecraftClient.getInstance().player); } - private final Lerp rainGradient = new Lerp(0); - private final Lerp thunderGradient = new Lerp(0); - public final Lerp tangentalSkyAngle = new Lerp(0, true); public final Lerp skyAngle = new Lerp(0, true); @@ -103,10 +100,6 @@ public class UnicopiaClient implements ClientModInitializer { return Unicopia.getConfig().preferredRace.get(); } - public static float getWorldBrightness(float initial) { - return 0.6F; - } - public UnicopiaClient() { instance = this; } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java index 2fe4abe2..d9effcf6 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinGameRenderer.java @@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.client.BatEyesApplicator; import com.minelittlepony.unicopia.client.UnicopiaClient; import com.minelittlepony.unicopia.client.render.shader.ViewportShader; @@ -17,7 +16,6 @@ import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.RotationAxis; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffects; import net.minecraft.resource.SynchronousResourceReloader; @Mixin(value = GameRenderer.class, priority = Integer.MAX_VALUE) @@ -46,21 +44,11 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe BatEyesApplicator.INSTANCE.disable(); } - @Inject(method = "getNightVisionStrength(Lnet/minecraft/entity/LivingEntity;F)F", - at = @At("HEAD"), - cancellable = true) - private static void onGetNightVisionStrengthHead(LivingEntity entity, float tickDelta, CallbackInfoReturnable info) { - if (!entity.hasStatusEffect(StatusEffects.NIGHT_VISION)) { - info.setReturnValue(UnicopiaClient.getWorldBrightness(0)); - } - } @Inject(method = "getNightVisionStrength(Lnet/minecraft/entity/LivingEntity;F)F", at = @At("RETURN"), cancellable = true) private static void onGetNightVisionStrengthReturn(LivingEntity entity, float tickDelta, CallbackInfoReturnable info) { - if (entity.hasStatusEffect(StatusEffects.NIGHT_VISION) && EquinePredicates.PLAYER_BAT.test(entity)) { - info.setReturnValue(UnicopiaClient.getWorldBrightness(info.getReturnValueF())); - } + info.setReturnValue(BatEyesApplicator.INSTANCE.getWorldBrightness(info.getReturnValueF(), entity, tickDelta)); } @Inject(method = "render",