Skip to content

Commit

Permalink
Fix PotionSpoof flickering with night vision and add potion mode to F…
Browse files Browse the repository at this point in the history
…ullbright (#4985)
  • Loading branch information
0xTas authored Oct 27, 2024
1 parent 2d96d9c commit 37f9414
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public class PotionSpoof extends Module {
.build()
);

private final Setting<Integer> 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.");
}
Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
);
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}

0 comments on commit 37f9414

Please sign in to comment.