From 1992a1fd53ed65bd9ac6f2944632cdddc8138063 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 27 Feb 2021 22:06:25 +0200 Subject: [PATCH] Add particle effects and sound effects when adding/removing the wings of icarus --- .../minelittlepony/unicopia/FlightType.java | 10 ++----- .../unicopia/entity/player/PlayerPhysics.java | 28 ++++++++++++------- .../unicopia/item/AmuletItem.java | 10 +++++++ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/FlightType.java b/src/main/java/com/minelittlepony/unicopia/FlightType.java index 7935e92a..6c9d6368 100644 --- a/src/main/java/com/minelittlepony/unicopia/FlightType.java +++ b/src/main/java/com/minelittlepony/unicopia/FlightType.java @@ -2,11 +2,11 @@ package com.minelittlepony.unicopia; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.sound.SoundEvent; public enum FlightType { NONE, - CREATIVE, AVIAN, INSECTOID, ARTIFICIAL; @@ -27,12 +27,8 @@ public enum FlightType { return !isGrounded(); } - public boolean canFlyCreative() { - return this == CREATIVE || this == INSECTOID; - } - - public boolean canFlySurvival() { - return canFly() && !canFlyCreative(); + public boolean canFlyCreative(PlayerEntity player) { + return this == INSECTOID || player.isCreative() || player.isSpectator(); } public SoundEvent getWingFlapSound() { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 73d71632..081671d9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -13,6 +13,7 @@ import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.item.AmuletItem; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.enchantment.UEnchantments; +import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.projectile.ProjectileUtil; import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.MutableVector; @@ -30,6 +31,7 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.particle.ParticleTypes; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Tickable; @@ -43,7 +45,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti private float thrustScale = 0; - private FlightType lastFlightType; + private FlightType lastFlightType = FlightType.NONE; public boolean isFlyingEither = false; public boolean isFlyingSurvival = false; @@ -83,16 +85,19 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti public float getWingAngle() { float spreadAmount = -0.5F; + PlayerEntity entity = pony.getMaster(); + if (isFlying()) { //spreadAmount += Math.sin(pony.getEntity().age / 4F) * 8; spreadAmount += isGliding() ? 3 : thrustScale * 60; } - if (pony.getEntity().isSneaking()) { + if (entity.isSneaking()) { spreadAmount += 2; } - spreadAmount += Math.sin(pony.getEntity().age / 9F) / 9F; + spreadAmount += MathHelper.clamp(-entity.getVelocity().y, 0, 2); + spreadAmount += Math.sin(entity.age / 9F) / 9F; spreadAmount = MathHelper.clamp(spreadAmount, -2, 5); return pony.getInterpolator().interpolate("wingSpreadAmount", spreadAmount, 10); @@ -121,7 +126,13 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti FlightType type = getFlightType(); - entity.abilities.allowFlying = type.canFlyCreative(); + if (type != lastFlightType && (lastFlightType.isArtifical() || type.isArtifical())) { + ParticleUtils.spawnParticles(ParticleTypes.CLOUD, entity, 10); + + entity.world.playSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_BELL_RESONATE, SoundCategory.PLAYERS, 0.1125F, 1.5F, true); + } + + entity.abilities.allowFlying = type.canFlyCreative(entity); if (!creative) { entity.abilities.flying |= (type.canFly() || entity.abilities.allowFlying) && isFlyingEither; @@ -195,8 +206,8 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti entity.world.playSoundFromEntity(null, entity, SoundEvents.BLOCK_CHAIN_STEP, SoundCategory.PLAYERS, 0.13F, 0.5F); } - if (entity.world.random.nextInt(50) == 0) { - stack.damage(1, entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); + if (entity.world.random.nextInt(20) == 0) { + stack.damage(1 + entity.world.random.nextInt(50), entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); } if (!getFlightType().canFly()) { @@ -420,9 +431,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti } private FlightType getFlightType() { - if (pony.getMaster().isCreative() || pony.getMaster().isSpectator()) { - return FlightType.CREATIVE; - } if (UItems.PEGASUS_AMULET.isApplicable(pony.getMaster())) { return FlightType.ARTIFICIAL; @@ -443,7 +451,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti FlightType type = getFlightType(); - entity.abilities.allowFlying = type.canFlyCreative(); + entity.abilities.allowFlying = type.canFlyCreative(entity); if (type.canFly() || entity.abilities.allowFlying) { entity.abilities.flying |= flying; diff --git a/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java index cd67f855..def19750 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java @@ -7,6 +7,7 @@ import javax.annotation.Nullable; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; +import com.minelittlepony.unicopia.particle.ParticleUtils; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.client.MinecraftClient; @@ -17,6 +18,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.item.ItemStack; +import net.minecraft.particle.ParticleTypes; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.StringVisitable; @@ -53,6 +55,14 @@ public class AmuletItem extends WearableItem { if (isChargable() && entity instanceof LivingEntity && ((LivingEntity) entity).getEquippedStack(EquipmentSlot.CHEST) == stack) { consumeEnergy(stack, drain); }*/ + + if (this == UItems.PEGASUS_AMULET + && entity.world.getTime() % 6 == 0 + && entity instanceof LivingEntity + && ((LivingEntity) entity).getEquippedStack(EquipmentSlot.CHEST) == stack + && isApplicable((LivingEntity)entity)) { + ParticleUtils.spawnParticles(ParticleTypes.COMPOSTER, entity, 1); + } } @Override