From 9824801609e93efe6a9617b2d2235156d2de0523 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 23 Dec 2022 22:13:21 +0100 Subject: [PATCH] Bat ponies can now burn their eyes by looking directly at the sun --- .../client/ClientInteractionManager.java | 2 - .../effect/SunBlindnessStatusEffect.java | 8 ++-- .../unicopia/entity/player/Pony.java | 46 +++++++++++++++---- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java index c2267848..f5f17927 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java @@ -13,8 +13,6 @@ import com.minelittlepony.unicopia.ability.magic.CasterView; import com.minelittlepony.unicopia.block.data.Ether; import com.minelittlepony.unicopia.client.gui.DismissSpellScreen; import com.minelittlepony.unicopia.client.sound.*; -import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect; -import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.player.PlayerPhysics; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity; 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 5df140cb..420c5093 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java @@ -34,10 +34,10 @@ public class SunBlindnessStatusEffect extends StatusEffect { return; } - if (!hasSunExposure(entity)) { - entity.setStatusEffect(new StatusEffectInstance(this, (int)(state.getDuration() * 0.8F), amplifier, true, false), entity); - } else { - if (entity.age % 15 == 0) { + if (entity.age % 15 == 0) { + if (!hasSunExposure(entity)) { + entity.setStatusEffect(new StatusEffectInstance(this, (int)(state.getDuration() * 0.8F), Math.max(1, amplifier - 1), true, false), entity); + } else if (amplifier > 1) { entity.damage(DamageSource.IN_FIRE, amplifier / 20F); } } 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 fd3bdcec..12e6761d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -54,6 +54,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Hand; +import net.minecraft.util.hit.HitResult.Type; import net.minecraft.util.math.*; import net.minecraft.world.GameMode; @@ -70,6 +71,8 @@ public class Pony extends Living implements Copyable, Update static final TrackedData LEVEL = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER); static final TrackedData CORRUPTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER); + static final int INITIAL_SUN_IMMUNITY = 20; + private static final TrackedData EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND); private final AbilityDispatcher powers = new AbilityDispatcher(this); @@ -103,7 +106,7 @@ public class Pony extends Living implements Copyable, Update private int ticksInSun; private boolean hasShades; - private int ticksSunImmunity = 20; + private int ticksSunImmunity = INITIAL_SUN_IMMUNITY; private Animation animation = Animation.NONE; private int animationMaxDuration; @@ -300,6 +303,7 @@ public class Pony extends Living implements Copyable, Update && SunBlindnessStatusEffect.isPositionExposedToSun(sw, getOrigin())) { SpawnLocator.selectSpawnPosition(sw, entity); } + ticksSunImmunity = INITIAL_SUN_IMMUNITY; } @Override @@ -383,6 +387,39 @@ public class Pony extends Living implements Copyable, Update } if (getObservedSpecies() == Race.BAT && !entity.hasPortalCooldown()) { + boolean hasShades = entity.getEquippedStack(EquipmentSlot.HEAD).isIn(UTags.SHADES); + if (!this.hasShades && hasShades && getObservedSpecies() == Race.BAT) { + UCriteria.WEAR_SHADES.trigger(entity); + } + this.hasShades = hasShades; + + if (!hasShades && ticksSunImmunity <= 0) { + float skyAngle = ((entity.world.getSkyAngle(1) + 0.25F) % 1F) * 2; + float playerAngle = (-entity.getPitch(1) / 90F) / 2F; + float playerYaw = MathHelper.wrapDegrees(entity.getHeadYaw()); + + if (playerYaw > 0) { + playerAngle = 1 - playerAngle; + } + + playerYaw = Math.abs(playerYaw); + + if (skyAngle < 1 + && (playerYaw > 89 && playerYaw < 92 || (playerAngle > 0.45F && playerAngle < 0.55F)) + && playerAngle > (skyAngle - 0.04F) && playerAngle < (skyAngle + 0.04F)) { + + if (entity.raycast(100, 1, true).getType() == Type.MISS) { + if (!isClient()) { + entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 2, true, false)); + UCriteria.LOOK_INTO_SUN.trigger(entity); + } else if (isClientPlayer()) { + InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_EARS_RINGING, entity.getId()); + } + + } + } + } + if (SunBlindnessStatusEffect.hasSunExposure(entity)) { if (ticksInSun < 200) { ticksInSun++; @@ -391,7 +428,6 @@ public class Pony extends Living implements Copyable, Update if (ticksInSun == 1) { if (!isClient()) { entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 1, true, false)); - UCriteria.LOOK_INTO_SUN.trigger(entity); } else if (isClientPlayer()) { InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_EARS_RINGING, entity.getId()); } @@ -399,12 +435,6 @@ public class Pony extends Living implements Copyable, Update } else if (ticksInSun > 0) { ticksInSun--; } - - boolean hasShades = entity.getEquippedStack(EquipmentSlot.HEAD).isIn(UTags.SHADES); - if (!this.hasShades && hasShades) { - UCriteria.WEAR_SHADES.trigger(entity); - } - this.hasShades = hasShades; } if (!isClient() && !UItems.ALICORN_AMULET.isApplicable(entity)) {