| 1 | package net.minecraft.world.entity.animal.nautilus;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Holder;
|
| 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.FluidTags;
|
| 13 | import net.minecraft.tags.ItemTags;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 | import net.minecraft.util.RandomSource;
|
| 16 | import net.minecraft.world.Container;
|
| 17 | import net.minecraft.world.DifficultyInstance;
|
| 18 | import net.minecraft.world.InteractionHand;
|
| 19 | import net.minecraft.world.InteractionResult;
|
| 20 | import net.minecraft.world.SimpleContainer;
|
| 21 | import net.minecraft.world.damagesource.DamageSource;
|
| 22 | import net.minecraft.world.effect.MobEffectInstance;
|
| 23 | import net.minecraft.world.effect.MobEffects;
|
| 24 | import net.minecraft.world.entity.Entity;
|
| 25 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 26 | import net.minecraft.world.entity.EntityType;
|
| 27 | import net.minecraft.world.entity.EquipmentSlot;
|
| 28 | import net.minecraft.world.entity.HasCustomInventoryScreen;
|
| 29 | import net.minecraft.world.entity.LivingEntity;
|
| 30 | import net.minecraft.world.entity.Mob;
|
| 31 | import net.minecraft.world.entity.MoverType;
|
| 32 | import net.minecraft.world.entity.PlayerRideableJumping;
|
| 33 | import net.minecraft.world.entity.SlotAccess;
|
| 34 | import net.minecraft.world.entity.SpawnGroupData;
|
| 35 | import net.minecraft.world.entity.TamableAnimal;
|
| 36 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 37 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 38 | import net.minecraft.world.entity.ai.control.SmoothSwimmingLookControl;
|
| 39 | import net.minecraft.world.entity.ai.control.SmoothSwimmingMoveControl;
|
| 40 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 41 | import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
| 42 | import net.minecraft.world.entity.ai.navigation.WaterBoundPathNavigation;
|
| 43 | import net.minecraft.world.entity.animal.Animal;
|
| 44 | import net.minecraft.world.entity.player.Player;
|
| 45 | import net.minecraft.world.inventory.AbstractMountInventoryMenu;
|
| 46 | import net.minecraft.world.item.ItemStack;
|
| 47 | import net.minecraft.world.item.ItemUtils;
|
| 48 | import net.minecraft.world.item.Items;
|
| 49 | import net.minecraft.world.item.equipment.Equippable;
|
| 50 | import net.minecraft.world.level.Level;
|
| 51 | import net.minecraft.world.level.LevelAccessor;
|
| 52 | import net.minecraft.world.level.LevelReader;
|
| 53 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 54 | import net.minecraft.world.level.block.Blocks;
|
| 55 | import net.minecraft.world.level.block.state.BlockState;
|
| 56 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 57 | import net.minecraft.world.level.pathfinder.PathType;
|
| 58 | import net.minecraft.world.phys.Vec2;
|
| 59 | import net.minecraft.world.phys.Vec3;
|
| 60 | import org.jspecify.annotations.Nullable;
|
| 61 |
|
| 62 | public abstract class AbstractNautilus extends TamableAnimal implements PlayerRideableJumping, HasCustomInventoryScreen {
|
| 63 | public static final int INVENTORY_SLOT_OFFSET = 500;
|
| 64 | public static final int INVENTORY_ROWS = 3;
|
| 65 | public static final int SMALL_RESTRICTION_RADIUS = 16;
|
| 66 | public static final int LARGE_RESTRICTION_RADIUS = 32;
|
| 67 | public static final int RESTRICTION_RADIUS_BUFFER = 8;
|
| 68 | private static final int EFFECT_DURATION = 60;
|
| 69 | private static final int EFFECT_REFRESH_RATE = 40;
|
| 70 | private static final double NAUTILUS_WATER_RESISTANCE = 0.9;
|
| 71 | private static final float IN_WATER_SPEED_MODIFIER = 0.011F;
|
| 72 | private static final float RIDDEN_SPEED_MODIFIER_IN_WATER = 0.0325F;
|
| 73 | private static final float RIDDEN_SPEED_MODIFIER_ON_LAND = 0.02F;
|
| 74 | private static final EntityDataAccessor<Boolean> DASH = SynchedEntityData.defineId(AbstractNautilus.class, EntityDataSerializers.BOOLEAN);
|
| 75 | private static final int DASH_COOLDOWN_TICKS = 40;
|
| 76 | private static final int DASH_MINIMUM_DURATION_TICKS = 5;
|
| 77 | private static final float DASH_MOMENTUM_IN_WATER = 1.2F;
|
| 78 | private static final float DASH_MOMENTUM_ON_LAND = 0.5F;
|
| 79 | private int dashCooldown = 0;
|
| 80 | protected float playerJumpPendingScale;
|
| 81 | protected SimpleContainer inventory;
|
| 82 | private static final double BUBBLE_SPREAD_FACTOR = 0.8;
|
| 83 | private static final double BUBBLE_DIRECTION_SCALE = 1.1;
|
| 84 | private static final double BUBBLE_Y_OFFSET = 0.25;
|
| 85 | private static final double BUBBLE_PROBABILITY_MULTIPLIER = 2.0;
|
| 86 | private static final float BUBBLE_PROBABILITY_MIN = 0.15F;
|
| 87 | private static final float BUBBLE_PROBABILITY_MAX = 1.0F;
|
| 88 |
|
| 89 | protected AbstractNautilus(final EntityType<? extends AbstractNautilus> type, final Level level) {
|
| 90 | super(type, level);
|
| 91 | this.moveControl = new SmoothSwimmingMoveControl<>(this, 85, 10, 0.011F, 0.0F, true);
|
| 92 | this.lookControl = new SmoothSwimmingLookControl(this, 10);
|
| 93 | this.setPathfindingMalus(PathType.WATER, 0.0F);
|
| 94 | this.createInventory();
|
| 95 | }
|
| 96 |
|
| 97 | @Override
|
| 98 | public boolean isFood(final ItemStack itemStack) {
|
| 99 | return !this.isTame() && !this.isBaby() ? itemStack.is(ItemTags.NAUTILUS_TAMING_ITEMS) : itemStack.is(ItemTags.NAUTILUS_FOOD);
|
| 100 | }
|
| 101 |
|
| 102 | @Override
|
| 103 | protected void usePlayerItem(final Player player, final InteractionHand hand, final ItemStack itemStack) {
|
| 104 | if (itemStack.is(ItemTags.NAUTILUS_BUCKET_FOOD)) {
|
| 105 | player.setItemInHand(hand, ItemUtils.createFilledResult(itemStack, player, new ItemStack(Items.WATER_BUCKET)));
|
| 106 | } else {
|
| 107 | super.usePlayerItem(player, hand, itemStack);
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | public static AttributeSupplier.Builder createAttributes() {
|
| 112 | return Animal.createAnimalAttributes()
|
| 113 | .add(Attributes.MAX_HEALTH, 15.0)
|
| 114 | .add(Attributes.MOVEMENT_SPEED, 1.0)
|
| 115 | .add(Attributes.ATTACK_DAMAGE, 3.0)
|
| 116 | .add(Attributes.KNOCKBACK_RESISTANCE, 0.3F);
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | public boolean isPushedByFluid() {
|
| 121 | return false;
|
| 122 | }
|
| 123 |
|
| 124 | @Override
|
| 125 | protected PathNavigation createNavigation(final Level level) {
|
| 126 | return new WaterBoundPathNavigation(this, level);
|
| 127 | }
|
| 128 |
|
| 129 | @Override
|
| 130 | public float getWalkTargetValue(final BlockPos pos, final LevelReader level) {
|
| 131 | return 0.0F;
|
| 132 | }
|
| 133 |
|
| 134 | public static boolean checkNautilusSpawnRules(
|
| 135 | final EntityType<? extends AbstractNautilus> type,
|
| 136 | final LevelAccessor level,
|
| 137 | final EntitySpawnReason spawnReason,
|
| 138 | final BlockPos pos,
|
| 139 | final RandomSource random
|
| 140 | ) {
|
| 141 | int seaLevel = level.getSeaLevel();
|
| 142 | int minSpawnLevel = seaLevel - 25;
|
| 143 | return pos.getY() >= minSpawnLevel
|
| 144 | && pos.getY() <= seaLevel - 5
|
| 145 | && level.getFluidState(pos.below()).is(FluidTags.WATER)
|
| 146 | && level.getBlockState(pos.above()).is(Blocks.WATER);
|
| 147 | }
|
| 148 |
|
| 149 | @Override
|
| 150 | public boolean checkSpawnObstruction(final LevelReader level) {
|
| 151 | return level.isUnobstructed(this);
|
| 152 | }
|
| 153 |
|
| 154 | @Override
|
| 155 | public boolean canUseSlot(final EquipmentSlot slot) {
|
| 156 | return slot != EquipmentSlot.SADDLE && slot != EquipmentSlot.BODY ? super.canUseSlot(slot) : this.isAlive() && !this.isBaby() && this.isTame();
|
| 157 | }
|
| 158 |
|
| 159 | @Override
|
| 160 | protected boolean canDispenserEquipIntoSlot(final EquipmentSlot slot) {
|
| 161 | return slot == EquipmentSlot.BODY || slot == EquipmentSlot.SADDLE || super.canDispenserEquipIntoSlot(slot);
|
| 162 | }
|
| 163 |
|
| 164 | @Override
|
| 165 | protected boolean canAddPassenger(final Entity passenger) {
|
| 166 | return !this.isVehicle();
|
| 167 | }
|
| 168 |
|
| 169 | @Override
|
| 170 | public @Nullable LivingEntity getControllingPassenger() {
|
| 171 | return this.isSaddled() && this.getFirstPassenger() instanceof Player player ? player : super.getControllingPassenger();
|
| 172 | }
|
| 173 |
|
| 174 | @Override
|
| 175 | protected Vec3 getRiddenInput(final Player controller, final Vec3 selfInput) {
|
| 176 | float strafe = controller.xxa;
|
| 177 | float forward = 0.0F;
|
| 178 | float up = 0.0F;
|
| 179 | if (controller.zza != 0.0F) {
|
| 180 | float forwardLook = Mth.cos(controller.getXRot() * (float) (Math.PI / 180.0));
|
| 181 | float upLook = -Mth.sin(controller.getXRot() * (float) (Math.PI / 180.0));
|
| 182 | if (controller.zza < 0.0F) {
|
| 183 | forwardLook *= -0.5F;
|
| 184 | upLook *= -0.5F;
|
| 185 | }
|
| 186 |
|
| 187 | up = upLook;
|
| 188 | forward = forwardLook;
|
| 189 | }
|
| 190 |
|
| 191 | return new Vec3(strafe, up, forward);
|
| 192 | }
|
| 193 |
|
| 194 | protected Vec2 getRiddenRotation(final LivingEntity controller) {
|
| 195 | return new Vec2(controller.getXRot() * 0.5F, controller.getYRot());
|
| 196 | }
|
| 197 |
|
| 198 | @Override
|
| 199 | protected void tickRidden(final Player controller, final Vec3 riddenInput) {
|
| 200 | super.tickRidden(controller, riddenInput);
|
| 201 | Vec2 rotation = this.getRiddenRotation(controller);
|
| 202 | float yRot = this.getYRot();
|
| 203 | float diff = Mth.wrapDegrees(rotation.y - yRot);
|
| 204 | float turnSpeed = 0.5F;
|
| 205 | yRot += diff * 0.5F;
|
| 206 | this.setRot(yRot, rotation.x);
|
| 207 | this.yRotO = this.yBodyRot = this.yHeadRot = yRot;
|
| 208 | if (this.isLocalInstanceAuthoritative()) {
|
| 209 | if (this.playerJumpPendingScale > 0.0F && !this.isJumping()) {
|
| 210 | this.executeRidersJump(this.playerJumpPendingScale, controller);
|
| 211 | }
|
| 212 |
|
| 213 | this.playerJumpPendingScale = 0.0F;
|
| 214 | }
|
| 215 | }
|
| 216 |
|
| 217 | @Override
|
| 218 | protected void travelInWater(final Vec3 input, final double baseGravity, final boolean isFalling, final double oldY) {
|
| 219 | float speed = this.getSpeed();
|
| 220 | this.moveRelative(speed, input);
|
| 221 | this.move(MoverType.SELF, this.getDeltaMovement());
|
| 222 | this.setDeltaMovement(this.getDeltaMovement().scale(0.9));
|
| 223 | }
|
| 224 |
|
| 225 | @Override
|
| 226 | protected float getRiddenSpeed(final Player controller) {
|
| 227 | return this.isInWater()
|
| 228 | ? 0.0325F * (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED)
|
| 229 | : 0.02F * (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED);
|
| 230 | }
|
| 231 |
|
| 232 | protected void doPlayerRide(final Player player) {
|
| 233 | if (!this.level().isClientSide()) {
|
| 234 | player.startRiding(this);
|
| 235 | if (!this.isVehicle()) {
|
| 236 | this.clearHome();
|
| 237 | }
|
| 238 | }
|
| 239 | }
|
| 240 |
|
| 241 | private int getNautilusRestrictionRadius() {
|
| 242 | return !this.isBaby() && this.getItemBySlot(EquipmentSlot.SADDLE).isEmpty() ? 32 : 16;
|
| 243 | }
|
| 244 |
|
| 245 | protected void checkRestriction() {
|
| 246 | if (!this.isLeashed() && !this.isVehicle() && this.isTame()) {
|
| 247 | int radius = this.getNautilusRestrictionRadius();
|
| 248 | if (!this.hasHome() || !this.getHomePosition().closerThan(this.blockPosition(), radius + 8) || radius != this.getHomeRadius()) {
|
| 249 | this.setHomeTo(this.blockPosition(), radius);
|
| 250 | }
|
| 251 | }
|
| 252 | }
|
| 253 |
|
| 254 | @Override
|
| 255 | protected void customServerAiStep(final ServerLevel level) {
|
| 256 | this.checkRestriction();
|
| 257 | super.customServerAiStep(level);
|
| 258 | }
|
| 259 |
|
| 260 | private void applyEffects(final Level level) {
|
| 261 | if (this.getFirstPassenger() instanceof Player player) {
|
| 262 | boolean hasEffect = player.hasEffect(MobEffects.BREATH_OF_THE_NAUTILUS);
|
| 263 | boolean shouldRefresh = level.getGameTime() % 40L == 0L;
|
| 264 | if (!hasEffect || shouldRefresh) {
|
| 265 | player.addEffect(new MobEffectInstance(MobEffects.BREATH_OF_THE_NAUTILUS, 60, 0, true, true, true));
|
| 266 | }
|
| 267 | }
|
| 268 | }
|
| 269 |
|
| 270 | private void spawnBubbles() {
|
| 271 | double speed = this.getDeltaMovement().length();
|
| 272 | double bubbleProbability = Mth.clamp(speed * 2.0, 0.15F, 1.0);
|
| 273 | if (this.random.nextFloat() < bubbleProbability) {
|
| 274 | float yRot = this.getYRot();
|
| 275 | float xRot = Mth.clamp(this.getXRot(), -10.0F, 10.0F);
|
| 276 | Vec3 mouthDirectionVector = calculateViewVector(xRot, yRot);
|
| 277 | double spread = this.random.nextDouble() * 0.8 * (1.0 + speed);
|
| 278 | double dx = (this.random.nextFloat() - 0.5) * spread;
|
| 279 | double dy = (this.random.nextFloat() - 0.5) * spread;
|
| 280 | double dz = (this.random.nextFloat() - 0.5) * spread;
|
| 281 | this.level()
|
| 282 | .addParticle(
|
| 283 | ParticleTypes.BUBBLE,
|
| 284 | this.getX() - mouthDirectionVector.x * 1.1,
|
| 285 | this.getY() - mouthDirectionVector.y + 0.25,
|
| 286 | this.getZ() - mouthDirectionVector.z * 1.1,
|
| 287 | dx,
|
| 288 | dy,
|
| 289 | dz
|
| 290 | );
|
| 291 | }
|
| 292 | }
|
| 293 |
|
| 294 | @Override
|
| 295 | public void tick() {
|
| 296 | super.tick();
|
| 297 | if (!this.level().isClientSide()) {
|
| 298 | this.applyEffects(this.level());
|
| 299 | }
|
| 300 |
|
| 301 | if (this.isDashing() && this.dashCooldown < 35) {
|
| 302 | this.setDashing(false);
|
| 303 | }
|
| 304 |
|
| 305 | if (this.dashCooldown > 0) {
|
| 306 | this.dashCooldown--;
|
| 307 | if (this.dashCooldown == 0) {
|
| 308 | this.makeSound(this.getDashReadySound());
|
| 309 | }
|
| 310 | }
|
| 311 |
|
| 312 | if (this.isInWater()) {
|
| 313 | this.spawnBubbles();
|
| 314 | }
|
| 315 | }
|
| 316 |
|
| 317 | @Override
|
| 318 | public boolean canJump() {
|
| 319 | return this.isSaddled();
|
| 320 | }
|
| 321 |
|
| 322 | @Override
|
| 323 | public void onPlayerJump(final int jumpAmount) {
|
| 324 | if (this.isSaddled() && this.dashCooldown <= 0) {
|
| 325 | this.playerJumpPendingScale = this.getPlayerJumpPendingScale(jumpAmount);
|
| 326 | }
|
| 327 | }
|
| 328 |
|
| 329 | @Override
|
| 330 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 331 | super.defineSynchedData(entityData);
|
| 332 | entityData.define(DASH, false);
|
| 333 | }
|
| 334 |
|
| 335 | public boolean isDashing() {
|
| 336 | return this.entityData.get(DASH);
|
| 337 | }
|
| 338 |
|
| 339 | public void setDashing(final boolean isDashing) {
|
| 340 | this.entityData.set(DASH, isDashing);
|
| 341 | }
|
| 342 |
|
| 343 | protected void executeRidersJump(final float amount, final Player controller) {
|
| 344 | this.addDeltaMovement(
|
| 345 | controller.getLookAngle().scale((this.isInWater() ? 1.2F : 0.5F) * amount * this.getAttributeValue(Attributes.MOVEMENT_SPEED) * this.getBlockSpeedFactor())
|
| 346 | );
|
| 347 | this.dashCooldown = 40;
|
| 348 | this.setDashing(true);
|
| 349 | this.needsSync = true;
|
| 350 | }
|
| 351 |
|
| 352 | @Override
|
| 353 | public void handleStartJump(final int jumpScale) {
|
| 354 | this.makeSound(this.getDashSound());
|
| 355 | this.gameEvent(GameEvent.ENTITY_ACTION);
|
| 356 | this.setDashing(true);
|
| 357 | }
|
| 358 |
|
| 359 | @Override
|
| 360 | public int getJumpCooldown() {
|
| 361 | return this.dashCooldown;
|
| 362 | }
|
| 363 |
|
| 364 | @Override
|
| 365 | public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
|
| 366 | if (!this.firstTick && DASH.equals(accessor)) {
|
| 367 | this.dashCooldown = this.dashCooldown == 0 ? 40 : this.dashCooldown;
|
| 368 | }
|
| 369 |
|
| 370 | super.onSyncedDataUpdated(accessor);
|
| 371 | }
|
| 372 |
|
| 373 | @Override
|
| 374 | public void handleStopJump() {
|
| 375 | }
|
| 376 |
|
| 377 | @Override
|
| 378 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 379 | }
|
| 380 |
|
| 381 | protected @Nullable SoundEvent getDashSound() {
|
| 382 | return null;
|
| 383 | }
|
| 384 |
|
| 385 | protected @Nullable SoundEvent getDashReadySound() {
|
| 386 | return null;
|
| 387 | }
|
| 388 |
|
| 389 | @Override
|
| 390 | public InteractionResult interact(final Player player, final InteractionHand hand, final Vec3 location) {
|
| 391 | this.setPersistenceRequired();
|
| 392 | return super.interact(player, hand, location);
|
| 393 | }
|
| 394 |
|
| 395 | @Override
|
| 396 | public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
|
| 397 | ItemStack itemStack = player.getItemInHand(hand);
|
| 398 | if (this.isBaby()) {
|
| 399 | return super.mobInteract(player, hand);
|
| 400 | }
|
| 401 |
|
| 402 | if (this.isTame() && player.isSecondaryUseActive()) {
|
| 403 | this.openCustomInventoryScreen(player);
|
| 404 | return InteractionResult.SUCCESS;
|
| 405 | }
|
| 406 |
|
| 407 | if (!itemStack.isEmpty()) {
|
| 408 | if (!this.level().isClientSide() && !this.isTame() && this.isFood(itemStack)) {
|
| 409 | this.usePlayerItem(player, hand, itemStack);
|
| 410 | this.tryToTame(player);
|
| 411 | return InteractionResult.SUCCESS_SERVER;
|
| 412 | }
|
| 413 |
|
| 414 | if (this.isFood(itemStack) && this.getHealth() < this.getMaxHealth()) {
|
| 415 | this.feed(player, hand, itemStack, 2.0F, 1.0F);
|
| 416 | return InteractionResult.SUCCESS;
|
| 417 | }
|
| 418 |
|
| 419 | InteractionResult interactionResult = itemStack.interactLivingEntity(player, this, hand);
|
| 420 | if (interactionResult.consumesAction()) {
|
| 421 | return interactionResult;
|
| 422 | }
|
| 423 | }
|
| 424 |
|
| 425 | if (this.isTame() && !player.isSecondaryUseActive() && !this.isFood(itemStack)) {
|
| 426 | this.doPlayerRide(player);
|
| 427 | return InteractionResult.SUCCESS;
|
| 428 | } else {
|
| 429 | return super.mobInteract(player, hand);
|
| 430 | }
|
| 431 | }
|
| 432 |
|
| 433 | private void tryToTame(final Player player) {
|
| 434 | if (this.random.nextInt(3) == 0) {
|
| 435 | this.tame(player);
|
| 436 | this.navigation.stop();
|
| 437 | this.level().broadcastEntityEvent(this, (byte)7);
|
| 438 | } else {
|
| 439 | this.level().broadcastEntityEvent(this, (byte)6);
|
| 440 | }
|
| 441 |
|
| 442 | this.playEatingSound();
|
| 443 | }
|
| 444 |
|
| 445 | @Override
|
| 446 | public boolean removeWhenFarAway(final double distSqr) {
|
| 447 | return true;
|
| 448 | }
|
| 449 |
|
| 450 | @Override
|
| 451 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 452 | boolean wasHurt = super.hurtServer(level, source, damage);
|
| 453 | if (wasHurt && source.getEntity() instanceof LivingEntity sourceEntity) {
|
| 454 | NautilusAi.setAngerTarget(level, this, sourceEntity);
|
| 455 | }
|
| 456 |
|
| 457 | return wasHurt;
|
| 458 | }
|
| 459 |
|
| 460 | @Override
|
| 461 | public boolean canBeAffected(final MobEffectInstance newEffect) {
|
| 462 | return newEffect.getEffect() == MobEffects.POISON ? false : super.canBeAffected(newEffect);
|
| 463 | }
|
| 464 |
|
| 465 | @Override
|
| 466 | public SpawnGroupData finalizeSpawn(
|
| 467 | final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
|
| 468 | ) {
|
| 469 | RandomSource random = level.getRandom();
|
| 470 | NautilusAi.initMemories(this, random);
|
| 471 | return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
|
| 472 | }
|
| 473 |
|
| 474 | @Override
|
| 475 | protected Holder<SoundEvent> getEquipSound(final EquipmentSlot slot, final ItemStack stack, final Equippable equippable) {
|
| 476 | if (slot == EquipmentSlot.SADDLE && this.isUnderWater()) {
|
| 477 | return SoundEvents.NAUTILUS_SADDLE_UNDERWATER_EQUIP;
|
| 478 | } else {
|
| 479 | return slot == EquipmentSlot.SADDLE ? SoundEvents.NAUTILUS_SADDLE_EQUIP : super.getEquipSound(slot, stack, equippable);
|
| 480 | }
|
| 481 | }
|
| 482 |
|
| 483 | public final int getInventorySize() {
|
| 484 | return AbstractMountInventoryMenu.getInventorySize(this.getInventoryColumns());
|
| 485 | }
|
| 486 |
|
| 487 | protected void createInventory() {
|
| 488 | SimpleContainer old = this.inventory;
|
| 489 | this.inventory = new SimpleContainer(this.getInventorySize());
|
| 490 | if (old != null) {
|
| 491 | int max = Math.min(old.getContainerSize(), this.inventory.getContainerSize());
|
| 492 |
|
| 493 | for (int slot = 0; slot < max; slot++) {
|
| 494 | ItemStack itemStack = old.getItem(slot);
|
| 495 | if (!itemStack.isEmpty()) {
|
| 496 | this.inventory.setItem(slot, itemStack.copy());
|
| 497 | }
|
| 498 | }
|
| 499 | }
|
| 500 | }
|
| 501 |
|
| 502 | @Override
|
| 503 | public void openCustomInventoryScreen(final Player player) {
|
| 504 | if (!this.level().isClientSide() && (!this.isVehicle() || this.hasPassenger(player)) && this.isTame()) {
|
| 505 | player.openNautilusInventory(this, this.inventory);
|
| 506 | }
|
| 507 | }
|
| 508 |
|
| 509 | @Override
|
| 510 | public @Nullable SlotAccess getSlot(final int slot) {
|
| 511 | int inventorySlot = slot - 500;
|
| 512 | return inventorySlot >= 0 && inventorySlot < this.inventory.getContainerSize() ? this.inventory.getSlot(inventorySlot) : super.getSlot(slot);
|
| 513 | }
|
| 514 |
|
| 515 | public boolean hasInventoryChanged(final Container oldInventory) {
|
| 516 | return this.inventory != oldInventory;
|
| 517 | }
|
| 518 |
|
| 519 | public int getInventoryColumns() {
|
| 520 | return 0;
|
| 521 | }
|
| 522 |
|
| 523 | protected boolean isMobControlled() {
|
| 524 | return this.getFirstPassenger() instanceof Mob;
|
| 525 | }
|
| 526 |
|
| 527 | protected boolean isAggravated() {
|
| 528 | return this.getBrain().hasMemoryValue(MemoryModuleType.ANGRY_AT) || this.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET);
|
| 529 | }
|
| 530 |
|
| 531 | @Override
|
| 532 | public boolean requiresCustomPersistence() {
|
| 533 | return super.requiresCustomPersistence() || this.isTame();
|
| 534 | }
|
| 535 | }
|
| 536 |
|