| 1 | package net.minecraft.world.entity.animal.happyghast;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket;
|
| 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.sounds.SoundSource;
|
| 13 | import net.minecraft.tags.ItemTags;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 | import net.minecraft.util.profiling.Profiler;
|
| 16 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 17 | import net.minecraft.world.InteractionHand;
|
| 18 | import net.minecraft.world.InteractionResult;
|
| 19 | import net.minecraft.world.damagesource.DamageSource;
|
| 20 | import net.minecraft.world.entity.AgeableMob;
|
| 21 | import net.minecraft.world.entity.Entity;
|
| 22 | import net.minecraft.world.entity.EntityDimensions;
|
| 23 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 24 | import net.minecraft.world.entity.EntityType;
|
| 25 | import net.minecraft.world.entity.EntityTypes;
|
| 26 | import net.minecraft.world.entity.EquipmentSlot;
|
| 27 | import net.minecraft.world.entity.Leashable;
|
| 28 | import net.minecraft.world.entity.LivingEntity;
|
| 29 | import net.minecraft.world.entity.Pose;
|
| 30 | import net.minecraft.world.entity.ai.Brain;
|
| 31 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 32 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 33 | import net.minecraft.world.entity.ai.control.BodyRotationControl;
|
| 34 | import net.minecraft.world.entity.ai.control.FlyingMoveControl;
|
| 35 | import net.minecraft.world.entity.ai.control.LookControl;
|
| 36 | import net.minecraft.world.entity.ai.goal.FloatGoal;
|
| 37 | import net.minecraft.world.entity.ai.goal.TemptGoal;
|
| 38 | import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation;
|
| 39 | import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
| 40 | import net.minecraft.world.entity.ai.sensing.SensorType;
|
| 41 | import net.minecraft.world.entity.animal.Animal;
|
| 42 | import net.minecraft.world.entity.monster.Ghast;
|
| 43 | import net.minecraft.world.entity.player.Player;
|
| 44 | import net.minecraft.world.item.ItemStack;
|
| 45 | import net.minecraft.world.level.Level;
|
| 46 | import net.minecraft.world.level.LevelReader;
|
| 47 | import net.minecraft.world.level.biome.Biome;
|
| 48 | import net.minecraft.world.level.block.state.BlockState;
|
| 49 | import net.minecraft.world.level.storage.ValueInput;
|
| 50 | import net.minecraft.world.level.storage.ValueOutput;
|
| 51 | import net.minecraft.world.phys.AABB;
|
| 52 | import net.minecraft.world.phys.Vec2;
|
| 53 | import net.minecraft.world.phys.Vec3;
|
| 54 | import org.jspecify.annotations.Nullable;
|
| 55 |
|
| 56 | public class HappyGhast extends Animal {
|
| 57 | public static final float BABY_SCALE = 0.2375F;
|
| 58 | public static final int WANDER_GROUND_DISTANCE = 16;
|
| 59 | public static final int SMALL_RESTRICTION_RADIUS = 32;
|
| 60 | public static final int LARGE_RESTRICTION_RADIUS = 64;
|
| 61 | public static final int RESTRICTION_RADIUS_BUFFER = 16;
|
| 62 | public static final int FAST_HEALING_TICKS = 20;
|
| 63 | public static final int SLOW_HEALING_TICKS = 600;
|
| 64 | public static final int MAX_PASSANGERS = 4;
|
| 65 | private static final int STILL_TIMEOUT_ON_LOAD_GRACE_PERIOD = 60;
|
| 66 | private static final int MAX_STILL_TIMEOUT = 10;
|
| 67 | private static final Brain.Provider<HappyGhast> BRAIN_PROVIDER = Brain.provider(
|
| 68 | List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.HURT_BY, SensorType.FOOD_TEMPTATIONS, SensorType.NEAREST_ADULT_ANY_TYPE, SensorType.NEAREST_PLAYERS),
|
| 69 | var0 -> HappyGhastAi.getActivities()
|
| 70 | );
|
| 71 | public static final float SPEED_MULTIPLIER_WHEN_PANICKING = 2.0F;
|
| 72 | private int leashHolderTime = 0;
|
| 73 | private int serverStillTimeout;
|
| 74 | private static final EntityDataAccessor<Boolean> IS_LEASH_HOLDER = SynchedEntityData.defineId(HappyGhast.class, EntityDataSerializers.BOOLEAN);
|
| 75 | private static final EntityDataAccessor<Boolean> STAYS_STILL = SynchedEntityData.defineId(HappyGhast.class, EntityDataSerializers.BOOLEAN);
|
| 76 | private static final float MAX_SCALE = 1.0F;
|
| 77 | private static final EntityDimensions BABY_DIMENSIONS = EntityTypes.HAPPY_GHAST.getDimensions().scale(0.2375F).withEyeHeight(0.46875F);
|
| 78 |
|
| 79 | public HappyGhast(final EntityType<? extends HappyGhast> type, final Level level) {
|
| 80 | super(type, level);
|
| 81 | this.moveControl = new Ghast.GhastMoveControl<>(this, true, this::isOnStillTimeout);
|
| 82 | this.lookControl = new HappyGhast.HappyGhastLookControl();
|
| 83 | }
|
| 84 |
|
| 85 | private void setServerStillTimeout(final int serverStillTimeout) {
|
| 86 | if (this.serverStillTimeout <= 0 && serverStillTimeout > 0 && this.level() instanceof ServerLevel serverLevel) {
|
| 87 | this.syncPacketPositionCodec(this.getX(), this.getY(), this.getZ());
|
| 88 | serverLevel.getChunkSource().chunkMap.sendToTrackingPlayers(this, ClientboundEntityPositionSyncPacket.of(this));
|
| 89 | }
|
| 90 |
|
| 91 | this.serverStillTimeout = serverStillTimeout;
|
| 92 | this.syncStayStillFlag();
|
| 93 | }
|
| 94 |
|
| 95 | private PathNavigation createBabyNavigation(final Level level) {
|
| 96 | return new HappyGhast.BabyFlyingPathNavigation(this, level);
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | protected void registerGoals() {
|
| 101 | this.goalSelector.addGoal(3, new HappyGhast.HappyGhastFloatGoal());
|
| 102 | this.goalSelector
|
| 103 | .addGoal(
|
| 104 | 4,
|
| 105 | new TemptGoal.ForNonPathfinders(
|
| 106 | this,
|
| 107 | 1.0,
|
| 108 | itemStack -> !this.isWearingBodyArmor() && !this.isBaby() ? itemStack.is(ItemTags.HAPPY_GHAST_TEMPT_ITEMS) : itemStack.is(ItemTags.HAPPY_GHAST_FOOD),
|
| 109 | false,
|
| 110 | 7.0
|
| 111 | )
|
| 112 | );
|
| 113 | this.goalSelector.addGoal(5, new Ghast.RandomFloatAroundGoal(this, 16));
|
| 114 | }
|
| 115 |
|
| 116 | private void adultGhastSetup() {
|
| 117 | this.moveControl = new Ghast.GhastMoveControl<>(this, true, this::isOnStillTimeout);
|
| 118 | this.lookControl = new HappyGhast.HappyGhastLookControl();
|
| 119 | this.navigation = this.createNavigation(this.level());
|
| 120 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 121 | this.removeAllGoals(goal -> true);
|
| 122 | this.registerGoals();
|
| 123 | this.getBrain().stopAll(serverLevel, this);
|
| 124 | this.brain.clearMemories();
|
| 125 | }
|
| 126 | }
|
| 127 |
|
| 128 | private void babyGhastSetup() {
|
| 129 | this.moveControl = new FlyingMoveControl<>(this, 180, true);
|
| 130 | this.lookControl = new LookControl(this);
|
| 131 | this.navigation = this.createBabyNavigation(this.level());
|
| 132 | this.setServerStillTimeout(0);
|
| 133 | this.removeAllGoals(goal -> true);
|
| 134 | }
|
| 135 |
|
| 136 | @Override
|
| 137 | protected void ageBoundaryReached() {
|
| 138 | if (this.isBaby()) {
|
| 139 | this.babyGhastSetup();
|
| 140 | } else {
|
| 141 | this.adultGhastSetup();
|
| 142 | }
|
| 143 |
|
| 144 | super.ageBoundaryReached();
|
| 145 | }
|
| 146 |
|
| 147 | public static AttributeSupplier.Builder createAttributes() {
|
| 148 | return Animal.createAnimalAttributes()
|
| 149 | .add(Attributes.MAX_HEALTH, 20.0)
|
| 150 | .add(Attributes.TEMPT_RANGE, 16.0)
|
| 151 | .add(Attributes.FLYING_SPEED, 0.05)
|
| 152 | .add(Attributes.MOVEMENT_SPEED, 0.05)
|
| 153 | .add(Attributes.FOLLOW_RANGE, 16.0)
|
| 154 | .add(Attributes.CAMERA_DISTANCE, 8.0);
|
| 155 | }
|
| 156 |
|
| 157 | @Override
|
| 158 | protected float sanitizeScale(final float scale) {
|
| 159 | return Math.min(scale, 1.0F);
|
| 160 | }
|
| 161 |
|
| 162 | @Override
|
| 163 | protected void checkFallDamage(final double ya, final boolean onGround, final BlockState onState, final BlockPos pos) {
|
| 164 | }
|
| 165 |
|
| 166 | @Override
|
| 167 | public boolean onClimbable() {
|
| 168 | return false;
|
| 169 | }
|
| 170 |
|
| 171 | @Override
|
| 172 | public void travel(final Vec3 input) {
|
| 173 | float speed = (float)this.getAttributeValue(Attributes.FLYING_SPEED) * 5.0F / 3.0F;
|
| 174 | this.travelFlying(input, speed, speed, speed);
|
| 175 | }
|
| 176 |
|
| 177 | @Override
|
| 178 | public float getWalkTargetValue(final BlockPos pos, final LevelReader level) {
|
| 179 | if (!level.isEmptyBlock(pos)) {
|
| 180 | return 0.0F;
|
| 181 | } else {
|
| 182 | return level.isEmptyBlock(pos.below()) && !level.isEmptyBlock(pos.below(2)) ? 10.0F : 5.0F;
|
| 183 | }
|
| 184 | }
|
| 185 |
|
| 186 | @Override
|
| 187 | public boolean canBreatheUnderwater() {
|
| 188 | return this.isBaby() ? true : super.canBreatheUnderwater();
|
| 189 | }
|
| 190 |
|
| 191 | @Override
|
| 192 | protected boolean shouldStayCloseToLeashHolder() {
|
| 193 | return false;
|
| 194 | }
|
| 195 |
|
| 196 | @Override
|
| 197 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 198 | }
|
| 199 |
|
| 200 | @Override
|
| 201 | public float getVoicePitch() {
|
| 202 | return 1.0F;
|
| 203 | }
|
| 204 |
|
| 205 | @Override
|
| 206 | public SoundSource getSoundSource() {
|
| 207 | return SoundSource.NEUTRAL;
|
| 208 | }
|
| 209 |
|
| 210 | @Override
|
| 211 | public int getAmbientSoundInterval() {
|
| 212 | int interval = super.getAmbientSoundInterval();
|
| 213 | return this.isVehicle() ? interval * 6 : interval;
|
| 214 | }
|
| 215 |
|
| 216 | @Override
|
| 217 | protected SoundEvent getAmbientSound() {
|
| 218 | return this.isBaby() ? SoundEvents.GHASTLING_AMBIENT : SoundEvents.HAPPY_GHAST_AMBIENT;
|
| 219 | }
|
| 220 |
|
| 221 | @Override
|
| 222 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 223 | return this.isBaby() ? SoundEvents.GHASTLING_HURT : SoundEvents.HAPPY_GHAST_HURT;
|
| 224 | }
|
| 225 |
|
| 226 | @Override
|
| 227 | protected SoundEvent getDeathSound() {
|
| 228 | return this.isBaby() ? SoundEvents.GHASTLING_DEATH : SoundEvents.HAPPY_GHAST_DEATH;
|
| 229 | }
|
| 230 |
|
| 231 | @Override
|
| 232 | protected float getSoundVolume() {
|
| 233 | return this.isBaby() ? 1.0F : 4.0F;
|
| 234 | }
|
| 235 |
|
| 236 | @Override
|
| 237 | public int getMaxSpawnClusterSize() {
|
| 238 | return 1;
|
| 239 | }
|
| 240 |
|
| 241 | @Override
|
| 242 | public EntityDimensions getDefaultDimensions(final Pose pose) {
|
| 243 | return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
|
| 244 | }
|
| 245 |
|
| 246 | @Override
|
| 247 | public @Nullable AgeableMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
|
| 248 | return EntityTypes.HAPPY_GHAST.create(level, EntitySpawnReason.BREEDING);
|
| 249 | }
|
| 250 |
|
| 251 | @Override
|
| 252 | public boolean canFallInLove() {
|
| 253 | return false;
|
| 254 | }
|
| 255 |
|
| 256 | @Override
|
| 257 | public float getAgeScale() {
|
| 258 | return this.isBaby() ? 0.2375F : 1.0F;
|
| 259 | }
|
| 260 |
|
| 261 | @Override
|
| 262 | public boolean isFood(final ItemStack itemStack) {
|
| 263 | return itemStack.is(ItemTags.HAPPY_GHAST_FOOD);
|
| 264 | }
|
| 265 |
|
| 266 | @Override
|
| 267 | public boolean canUseSlot(final EquipmentSlot slot) {
|
| 268 | return slot != EquipmentSlot.BODY ? super.canUseSlot(slot) : this.isAlive() && !this.isBaby();
|
| 269 | }
|
| 270 |
|
| 271 | @Override
|
| 272 | protected boolean canDispenserEquipIntoSlot(final EquipmentSlot slot) {
|
| 273 | return slot == EquipmentSlot.BODY;
|
| 274 | }
|
| 275 |
|
| 276 | @Override
|
| 277 | public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
|
| 278 | if (this.isBaby()) {
|
| 279 | return super.mobInteract(player, hand);
|
| 280 | }
|
| 281 |
|
| 282 | ItemStack itemStack = player.getItemInHand(hand);
|
| 283 | if (!itemStack.isEmpty()) {
|
| 284 | InteractionResult interactionResult = itemStack.interactLivingEntity(player, this, hand);
|
| 285 | if (interactionResult.consumesAction()) {
|
| 286 | return interactionResult;
|
| 287 | }
|
| 288 | }
|
| 289 |
|
| 290 | if (this.isWearingBodyArmor() && !player.isSecondaryUseActive()) {
|
| 291 | this.doPlayerRide(player);
|
| 292 | return InteractionResult.SUCCESS;
|
| 293 | } else {
|
| 294 | return super.mobInteract(player, hand);
|
| 295 | }
|
| 296 | }
|
| 297 |
|
| 298 | private void doPlayerRide(final Player player) {
|
| 299 | if (!this.level().isClientSide()) {
|
| 300 | player.startRiding(this);
|
| 301 | }
|
| 302 | }
|
| 303 |
|
| 304 | @Override
|
| 305 | protected void addPassenger(final Entity passenger) {
|
| 306 | if (!this.isVehicle()) {
|
| 307 | this.playSound(SoundEvents.HARNESS_GOGGLES_DOWN);
|
| 308 | }
|
| 309 |
|
| 310 | super.addPassenger(passenger);
|
| 311 | if (!this.level().isClientSide()) {
|
| 312 | if (!this.scanPlayerAboveGhast()) {
|
| 313 | this.setServerStillTimeout(0);
|
| 314 | } else if (this.serverStillTimeout > 10) {
|
| 315 | this.setServerStillTimeout(10);
|
| 316 | }
|
| 317 | }
|
| 318 | }
|
| 319 |
|
| 320 | @Override
|
| 321 | protected void removePassenger(final Entity passenger) {
|
| 322 | super.removePassenger(passenger);
|
| 323 | if (!this.level().isClientSide()) {
|
| 324 | this.setServerStillTimeout(10);
|
| 325 | }
|
| 326 |
|
| 327 | if (!this.isVehicle()) {
|
| 328 | this.clearHome();
|
| 329 | this.playSound(SoundEvents.HARNESS_GOGGLES_UP);
|
| 330 | }
|
| 331 | }
|
| 332 |
|
| 333 | @Override
|
| 334 | protected boolean canAddPassenger(final Entity passenger) {
|
| 335 | return this.getPassengers().size() < 4;
|
| 336 | }
|
| 337 |
|
| 338 | @Override
|
| 339 | public @Nullable LivingEntity getControllingPassenger() {
|
| 340 | return this.isWearingBodyArmor() && !this.isOnStillTimeout() && this.getFirstPassenger() instanceof Player player ? player : super.getControllingPassenger();
|
| 341 | }
|
| 342 |
|
| 343 | @Override
|
| 344 | protected Vec3 getRiddenInput(final Player controller, final Vec3 selfInput) {
|
| 345 | float strafe = controller.xxa;
|
| 346 | float forward = 0.0F;
|
| 347 | float up = 0.0F;
|
| 348 | if (controller.zza != 0.0F) {
|
| 349 | float forwardLook = Mth.cos(controller.getXRot() * (float) (Math.PI / 180.0));
|
| 350 | float upLook = -Mth.sin(controller.getXRot() * (float) (Math.PI / 180.0));
|
| 351 | if (controller.zza < 0.0F) {
|
| 352 | forwardLook *= -0.5F;
|
| 353 | upLook *= -0.5F;
|
| 354 | }
|
| 355 |
|
| 356 | up = upLook;
|
| 357 | forward = forwardLook;
|
| 358 | }
|
| 359 |
|
| 360 | if (controller.isJumping()) {
|
| 361 | up += 0.5F;
|
| 362 | }
|
| 363 |
|
| 364 | return new Vec3(strafe, up, forward).scale(3.9F * this.getAttributeValue(Attributes.FLYING_SPEED));
|
| 365 | }
|
| 366 |
|
| 367 | protected Vec2 getRiddenRotation(final LivingEntity controller) {
|
| 368 | return new Vec2(controller.getXRot() * 0.5F, controller.getYRot());
|
| 369 | }
|
| 370 |
|
| 371 | @Override
|
| 372 | protected void tickRidden(final Player controller, final Vec3 riddenInput) {
|
| 373 | super.tickRidden(controller, riddenInput);
|
| 374 | Vec2 rotation = this.getRiddenRotation(controller);
|
| 375 | float yRot = this.getYRot();
|
| 376 | float diff = Mth.wrapDegrees(rotation.y - yRot);
|
| 377 | float turnSpeed = 0.08F;
|
| 378 | yRot += diff * 0.08F;
|
| 379 | this.setRot(yRot, rotation.x);
|
| 380 | this.yRotO = this.yBodyRot = this.yHeadRot = yRot;
|
| 381 | }
|
| 382 |
|
| 383 | @Override
|
| 384 | protected Brain<HappyGhast> makeBrain(final Brain.Packed packedBrain) {
|
| 385 | return BRAIN_PROVIDER.makeBrain(this, packedBrain);
|
| 386 | }
|
| 387 |
|
| 388 | @Override
|
| 389 | public Brain<HappyGhast> getBrain() {
|
| 390 | return super.getBrain();
|
| 391 | }
|
| 392 |
|
| 393 | @Override
|
| 394 | protected void customServerAiStep(final ServerLevel level) {
|
| 395 | if (this.isBaby()) {
|
| 396 | ProfilerFiller profiler = Profiler.get();
|
| 397 | profiler.push("happyGhastBrain");
|
| 398 | this.getBrain().tick(level, this);
|
| 399 | profiler.pop();
|
| 400 | profiler.push("happyGhastActivityUpdate");
|
| 401 | HappyGhastAi.updateActivity(this);
|
| 402 | profiler.pop();
|
| 403 | }
|
| 404 |
|
| 405 | this.checkRestriction();
|
| 406 | super.customServerAiStep(level);
|
| 407 | }
|
| 408 |
|
| 409 | @Override
|
| 410 | public void tick() {
|
| 411 | super.tick();
|
| 412 | if (!this.level().isClientSide()) {
|
| 413 | if (this.leashHolderTime > 0) {
|
| 414 | this.leashHolderTime--;
|
| 415 | }
|
| 416 |
|
| 417 | this.setLeashHolder(this.leashHolderTime > 0);
|
| 418 | if (this.serverStillTimeout > 0) {
|
| 419 | if (this.tickCount > 60) {
|
| 420 | this.serverStillTimeout--;
|
| 421 | }
|
| 422 |
|
| 423 | this.setServerStillTimeout(this.serverStillTimeout);
|
| 424 | }
|
| 425 |
|
| 426 | if (this.scanPlayerAboveGhast()) {
|
| 427 | this.setServerStillTimeout(10);
|
| 428 | }
|
| 429 | }
|
| 430 | }
|
| 431 |
|
| 432 | @Override
|
| 433 | public void aiStep() {
|
| 434 | if (!this.level().isClientSide()) {
|
| 435 | this.setRequiresPrecisePosition(this.isOnStillTimeout());
|
| 436 | }
|
| 437 |
|
| 438 | super.aiStep();
|
| 439 | this.continuousHeal();
|
| 440 | }
|
| 441 |
|
| 442 | private int getHappyGhastRestrictionRadius() {
|
| 443 | return !this.isBaby() && this.getItemBySlot(EquipmentSlot.BODY).isEmpty() ? 64 : 32;
|
| 444 | }
|
| 445 |
|
| 446 | private void checkRestriction() {
|
| 447 | if (!this.isLeashed() && !this.isVehicle()) {
|
| 448 | int radius = this.getHappyGhastRestrictionRadius();
|
| 449 | if (!this.hasHome() || !this.getHomePosition().closerThan(this.blockPosition(), radius + 16) || radius != this.getHomeRadius()) {
|
| 450 | this.setHomeTo(this.blockPosition(), radius);
|
| 451 | }
|
| 452 | }
|
| 453 | }
|
| 454 |
|
| 455 | private void continuousHeal() {
|
| 456 | if (this.level() instanceof ServerLevel level && this.isAlive() && this.deathTime == 0 && this.getMaxHealth() != this.getHealth()) {
|
| 457 | boolean isFastHealing = this.isInClouds() || level.precipitationAt(this.blockPosition()) != Biome.Precipitation.NONE;
|
| 458 | if (this.tickCount % (isFastHealing ? 20 : 600) == 0) {
|
| 459 | this.heal(1.0F);
|
| 460 | }
|
| 461 | }
|
| 462 | }
|
| 463 |
|
| 464 | @Override
|
| 465 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 466 | super.defineSynchedData(entityData);
|
| 467 | entityData.define(IS_LEASH_HOLDER, false);
|
| 468 | entityData.define(STAYS_STILL, false);
|
| 469 | }
|
| 470 |
|
| 471 | private void setLeashHolder(final boolean isLeashHolder) {
|
| 472 | this.entityData.set(IS_LEASH_HOLDER, isLeashHolder);
|
| 473 | }
|
| 474 |
|
| 475 | public boolean isLeashHolder() {
|
| 476 | return this.entityData.get(IS_LEASH_HOLDER);
|
| 477 | }
|
| 478 |
|
| 479 | private void syncStayStillFlag() {
|
| 480 | this.entityData.set(STAYS_STILL, this.serverStillTimeout > 0);
|
| 481 | }
|
| 482 |
|
| 483 | public boolean staysStill() {
|
| 484 | return this.entityData.get(STAYS_STILL);
|
| 485 | }
|
| 486 |
|
| 487 | @Override
|
| 488 | public boolean supportQuadLeashAsHolder() {
|
| 489 | return true;
|
| 490 | }
|
| 491 |
|
| 492 | @Override
|
| 493 | public Vec3[] getQuadLeashHolderOffsets() {
|
| 494 | return Leashable.createQuadLeashOffsets(this, -0.03125, 0.4375, 0.46875, 0.03125);
|
| 495 | }
|
| 496 |
|
| 497 | @Override
|
| 498 | public Vec3 getLeashOffset() {
|
| 499 | return Vec3.ZERO;
|
| 500 | }
|
| 501 |
|
| 502 | @Override
|
| 503 | public double leashElasticDistance() {
|
| 504 | return 10.0;
|
| 505 | }
|
| 506 |
|
| 507 | @Override
|
| 508 | public double leashSnapDistance() {
|
| 509 | return 16.0;
|
| 510 | }
|
| 511 |
|
| 512 | @Override
|
| 513 | public void onElasticLeashPull() {
|
| 514 | super.onElasticLeashPull();
|
| 515 | this.getMoveControl().setWait();
|
| 516 | }
|
| 517 |
|
| 518 | @Override
|
| 519 | public void notifyLeashHolder(final Leashable entity) {
|
| 520 | if (entity.supportQuadLeash()) {
|
| 521 | this.leashHolderTime = 5;
|
| 522 | }
|
| 523 | }
|
| 524 |
|
| 525 | @Override
|
| 526 | public void addAdditionalSaveData(final ValueOutput tag) {
|
| 527 | super.addAdditionalSaveData(tag);
|
| 528 | tag.putInt("still_timeout", this.serverStillTimeout);
|
| 529 | }
|
| 530 |
|
| 531 | @Override
|
| 532 | public void readAdditionalSaveData(final ValueInput tag) {
|
| 533 | super.readAdditionalSaveData(tag);
|
| 534 | this.setServerStillTimeout(tag.getIntOr("still_timeout", 0));
|
| 535 | }
|
| 536 |
|
| 537 | public boolean isOnStillTimeout() {
|
| 538 | return this.staysStill() || this.serverStillTimeout > 0;
|
| 539 | }
|
| 540 |
|
| 541 | private boolean scanPlayerAboveGhast() {
|
| 542 | AABB happyGhastBb = this.getBoundingBox();
|
| 543 | AABB ghastDetectionBox = new AABB(
|
| 544 | happyGhastBb.minX - 1.0,
|
| 545 | happyGhastBb.maxY - 1.0E-5F,
|
| 546 | happyGhastBb.minZ - 1.0,
|
| 547 | happyGhastBb.maxX + 1.0,
|
| 548 | happyGhastBb.maxY + happyGhastBb.getYsize() / 2.0,
|
| 549 | happyGhastBb.maxZ + 1.0
|
| 550 | );
|
| 551 |
|
| 552 | for (Player player : this.level().players()) {
|
| 553 | if (!player.isSpectator()) {
|
| 554 | Entity rootVehicle = player.getRootVehicle();
|
| 555 | if (!(rootVehicle instanceof HappyGhast) && ghastDetectionBox.contains(rootVehicle.position())) {
|
| 556 | return true;
|
| 557 | }
|
| 558 | }
|
| 559 | }
|
| 560 |
|
| 561 | return false;
|
| 562 | }
|
| 563 |
|
| 564 | @Override
|
| 565 | protected BodyRotationControl createBodyControl() {
|
| 566 | return new HappyGhast.HappyGhastBodyRotationControl();
|
| 567 | }
|
| 568 |
|
| 569 | @Override
|
| 570 | public boolean canBeCollidedWith(final @Nullable Entity other) {
|
| 571 | if (!this.isBaby() && this.isAlive()) {
|
| 572 | if (this.level().isClientSide() && other instanceof Player && other.position().y >= this.getBoundingBox().maxY) {
|
| 573 | return true;
|
| 574 | } else {
|
| 575 | return this.isVehicle() && other instanceof HappyGhast ? true : this.isOnStillTimeout();
|
| 576 | }
|
| 577 | } else {
|
| 578 | return false;
|
| 579 | }
|
| 580 | }
|
| 581 |
|
| 582 | @Override
|
| 583 | public boolean isFlyingVehicle() {
|
| 584 | return !this.isBaby();
|
| 585 | }
|
| 586 |
|
| 587 | @Override
|
| 588 | public Vec3 getDismountLocationForPassenger(final LivingEntity passenger) {
|
| 589 | return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
|
| 590 | }
|
| 591 |
|
| 592 | private static class BabyFlyingPathNavigation extends FlyingPathNavigation {
|
| 593 | public BabyFlyingPathNavigation(final HappyGhast mob, final Level level) {
|
| 594 | super(mob, level);
|
| 595 | this.setCanOpenDoors(false);
|
| 596 | this.setCanFloat(true);
|
| 597 | this.setRequiredPathLength(48.0F);
|
| 598 | }
|
| 599 |
|
| 600 | @Override
|
| 601 | protected boolean canMoveDirectly(final Vec3 startPos, final Vec3 stopPos) {
|
| 602 | return isClearForMovementBetween(this.mob, startPos, stopPos, false);
|
| 603 | }
|
| 604 | }
|
| 605 |
|
| 606 | private class HappyGhastBodyRotationControl extends BodyRotationControl {
|
| 607 | public HappyGhastBodyRotationControl() {
|
| 608 | super(HappyGhast.this);
|
| 609 | }
|
| 610 |
|
| 611 | @Override
|
| 612 | public void clientTick() {
|
| 613 | if (HappyGhast.this.isVehicle()) {
|
| 614 | HappyGhast.this.yHeadRot = HappyGhast.this.getYRot();
|
| 615 | HappyGhast.this.yBodyRot = HappyGhast.this.yHeadRot;
|
| 616 | }
|
| 617 |
|
| 618 | super.clientTick();
|
| 619 | }
|
| 620 | }
|
| 621 |
|
| 622 | private class HappyGhastFloatGoal extends FloatGoal {
|
| 623 | public HappyGhastFloatGoal() {
|
| 624 | super(HappyGhast.this);
|
| 625 | }
|
| 626 |
|
| 627 | @Override
|
| 628 | public boolean canUse() {
|
| 629 | return !HappyGhast.this.isOnStillTimeout() && super.canUse();
|
| 630 | }
|
| 631 | }
|
| 632 |
|
| 633 | private class HappyGhastLookControl extends LookControl {
|
| 634 | private HappyGhastLookControl() {
|
| 635 | super(HappyGhast.this);
|
| 636 | }
|
| 637 |
|
| 638 | @Override
|
| 639 | public void tick() {
|
| 640 | if (HappyGhast.this.isOnStillTimeout()) {
|
| 641 | float closeAngle = Mth.wrapDegrees90(HappyGhast.this.getYRot());
|
| 642 | HappyGhast.this.setYRot(HappyGhast.this.getYRot() - closeAngle);
|
| 643 | HappyGhast.this.setYHeadRot(HappyGhast.this.getYRot());
|
| 644 | } else if (this.lookAtCooldown > 0) {
|
| 645 | this.lookAtCooldown--;
|
| 646 | double xdd = this.wantedX - HappyGhast.this.getX();
|
| 647 | double zdd = this.wantedZ - HappyGhast.this.getZ();
|
| 648 | HappyGhast.this.setYRot(-((float)Mth.atan2(xdd, zdd)) * (180.0F / (float)Math.PI));
|
| 649 | HappyGhast.this.yBodyRot = HappyGhast.this.getYRot();
|
| 650 | HappyGhast.this.yHeadRot = HappyGhast.this.yBodyRot;
|
| 651 | } else {
|
| 652 | Ghast.faceMovementDirection(this.mob);
|
| 653 | }
|
| 654 | }
|
| 655 | }
|
| 656 | }
|
| 657 |
|