From 37f9414ffb7497e6db9e1fdbb4e2dddd4661e6d6 Mon Sep 17 00:00:00 2001 From: Tas <103238549+0xTas@users.noreply.github.com> Date: Sun, 27 Oct 2024 10:08:00 -0700 Subject: [PATCH] Fix PotionSpoof flickering with night vision and add potion mode to Fullbright (#4985) --- .../systems/modules/player/PotionSpoof.java | 13 ++++++-- .../systems/modules/render/Fullbright.java | 31 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java index a24a3271e5..95f92ca728 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java @@ -50,6 +50,15 @@ public class PotionSpoof extends Module { .build() ); + private final Setting effectDuration = sgGeneral.add(new IntSetting.Builder() + .name("effect-duration") + .description("How many ticks to spoof the effect for.") + .range(1, 32767) + .sliderRange(20, 500) + .defaultValue(420) + .build() + ); + public PotionSpoof() { super(Categories.Player, "potion-spoof", "Spoofs potion statuses for you. SOME effects DO NOT work."); } @@ -73,9 +82,9 @@ private void onTick(TickEvent.Post event) { if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey()))) { StatusEffectInstance instance = mc.player.getStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey())); ((StatusEffectInstanceAccessor) instance).setAmplifier(level - 1); - if (instance.getDuration() < 20) ((StatusEffectInstanceAccessor) instance).setDuration(20); + if (instance.getDuration() < effectDuration.get()) ((StatusEffectInstanceAccessor) instance).setDuration(effectDuration.get()); } else { - mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(entry.getKey()), 20, level - 1)); + mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(entry.getKey()), effectDuration.get(), level - 1)); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java index d039356086..5a0fa0fa2b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java @@ -5,12 +5,18 @@ package meteordevelopment.meteorclient.systems.modules.render; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.mixin.StatusEffectInstanceAccessor; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.IntSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.registry.Registries; import net.minecraft.world.LightType; public class Fullbright extends Module { @@ -21,7 +27,10 @@ public class Fullbright extends Module { .description("The mode to use for Fullbright.") .defaultValue(Mode.Gamma) .onChanged(mode -> { - if (mc.worldRenderer != null && isActive()) mc.worldRenderer.reload(); + if (isActive()) { + if (mode != Mode.Potion) disableNightVision(); + if (mc.worldRenderer != null) mc.worldRenderer.reload(); + } }) .build() ); @@ -62,6 +71,7 @@ public void onActivate() { @Override public void onDeactivate() { if (mode.get() == Mode.Luminance) mc.worldRenderer.reload(); + else if (mode.get() == Mode.Potion) disableNightVision(); } public int getLuminance(LightType type) { @@ -73,8 +83,27 @@ public boolean getGamma() { return isActive() && mode.get() == Mode.Gamma; } + @EventHandler + private void onTick(TickEvent.Post event) { + if (mc.player == null || !mode.get().equals(Mode.Potion)) return; + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()))) { + StatusEffectInstance instance = mc.player.getStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value())); + if (instance != null && instance.getDuration() < 420) ((StatusEffectInstanceAccessor) instance).setDuration(420); + } else { + mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()), 420, 0)); + } + } + + private void disableNightVision() { + if (mc.player == null) return; + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()))) { + mc.player.removeStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value())); + } + } + public enum Mode { Gamma, + Potion, Luminance } }