| 1 | package net.minecraft.world.entity.monster;
|
| 2 |
|
| 3 | import java.util.EnumSet;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 7 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 8 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 9 | import net.minecraft.server.level.ServerLevel;
|
| 10 | import net.minecraft.sounds.SoundEvent;
|
| 11 | import net.minecraft.sounds.SoundEvents;
|
| 12 | import net.minecraft.tags.DamageTypeTags;
|
| 13 | import net.minecraft.tags.FluidTags;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 | import net.minecraft.util.RandomSource;
|
| 16 | import net.minecraft.world.Difficulty;
|
| 17 | import net.minecraft.world.damagesource.DamageSource;
|
| 18 | import net.minecraft.world.damagesource.DamageTypes;
|
| 19 | import net.minecraft.world.entity.Entity;
|
| 20 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 21 | import net.minecraft.world.entity.EntityType;
|
| 22 | import net.minecraft.world.entity.LivingEntity;
|
| 23 | import net.minecraft.world.entity.MoverType;
|
| 24 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 25 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 26 | import net.minecraft.world.entity.ai.control.LookControl;
|
| 27 | import net.minecraft.world.entity.ai.control.MoveControl;
|
| 28 | import net.minecraft.world.entity.ai.goal.Goal;
|
| 29 | import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
| 30 | import net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal;
|
| 31 | import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
| 32 | import net.minecraft.world.entity.ai.goal.RandomStrollGoal;
|
| 33 | import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
| 34 | import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
| 35 | import net.minecraft.world.entity.ai.navigation.WaterBoundPathNavigation;
|
| 36 | import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
| 37 | import net.minecraft.world.entity.animal.axolotl.Axolotl;
|
| 38 | import net.minecraft.world.entity.animal.squid.Squid;
|
| 39 | import net.minecraft.world.entity.player.Player;
|
| 40 | import net.minecraft.world.level.Level;
|
| 41 | import net.minecraft.world.level.LevelAccessor;
|
| 42 | import net.minecraft.world.level.LevelReader;
|
| 43 | import net.minecraft.world.level.pathfinder.PathType;
|
| 44 | import net.minecraft.world.phys.Vec3;
|
| 45 | import org.jspecify.annotations.Nullable;
|
| 46 |
|
| 47 | public class Guardian extends Monster {
|
| 48 | protected static final int ATTACK_TIME = 80;
|
| 49 | private static final EntityDataAccessor<Boolean> DATA_ID_MOVING = SynchedEntityData.defineId(Guardian.class, EntityDataSerializers.BOOLEAN);
|
| 50 | private static final EntityDataAccessor<Integer> DATA_ID_ATTACK_TARGET = SynchedEntityData.defineId(Guardian.class, EntityDataSerializers.INT);
|
| 51 | private float clientSideTailAnimation;
|
| 52 | private float clientSideTailAnimationO;
|
| 53 | private float clientSideTailAnimationSpeed;
|
| 54 | private float clientSideSpikesAnimation;
|
| 55 | private float clientSideSpikesAnimationO;
|
| 56 | private @Nullable LivingEntity clientSideCachedAttackTarget;
|
| 57 | private int clientSideAttackTime;
|
| 58 | private boolean clientSideTouchedGround;
|
| 59 | protected @Nullable RandomStrollGoal randomStrollGoal;
|
| 60 |
|
| 61 | public Guardian(final EntityType<? extends Guardian> type, final Level level) {
|
| 62 | super(type, level);
|
| 63 | this.xpReward = 10;
|
| 64 | this.setPathfindingMalus(PathType.WATER, 0.0F);
|
| 65 | this.moveControl = new Guardian.GuardianMoveControl<>(this);
|
| 66 | this.clientSideTailAnimation = this.random.nextFloat();
|
| 67 | this.clientSideTailAnimationO = this.clientSideTailAnimation;
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected void registerGoals() {
|
| 72 | MoveTowardsRestrictionGoal goal = new MoveTowardsRestrictionGoal(this, 1.0);
|
| 73 | this.randomStrollGoal = new RandomStrollGoal(this, 1.0, 80);
|
| 74 | this.goalSelector.addGoal(4, new Guardian.GuardianAttackGoal(this));
|
| 75 | this.goalSelector.addGoal(5, goal);
|
| 76 | this.goalSelector.addGoal(7, this.randomStrollGoal);
|
| 77 | this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F));
|
| 78 | this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Guardian.class, 12.0F, 0.01F));
|
| 79 | this.goalSelector.addGoal(9, new RandomLookAroundGoal(this));
|
| 80 | this.randomStrollGoal.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
|
| 81 | goal.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
|
| 82 | this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, LivingEntity.class, 10, true, false, new Guardian.GuardianAttackSelector(this)));
|
| 83 | }
|
| 84 |
|
| 85 | public static AttributeSupplier.Builder createAttributes() {
|
| 86 | return Monster.createMonsterAttributes().add(Attributes.ATTACK_DAMAGE, 6.0).add(Attributes.MOVEMENT_SPEED, 0.5).add(Attributes.MAX_HEALTH, 30.0);
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | protected PathNavigation createNavigation(final Level level) {
|
| 91 | return new WaterBoundPathNavigation(this, level);
|
| 92 | }
|
| 93 |
|
| 94 | @Override
|
| 95 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 96 | super.defineSynchedData(entityData);
|
| 97 | entityData.define(DATA_ID_MOVING, false);
|
| 98 | entityData.define(DATA_ID_ATTACK_TARGET, 0);
|
| 99 | }
|
| 100 |
|
| 101 | public boolean isMoving() {
|
| 102 | return this.entityData.get(DATA_ID_MOVING);
|
| 103 | }
|
| 104 |
|
| 105 | public void setMoving(final boolean value) {
|
| 106 | this.entityData.set(DATA_ID_MOVING, value);
|
| 107 | }
|
| 108 |
|
| 109 | public int getAttackDuration() {
|
| 110 | return 80;
|
| 111 | }
|
| 112 |
|
| 113 | private void setActiveAttackTarget(final int entityId) {
|
| 114 | this.entityData.set(DATA_ID_ATTACK_TARGET, entityId);
|
| 115 | }
|
| 116 |
|
| 117 | public boolean hasActiveAttackTarget() {
|
| 118 | return this.entityData.get(DATA_ID_ATTACK_TARGET) != 0;
|
| 119 | }
|
| 120 |
|
| 121 | public @Nullable LivingEntity getActiveAttackTarget() {
|
| 122 | if (!this.hasActiveAttackTarget()) {
|
| 123 | return null;
|
| 124 | }
|
| 125 |
|
| 126 | if (this.level().isClientSide()) {
|
| 127 | if (this.clientSideCachedAttackTarget != null) {
|
| 128 | return this.clientSideCachedAttackTarget;
|
| 129 | } else if (this.level().getEntity(this.entityData.get(DATA_ID_ATTACK_TARGET)) instanceof LivingEntity livingEntity) {
|
| 130 | this.clientSideCachedAttackTarget = livingEntity;
|
| 131 | return this.clientSideCachedAttackTarget;
|
| 132 | } else {
|
| 133 | return null;
|
| 134 | }
|
| 135 | } else {
|
| 136 | return this.getTarget();
|
| 137 | }
|
| 138 | }
|
| 139 |
|
| 140 | @Override
|
| 141 | public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
|
| 142 | super.onSyncedDataUpdated(accessor);
|
| 143 | if (DATA_ID_ATTACK_TARGET.equals(accessor)) {
|
| 144 | this.clientSideAttackTime = 0;
|
| 145 | this.clientSideCachedAttackTarget = null;
|
| 146 | }
|
| 147 | }
|
| 148 |
|
| 149 | @Override
|
| 150 | public int getAmbientSoundInterval() {
|
| 151 | return 160;
|
| 152 | }
|
| 153 |
|
| 154 | @Override
|
| 155 | protected SoundEvent getAmbientSound() {
|
| 156 | return this.isInWater() ? SoundEvents.GUARDIAN_AMBIENT : SoundEvents.GUARDIAN_AMBIENT_LAND;
|
| 157 | }
|
| 158 |
|
| 159 | @Override
|
| 160 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 161 | return this.isInWater() ? SoundEvents.GUARDIAN_HURT : SoundEvents.GUARDIAN_HURT_LAND;
|
| 162 | }
|
| 163 |
|
| 164 | @Override
|
| 165 | protected SoundEvent getDeathSound() {
|
| 166 | return this.isInWater() ? SoundEvents.GUARDIAN_DEATH : SoundEvents.GUARDIAN_DEATH_LAND;
|
| 167 | }
|
| 168 |
|
| 169 | @Override
|
| 170 | protected Entity.MovementEmission getMovementEmission() {
|
| 171 | return Entity.MovementEmission.EVENTS;
|
| 172 | }
|
| 173 |
|
| 174 | @Override
|
| 175 | public float getWalkTargetValue(final BlockPos pos, final LevelReader level) {
|
| 176 | return level.getFluidState(pos).is(FluidTags.WATER) ? 10.0F + level.getPathfindingCostFromLightLevels(pos) : super.getWalkTargetValue(pos, level);
|
| 177 | }
|
| 178 |
|
| 179 | @Override
|
| 180 | public void aiStep() {
|
| 181 | if (this.isAlive()) {
|
| 182 | if (this.level().isClientSide()) {
|
| 183 | this.clientSideTailAnimationO = this.clientSideTailAnimation;
|
| 184 | if (!this.isInWater()) {
|
| 185 | this.clientSideTailAnimationSpeed = 2.0F;
|
| 186 | Vec3 movement = this.getDeltaMovement();
|
| 187 | if (movement.y > 0.0 && this.clientSideTouchedGround && !this.isSilent()) {
|
| 188 | this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), this.getFlopSound(), this.getSoundSource(), 1.0F, 1.0F, false);
|
| 189 | }
|
| 190 |
|
| 191 | this.clientSideTouchedGround = movement.y < 0.0 && this.level().loadedAndEntityCanStandOn(this.blockPosition().below(), this);
|
| 192 | } else if (this.isMoving()) {
|
| 193 | if (this.clientSideTailAnimationSpeed < 0.5F) {
|
| 194 | this.clientSideTailAnimationSpeed = 4.0F;
|
| 195 | } else {
|
| 196 | this.clientSideTailAnimationSpeed = this.clientSideTailAnimationSpeed + (0.5F - this.clientSideTailAnimationSpeed) * 0.1F;
|
| 197 | }
|
| 198 | } else {
|
| 199 | this.clientSideTailAnimationSpeed = this.clientSideTailAnimationSpeed + (0.125F - this.clientSideTailAnimationSpeed) * 0.2F;
|
| 200 | }
|
| 201 |
|
| 202 | this.clientSideTailAnimation = this.clientSideTailAnimation + this.clientSideTailAnimationSpeed;
|
| 203 | this.clientSideSpikesAnimationO = this.clientSideSpikesAnimation;
|
| 204 | if (!this.isInWater()) {
|
| 205 | this.clientSideSpikesAnimation = this.random.nextFloat();
|
| 206 | } else if (this.isMoving()) {
|
| 207 | this.clientSideSpikesAnimation = this.clientSideSpikesAnimation + (0.0F - this.clientSideSpikesAnimation) * 0.25F;
|
| 208 | } else {
|
| 209 | this.clientSideSpikesAnimation = this.clientSideSpikesAnimation + (1.0F - this.clientSideSpikesAnimation) * 0.06F;
|
| 210 | }
|
| 211 |
|
| 212 | if (this.isMoving() && this.isInWater()) {
|
| 213 | Vec3 viewVector = this.getViewVector(0.0F);
|
| 214 |
|
| 215 | for (int i = 0; i < 2; i++) {
|
| 216 | this.level()
|
| 217 | .addParticle(
|
| 218 | ParticleTypes.BUBBLE,
|
| 219 | this.getRandomX(0.5) - viewVector.x * 1.5,
|
| 220 | this.getRandomY() - viewVector.y * 1.5,
|
| 221 | this.getRandomZ(0.5) - viewVector.z * 1.5,
|
| 222 | 0.0,
|
| 223 | 0.0,
|
| 224 | 0.0
|
| 225 | );
|
| 226 | }
|
| 227 | }
|
| 228 |
|
| 229 | if (this.hasActiveAttackTarget()) {
|
| 230 | if (this.clientSideAttackTime < this.getAttackDuration()) {
|
| 231 | this.clientSideAttackTime++;
|
| 232 | }
|
| 233 |
|
| 234 | LivingEntity attackTarget = this.getActiveAttackTarget();
|
| 235 | if (attackTarget != null) {
|
| 236 | this.getLookControl().setLookAt(attackTarget, 90.0F, 90.0F);
|
| 237 | this.getLookControl().tick();
|
| 238 | double at = this.getAttackAnimationScale(0.0F);
|
| 239 | double dx = attackTarget.getX() - this.getX();
|
| 240 | double dy = attackTarget.getY(0.5) - this.getEyeY();
|
| 241 | double dz = attackTarget.getZ() - this.getZ();
|
| 242 | double dd = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
| 243 | dx /= dd;
|
| 244 | dy /= dd;
|
| 245 | dz /= dd;
|
| 246 | double dist = this.random.nextDouble();
|
| 247 |
|
| 248 | while (dist < dd) {
|
| 249 | dist += 1.8 - at + this.random.nextDouble() * (1.7 - at);
|
| 250 | this.level().addParticle(ParticleTypes.BUBBLE, this.getX() + dx * dist, this.getEyeY() + dy * dist, this.getZ() + dz * dist, 0.0, 0.0, 0.0);
|
| 251 | }
|
| 252 | }
|
| 253 | }
|
| 254 | }
|
| 255 |
|
| 256 | if (this.isInWater()) {
|
| 257 | this.setAirSupply(300);
|
| 258 | } else if (this.onGround()) {
|
| 259 | this.setDeltaMovement(this.getDeltaMovement().add((this.random.nextFloat() * 2.0F - 1.0F) * 0.4F, 0.5, (this.random.nextFloat() * 2.0F - 1.0F) * 0.4F));
|
| 260 | this.setYRot(this.random.nextFloat() * 360.0F);
|
| 261 | this.setOnGround(false);
|
| 262 | this.needsSync = true;
|
| 263 | }
|
| 264 |
|
| 265 | if (this.hasActiveAttackTarget()) {
|
| 266 | this.setYRot(this.yHeadRot);
|
| 267 | }
|
| 268 | }
|
| 269 |
|
| 270 | super.aiStep();
|
| 271 | }
|
| 272 |
|
| 273 | protected SoundEvent getFlopSound() {
|
| 274 | return SoundEvents.GUARDIAN_FLOP;
|
| 275 | }
|
| 276 |
|
| 277 | public float getTailAnimation(final float a) {
|
| 278 | return Mth.lerp(a, this.clientSideTailAnimationO, this.clientSideTailAnimation);
|
| 279 | }
|
| 280 |
|
| 281 | public float getSpikesAnimation(final float a) {
|
| 282 | return Mth.lerp(a, this.clientSideSpikesAnimationO, this.clientSideSpikesAnimation);
|
| 283 | }
|
| 284 |
|
| 285 | public float getAttackAnimationScale(final float a) {
|
| 286 | return (this.clientSideAttackTime + a) / this.getAttackDuration();
|
| 287 | }
|
| 288 |
|
| 289 | public float getClientSideAttackTime() {
|
| 290 | return this.clientSideAttackTime;
|
| 291 | }
|
| 292 |
|
| 293 | @Override
|
| 294 | public boolean checkSpawnObstruction(final LevelReader level) {
|
| 295 | return level.isUnobstructed(this);
|
| 296 | }
|
| 297 |
|
| 298 | public static boolean checkGuardianSpawnRules(
|
| 299 | final EntityType<? extends Guardian> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
|
| 300 | ) {
|
| 301 | return (random.nextInt(20) == 0 || !level.canSeeSkyFromBelowWater(pos))
|
| 302 | && level.getDifficulty() != Difficulty.PEACEFUL
|
| 303 | && (EntitySpawnReason.isSpawner(spawnReason) || level.getFluidState(pos).is(FluidTags.WATER))
|
| 304 | && level.getFluidState(pos.below()).is(FluidTags.WATER);
|
| 305 | }
|
| 306 |
|
| 307 | @Override
|
| 308 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 309 | if (!this.isMoving()
|
| 310 | && !source.is(DamageTypeTags.AVOIDS_GUARDIAN_THORNS)
|
| 311 | && !source.is(DamageTypes.THORNS)
|
| 312 | && source.getDirectEntity() instanceof LivingEntity cause) {
|
| 313 | cause.hurtServer(level, this.damageSources().thorns(this), 2.0F);
|
| 314 | }
|
| 315 |
|
| 316 | if (this.randomStrollGoal != null) {
|
| 317 | this.randomStrollGoal.trigger();
|
| 318 | }
|
| 319 |
|
| 320 | return super.hurtServer(level, source, damage);
|
| 321 | }
|
| 322 |
|
| 323 | @Override
|
| 324 | public int getMaxHeadXRot() {
|
| 325 | return 180;
|
| 326 | }
|
| 327 |
|
| 328 | @Override
|
| 329 | protected void travelInWater(final Vec3 input, final double baseGravity, final boolean isFalling, final double oldY) {
|
| 330 | this.moveRelative(0.1F, input);
|
| 331 | this.move(MoverType.SELF, this.getDeltaMovement());
|
| 332 | this.setDeltaMovement(this.getDeltaMovement().scale(0.9));
|
| 333 | if (!this.isMoving() && this.getTarget() == null) {
|
| 334 | this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.005, 0.0));
|
| 335 | }
|
| 336 | }
|
| 337 |
|
| 338 | private static class GuardianAttackGoal extends Goal {
|
| 339 | private final Guardian guardian;
|
| 340 | private int attackTime;
|
| 341 | private final boolean elder;
|
| 342 |
|
| 343 | public GuardianAttackGoal(final Guardian guardian) {
|
| 344 | this.guardian = guardian;
|
| 345 | this.elder = guardian instanceof ElderGuardian;
|
| 346 | this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
|
| 347 | }
|
| 348 |
|
| 349 | @Override
|
| 350 | public boolean canUse() {
|
| 351 | LivingEntity target = this.guardian.getTarget();
|
| 352 | return target != null && target.isAlive();
|
| 353 | }
|
| 354 |
|
| 355 | @Override
|
| 356 | public boolean canContinueToUse() {
|
| 357 | return super.canContinueToUse() && (this.elder || this.guardian.getTarget() != null && this.guardian.distanceToSqr(this.guardian.getTarget()) > 9.0);
|
| 358 | }
|
| 359 |
|
| 360 | @Override
|
| 361 | public void start() {
|
| 362 | this.attackTime = -10;
|
| 363 | this.guardian.getNavigation().stop();
|
| 364 | LivingEntity target = this.guardian.getTarget();
|
| 365 | if (target != null) {
|
| 366 | this.guardian.getLookControl().setLookAt(target, 90.0F, 90.0F);
|
| 367 | }
|
| 368 |
|
| 369 | this.guardian.needsSync = true;
|
| 370 | }
|
| 371 |
|
| 372 | @Override
|
| 373 | public void stop() {
|
| 374 | this.guardian.setActiveAttackTarget(0);
|
| 375 | this.guardian.setTarget(null);
|
| 376 | this.guardian.randomStrollGoal.trigger();
|
| 377 | }
|
| 378 |
|
| 379 | @Override
|
| 380 | public boolean requiresUpdateEveryTick() {
|
| 381 | return true;
|
| 382 | }
|
| 383 |
|
| 384 | @Override
|
| 385 | public void tick() {
|
| 386 | LivingEntity target = this.guardian.getTarget();
|
| 387 | if (target != null) {
|
| 388 | this.guardian.getNavigation().stop();
|
| 389 | this.guardian.getLookControl().setLookAt(target, 90.0F, 90.0F);
|
| 390 | if (!this.guardian.hasLineOfSight(target)) {
|
| 391 | this.guardian.setTarget(null);
|
| 392 | } else {
|
| 393 | this.attackTime++;
|
| 394 | if (this.attackTime == 0) {
|
| 395 | this.guardian.setActiveAttackTarget(target.getId());
|
| 396 | if (!this.guardian.isSilent()) {
|
| 397 | this.guardian.level().broadcastEntityEvent(this.guardian, (byte)21);
|
| 398 | }
|
| 399 | } else if (this.attackTime >= this.guardian.getAttackDuration()) {
|
| 400 | float magicDamage = 1.0F;
|
| 401 | if (this.guardian.level().getDifficulty() == Difficulty.HARD) {
|
| 402 | magicDamage += 2.0F;
|
| 403 | }
|
| 404 |
|
| 405 | if (this.elder) {
|
| 406 | magicDamage += 2.0F;
|
| 407 | }
|
| 408 |
|
| 409 | ServerLevel serverLevel = getServerLevel(this.guardian);
|
| 410 | target.hurtServer(serverLevel, this.guardian.damageSources().indirectMagic(this.guardian, this.guardian), magicDamage);
|
| 411 | this.guardian.doHurtTarget(serverLevel, target);
|
| 412 | this.guardian.setTarget(null);
|
| 413 | }
|
| 414 |
|
| 415 | super.tick();
|
| 416 | }
|
| 417 | }
|
| 418 | }
|
| 419 | }
|
| 420 |
|
| 421 | private static class GuardianAttackSelector implements TargetingConditions.Selector {
|
| 422 | private final Guardian guardian;
|
| 423 |
|
| 424 | public GuardianAttackSelector(final Guardian guardian) {
|
| 425 | this.guardian = guardian;
|
| 426 | }
|
| 427 |
|
| 428 | @Override
|
| 429 | public boolean test(final @Nullable LivingEntity target, final ServerLevel level) {
|
| 430 | return (target instanceof Player || target instanceof Squid || target instanceof Axolotl) && target.distanceToSqr(this.guardian) > 9.0;
|
| 431 | }
|
| 432 | }
|
| 433 |
|
| 434 | private static class GuardianMoveControl<T extends Guardian> extends MoveControl<T> {
|
| 435 | public GuardianMoveControl(final T guardian) {
|
| 436 | super(guardian);
|
| 437 | }
|
| 438 |
|
| 439 | @Override
|
| 440 | public void tick() {
|
| 441 | if (this.operation == MoveControl.Operation.MOVE_TO && !this.mob.getNavigation().isDone()) {
|
| 442 | Vec3 delta = new Vec3(this.wantedX - this.mob.getX(), this.wantedY - this.mob.getY(), this.wantedZ - this.mob.getZ());
|
| 443 | double length = delta.length();
|
| 444 | double xd = delta.x / length;
|
| 445 | double yd = delta.y / length;
|
| 446 | double zd = delta.z / length;
|
| 447 | float yRotD = (float)(Mth.atan2(delta.z, delta.x) * 180.0F / (float)Math.PI) - 90.0F;
|
| 448 | this.mob.setYRot(this.rotlerp(this.mob.getYRot(), yRotD, 90.0F));
|
| 449 | this.mob.yBodyRot = this.mob.getYRot();
|
| 450 | float targetSpeed = (float)(this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED));
|
| 451 | float newSpeed = Mth.lerp(0.125F, this.mob.getSpeed(), targetSpeed);
|
| 452 | this.mob.setSpeed(newSpeed);
|
| 453 | double push = Math.sin((this.mob.tickCount + this.mob.getId()) * 0.5) * 0.05;
|
| 454 | double cos = Math.cos(this.mob.getYRot() * (float) (Math.PI / 180.0));
|
| 455 | double sin = Math.sin(this.mob.getYRot() * (float) (Math.PI / 180.0));
|
| 456 | double yPush = Math.sin((this.mob.tickCount + this.mob.getId()) * 0.75) * 0.05;
|
| 457 | this.mob.setDeltaMovement(this.mob.getDeltaMovement().add(push * cos, yPush * (sin + cos) * 0.25 + newSpeed * yd * 0.1, push * sin));
|
| 458 | LookControl control = this.mob.getLookControl();
|
| 459 | double newLookX = this.mob.getX() + xd * 2.0;
|
| 460 | double newLookY = this.mob.getEyeY() + yd / length;
|
| 461 | double newLookZ = this.mob.getZ() + zd * 2.0;
|
| 462 | double oldLookX = control.getWantedX();
|
| 463 | double oldLookY = control.getWantedY();
|
| 464 | double oldLookZ = control.getWantedZ();
|
| 465 | if (!control.isLookingAtTarget()) {
|
| 466 | oldLookX = newLookX;
|
| 467 | oldLookY = newLookY;
|
| 468 | oldLookZ = newLookZ;
|
| 469 | }
|
| 470 |
|
| 471 | this.mob
|
| 472 | .getLookControl()
|
| 473 | .setLookAt(Mth.lerp(0.125, oldLookX, newLookX), Mth.lerp(0.125, oldLookY, newLookY), Mth.lerp(0.125, oldLookZ, newLookZ), 10.0F, 40.0F);
|
| 474 | this.mob.setMoving(true);
|
| 475 | } else {
|
| 476 | this.mob.setSpeed(0.0F);
|
| 477 | this.mob.setMoving(false);
|
| 478 | }
|
| 479 | }
|
| 480 | }
|
| 481 | }
|
| 482 |
|