| 1 | package net.minecraft.world.entity.monster.creaking;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Optional;
|
| 5 | import net.minecraft.core.BlockPos;
|
| 6 | import net.minecraft.core.Vec3i;
|
| 7 | import net.minecraft.core.particles.BlockParticleOption;
|
| 8 | import net.minecraft.core.particles.ParticleTypes;
|
| 9 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 10 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 11 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 12 | import net.minecraft.server.level.ServerLevel;
|
| 13 | import net.minecraft.sounds.SoundEvent;
|
| 14 | import net.minecraft.sounds.SoundEvents;
|
| 15 | import net.minecraft.tags.DamageTypeTags;
|
| 16 | import net.minecraft.util.profiling.Profiler;
|
| 17 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 18 | import net.minecraft.world.damagesource.DamageSource;
|
| 19 | import net.minecraft.world.entity.AnimationState;
|
| 20 | import net.minecraft.world.entity.Entity;
|
| 21 | import net.minecraft.world.entity.EntityEvent;
|
| 22 | import net.minecraft.world.entity.EntityType;
|
| 23 | import net.minecraft.world.entity.LivingEntity;
|
| 24 | import net.minecraft.world.entity.ai.Brain;
|
| 25 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 26 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 27 | import net.minecraft.world.entity.ai.control.BodyRotationControl;
|
| 28 | import net.minecraft.world.entity.ai.control.JumpControl;
|
| 29 | import net.minecraft.world.entity.ai.control.LookControl;
|
| 30 | import net.minecraft.world.entity.ai.control.MoveControl;
|
| 31 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 32 | import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
|
| 33 | import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
| 34 | import net.minecraft.world.entity.ai.sensing.SensorType;
|
| 35 | import net.minecraft.world.entity.monster.Monster;
|
| 36 | import net.minecraft.world.entity.player.Player;
|
| 37 | import net.minecraft.world.entity.projectile.Projectile;
|
| 38 | import net.minecraft.world.level.Level;
|
| 39 | import net.minecraft.world.level.LevelReader;
|
| 40 | import net.minecraft.world.level.block.Blocks;
|
| 41 | import net.minecraft.world.level.block.CreakingHeartBlock;
|
| 42 | import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity;
|
| 43 | import net.minecraft.world.level.block.state.BlockState;
|
| 44 | import net.minecraft.world.level.block.state.properties.CreakingHeartState;
|
| 45 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 46 | import net.minecraft.world.level.pathfinder.PathFinder;
|
| 47 | import net.minecraft.world.level.pathfinder.PathType;
|
| 48 | import net.minecraft.world.level.pathfinder.PathfindingContext;
|
| 49 | import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
|
| 50 | import net.minecraft.world.level.storage.ValueInput;
|
| 51 | import net.minecraft.world.level.storage.ValueOutput;
|
| 52 | import net.minecraft.world.phys.AABB;
|
| 53 | import net.minecraft.world.phys.Vec3;
|
| 54 | import org.jspecify.annotations.Nullable;
|
| 55 |
|
| 56 | public class Creaking extends Monster {
|
| 57 | private static final EntityDataAccessor<Boolean> CAN_MOVE = SynchedEntityData.defineId(Creaking.class, EntityDataSerializers.BOOLEAN);
|
| 58 | private static final EntityDataAccessor<Boolean> IS_ACTIVE = SynchedEntityData.defineId(Creaking.class, EntityDataSerializers.BOOLEAN);
|
| 59 | private static final EntityDataAccessor<Boolean> IS_TEARING_DOWN = SynchedEntityData.defineId(Creaking.class, EntityDataSerializers.BOOLEAN);
|
| 60 | private static final EntityDataAccessor<Optional<BlockPos>> HOME_POS = SynchedEntityData.defineId(Creaking.class, EntityDataSerializers.OPTIONAL_BLOCK_POS);
|
| 61 | private static final Brain.Provider<Creaking> BRAIN_PROVIDER = Brain.provider(
|
| 62 | List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_PLAYERS), CreakingAi::getActivities
|
| 63 | );
|
| 64 | private static final int ATTACK_ANIMATION_DURATION = 15;
|
| 65 | private static final int MAX_HEALTH = 1;
|
| 66 | private static final float ATTACK_DAMAGE = 3.0F;
|
| 67 | private static final float FOLLOW_RANGE = 32.0F;
|
| 68 | private static final float ACTIVATION_RANGE_SQ = 144.0F;
|
| 69 | public static final int ATTACK_INTERVAL = 40;
|
| 70 | private static final float MOVEMENT_SPEED_WHEN_FIGHTING = 0.4F;
|
| 71 | public static final float SPEED_MULTIPLIER_WHEN_IDLING = 0.3F;
|
| 72 | public static final int CREAKING_ORANGE = 16545810;
|
| 73 | public static final int CREAKING_GRAY = 6250335;
|
| 74 | public static final int INVULNERABILITY_ANIMATION_DURATION = 8;
|
| 75 | public static final int TWITCH_DEATH_DURATION = 45;
|
| 76 | private static final int MAX_PLAYER_STUCK_COUNTER = 4;
|
| 77 | private int attackAnimationRemainingTicks;
|
| 78 | public final AnimationState attackAnimationState = new AnimationState();
|
| 79 | public final AnimationState invulnerabilityAnimationState = new AnimationState();
|
| 80 | public final AnimationState deathAnimationState = new AnimationState();
|
| 81 | private int invulnerabilityAnimationRemainingTicks;
|
| 82 | private boolean eyesGlowing;
|
| 83 | private int nextFlickerTime;
|
| 84 | private int playerStuckCounter;
|
| 85 |
|
| 86 | public Creaking(final EntityType<? extends Creaking> type, final Level level) {
|
| 87 | super(type, level);
|
| 88 | this.lookControl = new Creaking.CreakingLookControl(this);
|
| 89 | this.moveControl = new Creaking.CreakingMoveControl<>(this);
|
| 90 | this.jumpControl = new Creaking.CreakingJumpControl(this);
|
| 91 | GroundPathNavigation navigation = (GroundPathNavigation)this.getNavigation();
|
| 92 | navigation.setCanFloat(true);
|
| 93 | this.xpReward = 0;
|
| 94 | }
|
| 95 |
|
| 96 | public void setTransient(final BlockPos pos) {
|
| 97 | this.setHomePos(pos);
|
| 98 | this.setPathfindingMalus(PathType.DAMAGING, 8.0F);
|
| 99 | this.setPathfindingMalus(PathType.POWDER_SNOW, 8.0F);
|
| 100 | this.setPathfindingMalus(PathType.LAVA, 8.0F);
|
| 101 | this.setPathfindingMalus(PathType.FIRE, 0.0F);
|
| 102 | this.setPathfindingMalus(PathType.FIRE_IN_NEIGHBOR, 0.0F);
|
| 103 | }
|
| 104 |
|
| 105 | public boolean isHeartBound() {
|
| 106 | return this.getHomePos() != null;
|
| 107 | }
|
| 108 |
|
| 109 | @Override
|
| 110 | protected BodyRotationControl createBodyControl() {
|
| 111 | return new Creaking.CreakingBodyRotationControl(this);
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | protected Brain<Creaking> makeBrain(final Brain.Packed packedBrain) {
|
| 116 | return BRAIN_PROVIDER.makeBrain(this, packedBrain);
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 121 | super.defineSynchedData(entityData);
|
| 122 | entityData.define(CAN_MOVE, true);
|
| 123 | entityData.define(IS_ACTIVE, false);
|
| 124 | entityData.define(IS_TEARING_DOWN, false);
|
| 125 | entityData.define(HOME_POS, Optional.empty());
|
| 126 | }
|
| 127 |
|
| 128 | public static AttributeSupplier.Builder createAttributes() {
|
| 129 | return Monster.createMonsterAttributes()
|
| 130 | .add(Attributes.MAX_HEALTH, 1.0)
|
| 131 | .add(Attributes.MOVEMENT_SPEED, 0.4F)
|
| 132 | .add(Attributes.ATTACK_DAMAGE, 3.0)
|
| 133 | .add(Attributes.FOLLOW_RANGE, 32.0)
|
| 134 | .add(Attributes.STEP_HEIGHT, 1.0625);
|
| 135 | }
|
| 136 |
|
| 137 | public boolean canMove() {
|
| 138 | return this.entityData.get(CAN_MOVE);
|
| 139 | }
|
| 140 |
|
| 141 | @Override
|
| 142 | public boolean doHurtTarget(final ServerLevel level, final Entity target) {
|
| 143 | if (!(target instanceof LivingEntity)) {
|
| 144 | return false;
|
| 145 | }
|
| 146 |
|
| 147 | this.attackAnimationRemainingTicks = 15;
|
| 148 | this.level().broadcastEntityEvent(this, (byte)4);
|
| 149 | return super.doHurtTarget(level, target);
|
| 150 | }
|
| 151 |
|
| 152 | @Override
|
| 153 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 154 | BlockPos homePos = this.getHomePos();
|
| 155 | if (homePos == null || source.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
|
| 156 | return super.hurtServer(level, source, damage);
|
| 157 | }
|
| 158 |
|
| 159 | if (!this.isInvulnerableTo(level, source) && this.invulnerabilityAnimationRemainingTicks <= 0 && !this.isDeadOrDying()) {
|
| 160 | Player responsiblePlayer = this.blameSourceForDamage(source);
|
| 161 | Entity directEntity = source.getDirectEntity();
|
| 162 | if (!(directEntity instanceof LivingEntity) && !(directEntity instanceof Projectile) && responsiblePlayer == null) {
|
| 163 | return false;
|
| 164 | }
|
| 165 |
|
| 166 | this.invulnerabilityAnimationRemainingTicks = 8;
|
| 167 | this.level().broadcastEntityEvent(this, (byte)66);
|
| 168 | this.gameEvent(GameEvent.ENTITY_ACTION);
|
| 169 | if (this.level().getBlockEntity(homePos) instanceof CreakingHeartBlockEntity creakingHeartBlockEntity && creakingHeartBlockEntity.isProtector(this)) {
|
| 170 | if (responsiblePlayer != null) {
|
| 171 | creakingHeartBlockEntity.creakingHurt();
|
| 172 | }
|
| 173 |
|
| 174 | this.playHurtSound(source);
|
| 175 | }
|
| 176 |
|
| 177 | return true;
|
| 178 | } else {
|
| 179 | return false;
|
| 180 | }
|
| 181 | }
|
| 182 |
|
| 183 | public Player blameSourceForDamage(final DamageSource source) {
|
| 184 | this.resolveMobResponsibleForDamage(source);
|
| 185 | return this.resolvePlayerResponsibleForDamage(source);
|
| 186 | }
|
| 187 |
|
| 188 | @Override
|
| 189 | public boolean isPushable() {
|
| 190 | return super.isPushable() && this.canMove();
|
| 191 | }
|
| 192 |
|
| 193 | @Override
|
| 194 | public void push(final double xa, final double ya, final double za) {
|
| 195 | if (this.canMove()) {
|
| 196 | super.push(xa, ya, za);
|
| 197 | }
|
| 198 | }
|
| 199 |
|
| 200 | @Override
|
| 201 | public Brain<Creaking> getBrain() {
|
| 202 | return super.getBrain();
|
| 203 | }
|
| 204 |
|
| 205 | @Override
|
| 206 | protected void customServerAiStep(final ServerLevel level) {
|
| 207 | ProfilerFiller profiler = Profiler.get();
|
| 208 | profiler.push("creakingBrain");
|
| 209 | this.getBrain().tick((ServerLevel)this.level(), this);
|
| 210 | profiler.pop();
|
| 211 | CreakingAi.updateActivity(this);
|
| 212 | }
|
| 213 |
|
| 214 | @Override
|
| 215 | public void aiStep() {
|
| 216 | if (this.invulnerabilityAnimationRemainingTicks > 0) {
|
| 217 | this.invulnerabilityAnimationRemainingTicks--;
|
| 218 | }
|
| 219 |
|
| 220 | if (this.attackAnimationRemainingTicks > 0) {
|
| 221 | this.attackAnimationRemainingTicks--;
|
| 222 | }
|
| 223 |
|
| 224 | if (!this.level().isClientSide()) {
|
| 225 | boolean canMove = this.entityData.get(CAN_MOVE);
|
| 226 | boolean nowCanMove = this.checkCanMove();
|
| 227 | if (nowCanMove != canMove) {
|
| 228 | this.gameEvent(GameEvent.ENTITY_ACTION);
|
| 229 | if (nowCanMove) {
|
| 230 | this.makeSound(SoundEvents.CREAKING_UNFREEZE);
|
| 231 | } else {
|
| 232 | this.stopInPlace();
|
| 233 | this.makeSound(SoundEvents.CREAKING_FREEZE);
|
| 234 | }
|
| 235 | }
|
| 236 |
|
| 237 | this.entityData.set(CAN_MOVE, nowCanMove);
|
| 238 | }
|
| 239 |
|
| 240 | super.aiStep();
|
| 241 | }
|
| 242 |
|
| 243 | @Override
|
| 244 | public void tick() {
|
| 245 | if (!this.level().isClientSide()) {
|
| 246 | BlockPos homePos = this.getHomePos();
|
| 247 | if (homePos != null) {
|
| 248 | boolean hasProtectionFromCreakingHeart = this.level().getBlockEntity(homePos) instanceof CreakingHeartBlockEntity creakingHeartBlockEntity
|
| 249 | && creakingHeartBlockEntity.isProtector(this);
|
| 250 | if (!hasProtectionFromCreakingHeart) {
|
| 251 | this.setHealth(0.0F);
|
| 252 | }
|
| 253 | }
|
| 254 | }
|
| 255 |
|
| 256 | super.tick();
|
| 257 | if (this.level().isClientSide()) {
|
| 258 | this.setupAnimationStates();
|
| 259 | this.checkEyeBlink();
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | @Override
|
| 264 | protected void tickDeath() {
|
| 265 | if (this.isHeartBound() && this.isTearingDown()) {
|
| 266 | this.deathTime++;
|
| 267 | if (!this.level().isClientSide() && this.deathTime > 45 && !this.isRemoved()) {
|
| 268 | this.tearDown();
|
| 269 | }
|
| 270 | } else {
|
| 271 | super.tickDeath();
|
| 272 | }
|
| 273 | }
|
| 274 |
|
| 275 | @Override
|
| 276 | protected void updateWalkAnimation(final float distance) {
|
| 277 | float targetSpeed = Math.min(distance * 25.0F, 3.0F);
|
| 278 | this.walkAnimation.update(targetSpeed, 0.4F, 1.0F);
|
| 279 | }
|
| 280 |
|
| 281 | private void setupAnimationStates() {
|
| 282 | this.attackAnimationState.animateWhen(this.attackAnimationRemainingTicks > 0, this.tickCount);
|
| 283 | this.invulnerabilityAnimationState.animateWhen(this.invulnerabilityAnimationRemainingTicks > 0, this.tickCount);
|
| 284 | this.deathAnimationState.animateWhen(this.isTearingDown(), this.tickCount);
|
| 285 | }
|
| 286 |
|
| 287 | public void tearDown() {
|
| 288 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 289 | AABB box = this.getBoundingBox();
|
| 290 | Vec3 center = box.getCenter();
|
| 291 | double xSpread = box.getXsize() * 0.3;
|
| 292 | double ySpread = box.getYsize() * 0.3;
|
| 293 | double zSpread = box.getZsize() * 0.3;
|
| 294 | serverLevel.sendParticles(
|
| 295 | new BlockParticleOption(ParticleTypes.BLOCK_CRUMBLE, Blocks.PALE_OAK_WOOD.defaultBlockState()),
|
| 296 | center.x,
|
| 297 | center.y,
|
| 298 | center.z,
|
| 299 | 100,
|
| 300 | xSpread,
|
| 301 | ySpread,
|
| 302 | zSpread,
|
| 303 | 0.0
|
| 304 | );
|
| 305 | serverLevel.sendParticles(
|
| 306 | new BlockParticleOption(ParticleTypes.BLOCK_CRUMBLE, Blocks.CREAKING_HEART.defaultBlockState().setValue(CreakingHeartBlock.STATE, CreakingHeartState.AWAKE)),
|
| 307 | center.x,
|
| 308 | center.y,
|
| 309 | center.z,
|
| 310 | 10,
|
| 311 | xSpread,
|
| 312 | ySpread,
|
| 313 | zSpread,
|
| 314 | 0.0
|
| 315 | );
|
| 316 | }
|
| 317 |
|
| 318 | this.makeSound(this.getDeathSound());
|
| 319 | this.remove(Entity.RemovalReason.DISCARDED);
|
| 320 | }
|
| 321 |
|
| 322 | public void creakingDeathEffects(final DamageSource source) {
|
| 323 | this.blameSourceForDamage(source);
|
| 324 | this.die(source);
|
| 325 | this.makeSound(SoundEvents.CREAKING_TWITCH);
|
| 326 | }
|
| 327 |
|
| 328 | @Override
|
| 329 | public void handleEntityEvent(final @EntityEvent.Value byte id) {
|
| 330 | if (id == 66) {
|
| 331 | this.invulnerabilityAnimationRemainingTicks = 8;
|
| 332 | this.playHurtSound(this.damageSources().generic());
|
| 333 | } else if (id == 4) {
|
| 334 | this.attackAnimationRemainingTicks = 15;
|
| 335 | this.playAttackSound();
|
| 336 | } else {
|
| 337 | super.handleEntityEvent(id);
|
| 338 | }
|
| 339 | }
|
| 340 |
|
| 341 | @Override
|
| 342 | public boolean fireImmune() {
|
| 343 | return this.isHeartBound() || super.fireImmune();
|
| 344 | }
|
| 345 |
|
| 346 | @Override
|
| 347 | public boolean canUsePortal(final boolean ignorePassenger) {
|
| 348 | return !this.isHeartBound() && super.canUsePortal(ignorePassenger);
|
| 349 | }
|
| 350 |
|
| 351 | @Override
|
| 352 | protected PathNavigation createNavigation(final Level level) {
|
| 353 | return new Creaking.CreakingPathNavigation(this, level);
|
| 354 | }
|
| 355 |
|
| 356 | public boolean playerIsStuckInYou() {
|
| 357 | List<Player> players = this.brain.getMemory(MemoryModuleType.NEAREST_PLAYERS).orElse(List.of());
|
| 358 | if (players.isEmpty()) {
|
| 359 | this.playerStuckCounter = 0;
|
| 360 | return false;
|
| 361 | }
|
| 362 |
|
| 363 | AABB ownBox = this.getBoundingBox();
|
| 364 |
|
| 365 | for (Player player : players) {
|
| 366 | if (ownBox.contains(player.getEyePosition())) {
|
| 367 | this.playerStuckCounter++;
|
| 368 | return this.playerStuckCounter > 4;
|
| 369 | }
|
| 370 | }
|
| 371 |
|
| 372 | this.playerStuckCounter = 0;
|
| 373 | return false;
|
| 374 | }
|
| 375 |
|
| 376 | @Override
|
| 377 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 378 | super.readAdditionalSaveData(input);
|
| 379 | input.read("home_pos", BlockPos.CODEC).ifPresent(this::setTransient);
|
| 380 | }
|
| 381 |
|
| 382 | @Override
|
| 383 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 384 | super.addAdditionalSaveData(output);
|
| 385 | output.storeNullable("home_pos", BlockPos.CODEC, this.getHomePos());
|
| 386 | }
|
| 387 |
|
| 388 | public void setHomePos(final BlockPos pos) {
|
| 389 | this.entityData.set(HOME_POS, Optional.of(pos));
|
| 390 | }
|
| 391 |
|
| 392 | public @Nullable BlockPos getHomePos() {
|
| 393 | return this.entityData.get(HOME_POS).orElse(null);
|
| 394 | }
|
| 395 |
|
| 396 | public void setTearingDown() {
|
| 397 | this.entityData.set(IS_TEARING_DOWN, true);
|
| 398 | }
|
| 399 |
|
| 400 | public boolean isTearingDown() {
|
| 401 | return this.entityData.get(IS_TEARING_DOWN);
|
| 402 | }
|
| 403 |
|
| 404 | public boolean hasGlowingEyes() {
|
| 405 | return this.eyesGlowing;
|
| 406 | }
|
| 407 |
|
| 408 | public void checkEyeBlink() {
|
| 409 | if (this.deathTime > this.nextFlickerTime) {
|
| 410 | this.nextFlickerTime = this.deathTime
|
| 411 | + this.getRandom().nextIntBetweenInclusive(this.eyesGlowing ? 2 : this.deathTime / 4, this.eyesGlowing ? 8 : this.deathTime / 2);
|
| 412 | this.eyesGlowing = !this.eyesGlowing;
|
| 413 | }
|
| 414 | }
|
| 415 |
|
| 416 | @Override
|
| 417 | public void playAttackSound() {
|
| 418 | this.makeSound(SoundEvents.CREAKING_ATTACK);
|
| 419 | }
|
| 420 |
|
| 421 | @Override
|
| 422 | protected SoundEvent getAmbientSound() {
|
| 423 | return this.isActive() ? null : SoundEvents.CREAKING_AMBIENT;
|
| 424 | }
|
| 425 |
|
| 426 | @Override
|
| 427 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 428 | return this.isHeartBound() ? SoundEvents.CREAKING_SWAY : super.getHurtSound(source);
|
| 429 | }
|
| 430 |
|
| 431 | @Override
|
| 432 | protected SoundEvent getDeathSound() {
|
| 433 | return SoundEvents.CREAKING_DEATH;
|
| 434 | }
|
| 435 |
|
| 436 | @Override
|
| 437 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 438 | this.playSound(SoundEvents.CREAKING_STEP, 0.15F, 1.0F);
|
| 439 | }
|
| 440 |
|
| 441 | @Override
|
| 442 | public @Nullable LivingEntity getTarget() {
|
| 443 | return this.getTargetFromBrain();
|
| 444 | }
|
| 445 |
|
| 446 | @Override
|
| 447 | public void knockback(final double power, final double xd, final double zd, final DamageSource source, final float damage, final boolean comesFromEffect) {
|
| 448 | if (this.canMove()) {
|
| 449 | super.knockback(power, xd, zd, source, damage, comesFromEffect);
|
| 450 | }
|
| 451 | }
|
| 452 |
|
| 453 | public boolean checkCanMove() {
|
| 454 | List<Player> players = this.brain.getMemory(MemoryModuleType.NEAREST_PLAYERS).orElse(List.of());
|
| 455 | boolean active = this.isActive();
|
| 456 | if (players.isEmpty()) {
|
| 457 | if (active) {
|
| 458 | this.deactivate();
|
| 459 | }
|
| 460 |
|
| 461 | return true;
|
| 462 | } else {
|
| 463 | boolean hasPotentialTarget = false;
|
| 464 |
|
| 465 | for (Player player : players) {
|
| 466 | if (this.canAttack(player) && !this.isAlliedTo(player)) {
|
| 467 | hasPotentialTarget = true;
|
| 468 | if ((!active || LivingEntity.PLAYER_NOT_WEARING_DISGUISE_ITEM.test(player))
|
| 469 | && this.isLookingAtMe(player, 0.5, false, true, this.getEyeY(), this.getY() + 0.5 * this.getScale(), (this.getEyeY() + this.getY()) / 2.0)) {
|
| 470 | if (active) {
|
| 471 | return false;
|
| 472 | }
|
| 473 |
|
| 474 | if (player.distanceToSqr(this) < 144.0) {
|
| 475 | this.activate(player);
|
| 476 | return false;
|
| 477 | }
|
| 478 | }
|
| 479 | }
|
| 480 | }
|
| 481 |
|
| 482 | if (!hasPotentialTarget && active) {
|
| 483 | this.deactivate();
|
| 484 | }
|
| 485 |
|
| 486 | return true;
|
| 487 | }
|
| 488 | }
|
| 489 |
|
| 490 | public void activate(final Player player) {
|
| 491 | this.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, player);
|
| 492 | this.gameEvent(GameEvent.ENTITY_ACTION);
|
| 493 | this.makeSound(SoundEvents.CREAKING_ACTIVATE);
|
| 494 | this.setIsActive(true);
|
| 495 | }
|
| 496 |
|
| 497 | public void deactivate() {
|
| 498 | this.getBrain().eraseMemory(MemoryModuleType.ATTACK_TARGET);
|
| 499 | this.gameEvent(GameEvent.ENTITY_ACTION);
|
| 500 | this.makeSound(SoundEvents.CREAKING_DEACTIVATE);
|
| 501 | this.setIsActive(false);
|
| 502 | }
|
| 503 |
|
| 504 | public void setIsActive(final boolean active) {
|
| 505 | this.entityData.set(IS_ACTIVE, active);
|
| 506 | }
|
| 507 |
|
| 508 | public boolean isActive() {
|
| 509 | return this.entityData.get(IS_ACTIVE);
|
| 510 | }
|
| 511 |
|
| 512 | @Override
|
| 513 | public float getWalkTargetValue(final BlockPos pos, final LevelReader level) {
|
| 514 | return 0.0F;
|
| 515 | }
|
| 516 |
|
| 517 | private class CreakingBodyRotationControl extends BodyRotationControl {
|
| 518 | public CreakingBodyRotationControl(final Creaking creaking) {
|
| 519 | super(creaking);
|
| 520 | }
|
| 521 |
|
| 522 | @Override
|
| 523 | public void clientTick() {
|
| 524 | if (Creaking.this.canMove()) {
|
| 525 | super.clientTick();
|
| 526 | }
|
| 527 | }
|
| 528 | }
|
| 529 |
|
| 530 | private class CreakingJumpControl extends JumpControl {
|
| 531 | public CreakingJumpControl(final Creaking creaking) {
|
| 532 | super(creaking);
|
| 533 | }
|
| 534 |
|
| 535 | @Override
|
| 536 | public void tick() {
|
| 537 | if (Creaking.this.canMove()) {
|
| 538 | super.tick();
|
| 539 | } else {
|
| 540 | Creaking.this.setJumping(false);
|
| 541 | }
|
| 542 | }
|
| 543 | }
|
| 544 |
|
| 545 | private class CreakingLookControl extends LookControl {
|
| 546 | public CreakingLookControl(final Creaking creaking) {
|
| 547 | super(creaking);
|
| 548 | }
|
| 549 |
|
| 550 | @Override
|
| 551 | public void tick() {
|
| 552 | if (Creaking.this.canMove()) {
|
| 553 | super.tick();
|
| 554 | }
|
| 555 | }
|
| 556 | }
|
| 557 |
|
| 558 | private static class CreakingMoveControl<T extends Creaking> extends MoveControl<T> {
|
| 559 | public CreakingMoveControl(final T creaking) {
|
| 560 | super(creaking);
|
| 561 | }
|
| 562 |
|
| 563 | @Override
|
| 564 | public void tick() {
|
| 565 | if (this.mob.canMove()) {
|
| 566 | super.tick();
|
| 567 | }
|
| 568 | }
|
| 569 | }
|
| 570 |
|
| 571 | private class CreakingPathNavigation extends GroundPathNavigation {
|
| 572 | public CreakingPathNavigation(final Creaking mob, final Level level) {
|
| 573 | super(mob, level);
|
| 574 | }
|
| 575 |
|
| 576 | @Override
|
| 577 | public void tick() {
|
| 578 | if (Creaking.this.canMove()) {
|
| 579 | super.tick();
|
| 580 | }
|
| 581 | }
|
| 582 |
|
| 583 | @Override
|
| 584 | protected PathFinder createPathFinder(final int maxVisitedNodes) {
|
| 585 | this.nodeEvaluator = Creaking.this.new HomeNodeEvaluator();
|
| 586 | this.nodeEvaluator.setCanPassDoors(true);
|
| 587 | return new PathFinder(this.nodeEvaluator, maxVisitedNodes);
|
| 588 | }
|
| 589 | }
|
| 590 |
|
| 591 | private class HomeNodeEvaluator extends WalkNodeEvaluator {
|
| 592 | private static final int MAX_DISTANCE_TO_HOME_SQ = 1024;
|
| 593 |
|
| 594 | @Override
|
| 595 | public PathType getPathType(final PathfindingContext context, final int x, final int y, final int z) {
|
| 596 | BlockPos homePos = Creaking.this.getHomePos();
|
| 597 | if (homePos == null) {
|
| 598 | return super.getPathType(context, x, y, z);
|
| 599 | }
|
| 600 |
|
| 601 | double homeDistance = homePos.distSqr(new Vec3i(x, y, z));
|
| 602 | return homeDistance > 1024.0 && homeDistance >= homePos.distSqr(context.mobPosition()) ? PathType.BLOCKED : super.getPathType(context, x, y, z);
|
| 603 | }
|
| 604 | }
|
| 605 | }
|
| 606 |
|