From 869d900f1485ba5fd146c3b5a8908b0579e4f764 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 18 Sep 2022 23:05:28 +0200 Subject: [PATCH] Nerf batpony blindness. Fixes #58 --- .../unicopia/client/ClientInteractionManager.java | 12 +++++++++++- .../unicopia/client/sound/LoopingSoundInstance.java | 7 +++++++ .../entity/effect/SunBlindnessStatusEffect.java | 2 +- .../minelittlepony/unicopia/entity/player/Pony.java | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java index 3a64e5f6..ff0887d9 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.client; +import java.util.function.Predicate; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,7 +58,10 @@ public class ClientInteractionManager extends InteractionManager { SoundManager soundManager = client.getSoundManager(); if (type == SOUND_EARS_RINGING && source instanceof LivingEntity) { - soundManager.play(new LoopingSoundInstance<>((LivingEntity)source, e -> e.hasStatusEffect(UEffects.SUN_BLINDNESS), USounds.ENTITY_PLAYER_EARS_RINGING, 1, 1, Random.create(seed))); + soundManager.play(new LoopingSoundInstance<>((LivingEntity)source, + createTicker(100).and(e -> e.hasStatusEffect(UEffects.SUN_BLINDNESS)), + USounds.ENTITY_PLAYER_EARS_RINGING, 0.01F, 2, Random.create(seed)).setFadeIn() + ); } else if (type == SOUND_BEE && source instanceof BeeEntity) { soundManager.playNextTick( ((BeeEntity)source).hasAngerTime() @@ -78,6 +83,11 @@ public class ClientInteractionManager extends InteractionManager { }); } + static Predicate createTicker(int ticks) { + int[] ticker = new int[] {ticks}; + return entity -> ticker[0]-- > 0; + } + @Override public void openScreen(int type) { client.execute(() -> { diff --git a/src/main/java/com/minelittlepony/unicopia/client/sound/LoopingSoundInstance.java b/src/main/java/com/minelittlepony/unicopia/client/sound/LoopingSoundInstance.java index 9d1ab245..111509c1 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/sound/LoopingSoundInstance.java +++ b/src/main/java/com/minelittlepony/unicopia/client/sound/LoopingSoundInstance.java @@ -21,6 +21,13 @@ public class LoopingSoundInstance extends FadeOutSoundInstance this.attenuationType = SoundInstance.AttenuationType.NONE; } + public LoopingSoundInstance setFadeIn() { + float volume = this.volume; + this.volume = 0.001F; + setTargetVolume(volume); + return this; + } + @Override protected boolean shouldKeepPlaying() { if (source.isRemoved() || !shouldPlay.test(source)) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java index 5e0ed64e..3b681d00 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java @@ -16,7 +16,7 @@ import net.minecraft.entity.effect.StatusEffects; import net.minecraft.world.LightType; public class SunBlindnessStatusEffect extends StatusEffect { - public static final int MAX_DURATION = 50; + public static final int MAX_DURATION = 250; SunBlindnessStatusEffect(int color) { super(StatusEffectCategory.NEUTRAL, color); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 61bb9ece..3f46156e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -364,8 +364,8 @@ public class Pony extends Living implements Transmittable, Copieab } if (ticksInSun == 1) { + entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 1, true, false)); if (!isClient()) { - entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION * 10, 1, true, false)); UCriteria.LOOK_INTO_SUN.trigger(entity); } else if (isClientPlayer()) { InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_EARS_RINGING, getEntity().getId());