|
| 1 | +package com.minelittlepony.unicopia.entity.behaviour; |
| 2 | + |
| 3 | +import com.minelittlepony.unicopia.entity.Living; |
| 4 | +import com.minelittlepony.unicopia.entity.player.Pony; |
| 5 | +import net.minecraft.entity.Entity; |
| 6 | +import net.minecraft.entity.EntityPose; |
| 7 | +import net.minecraft.entity.effect.StatusEffectInstance; |
| 8 | +import net.minecraft.entity.effect.StatusEffects; |
| 9 | +import net.minecraft.entity.mob.BreezeEntity; |
| 10 | +import net.minecraft.entity.player.PlayerEntity; |
| 11 | +import net.minecraft.entity.projectile.BreezeWindChargeEntity; |
| 12 | +import net.minecraft.nbt.NbtCompound; |
| 13 | +import net.minecraft.sound.SoundEvents; |
| 14 | +import net.minecraft.util.math.MathHelper; |
| 15 | +import net.minecraft.util.math.Vec3d; |
| 16 | + |
| 17 | +public class BreezeBehaviour extends EntityBehaviour<BreezeEntity> { |
| 18 | + @Override |
| 19 | + public void update(Living<?> source, BreezeEntity entity, Disguise spell) { |
| 20 | + super.update(source, entity, spell); |
| 21 | + |
| 22 | + Entity src = source.asEntity(); |
| 23 | + |
| 24 | + if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + Vec3d vel = src.getVelocity(); |
| 29 | + |
| 30 | + if (vel.y < 0) { |
| 31 | + src.setVelocity(vel.multiply(1, 0.8, 1)); |
| 32 | + } |
| 33 | + |
| 34 | + if (!source.asEntity().isOnGround()) { |
| 35 | + vel = vel.multiply(1.2, 1, 1.2); |
| 36 | + |
| 37 | + src.setVelocity(MathHelper.clamp(vel.x, -0.5, 0.5), vel.y, MathHelper.clamp(vel.z, -0.5, 0.5)); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void update(Pony player, BreezeEntity entity, Disguise spell) { |
| 43 | + |
| 44 | + if (!player.isClient()) { |
| 45 | + |
| 46 | + if (!player.asEntity().hasStatusEffect(StatusEffects.JUMP_BOOST)) { |
| 47 | + player.asEntity().addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 10, 2, false, false)); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + NbtCompound tag = spell.getDisguise().getOrCreateTag(); |
| 52 | + |
| 53 | + boolean firing = tag.getBoolean("isFiring"); |
| 54 | + int fireballCooldown = tag.getInt("fireballCooldown"); |
| 55 | + int fireballsFired = tag.getInt("fireballsFired"); |
| 56 | + |
| 57 | + if (player.sneakingChanged()) { |
| 58 | + boolean sneaking = player.asEntity().isSneaking(); |
| 59 | + |
| 60 | + if (sneaking) { |
| 61 | + firing = true; |
| 62 | + fireballCooldown = 0; |
| 63 | + fireballsFired = 0; |
| 64 | + } else { |
| 65 | + firing = false; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + if (firing && fireballCooldown <= 0) { |
| 70 | + fireballsFired++; |
| 71 | + |
| 72 | + if (fireballsFired == 1) { |
| 73 | + fireballCooldown = 60; |
| 74 | + entity.setPose(EntityPose.SHOOTING); |
| 75 | + } else if (fireballsFired <= 4) { |
| 76 | + fireballCooldown = 6; |
| 77 | + } else { |
| 78 | + fireballCooldown = 100; |
| 79 | + fireballsFired = 0; |
| 80 | + entity.setPose(player.asEntity().isOnGround() ? EntityPose.STANDING : EntityPose.LONG_JUMPING); |
| 81 | + } |
| 82 | + |
| 83 | + if (fireballsFired > 0) { |
| 84 | + entity.playSound(SoundEvents.ENTITY_BREEZE_SHOOT, 1.5F, 1.0F); |
| 85 | + |
| 86 | + Vec3d rot = player.asEntity().getRotationVec(1); |
| 87 | + |
| 88 | + for (int i = 0; i < 1; ++i) { |
| 89 | + BreezeWindChargeEntity proj = new BreezeWindChargeEntity(entity, entity.getWorld()); |
| 90 | + proj.setVelocity(rot.add(entity.getRandom().nextGaussian() * 0.1, 0, entity.getRandom().nextGaussian() * 0.1)); |
| 91 | + proj.setPosition(proj.getX(), entity.getBodyY(0.5D) + 0.5D, proj.getZ()); |
| 92 | + entity.getWorld().spawnEntity(proj); |
| 93 | + } |
| 94 | + } |
| 95 | + } else if (!firing) { |
| 96 | + entity.setPose(player.asEntity().isOnGround() ? EntityPose.STANDING : EntityPose.LONG_JUMPING); |
| 97 | + } |
| 98 | + |
| 99 | + tag.putBoolean("isFiring", firing); |
| 100 | + tag.putInt("fireballCooldown", fireballCooldown); |
| 101 | + tag.putInt("fireballsFired", fireballsFired); |
| 102 | + } |
| 103 | +} |
0 commit comments