| 1 | package net.minecraft.world.entity.animal.nautilus;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.server.level.ServerLevel;
|
| 5 | import net.minecraft.sounds.SoundEvent;
|
| 6 | import net.minecraft.sounds.SoundEvents;
|
| 7 | import net.minecraft.util.profiling.Profiler;
|
| 8 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 9 | import net.minecraft.world.damagesource.DamageSource;
|
| 10 | import net.minecraft.world.entity.AgeableMob;
|
| 11 | import net.minecraft.world.entity.EntityAttachment;
|
| 12 | import net.minecraft.world.entity.EntityAttachments;
|
| 13 | import net.minecraft.world.entity.EntityDimensions;
|
| 14 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 15 | import net.minecraft.world.entity.EntityType;
|
| 16 | import net.minecraft.world.entity.EntityTypes;
|
| 17 | import net.minecraft.world.entity.Pose;
|
| 18 | import net.minecraft.world.entity.ai.Brain;
|
| 19 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 20 | import net.minecraft.world.entity.ai.sensing.SensorType;
|
| 21 | import net.minecraft.world.level.Level;
|
| 22 | import org.jspecify.annotations.Nullable;
|
| 23 |
|
| 24 | public class Nautilus extends AbstractNautilus {
|
| 25 | private static final int NAUTILUS_TOTAL_AIR_SUPPLY = 300;
|
| 26 | private static final EntityDimensions BABY_DIMENSIONS = EntityTypes.NAUTILUS
|
| 27 | .getDimensions()
|
| 28 | .scale(0.5F)
|
| 29 | .withAttachments(EntityAttachments.builder().attach(EntityAttachment.PASSENGER, 0.0F, 0.5F, 0.0F));
|
| 30 | private static final Brain.Provider<Nautilus> BRAIN_PROVIDER = Brain.provider(
|
| 31 | List.of(MemoryModuleType.ANGRY_AT, MemoryModuleType.ATTACK_TARGET_COOLDOWN),
|
| 32 | List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_ADULT, SensorType.NEAREST_PLAYERS, SensorType.HURT_BY, SensorType.NAUTILUS_TEMPTATIONS),
|
| 33 | var0 -> NautilusAi.getActivities()
|
| 34 | );
|
| 35 |
|
| 36 | public Nautilus(final EntityType<? extends Nautilus> type, final Level level) {
|
| 37 | super(type, level);
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | protected Brain<Nautilus> makeBrain(final Brain.Packed packedBrain) {
|
| 42 | return BRAIN_PROVIDER.makeBrain(this, packedBrain);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public Brain<Nautilus> getBrain() {
|
| 47 | return super.getBrain();
|
| 48 | }
|
| 49 |
|
| 50 | public @Nullable Nautilus getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
|
| 51 | Nautilus baby = EntityTypes.NAUTILUS.create(level, EntitySpawnReason.BREEDING);
|
| 52 | if (baby != null && this.isTame()) {
|
| 53 | baby.setOwnerReference(this.getOwnerReference());
|
| 54 | baby.setTame(true, true);
|
| 55 | }
|
| 56 |
|
| 57 | return baby;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | public EntityDimensions getDefaultDimensions(final Pose pose) {
|
| 62 | return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected void customServerAiStep(final ServerLevel level) {
|
| 67 | ProfilerFiller profiler = Profiler.get();
|
| 68 | profiler.push("nautilusBrain");
|
| 69 | this.getBrain().tick(level, this);
|
| 70 | profiler.pop();
|
| 71 | profiler.push("nautilusActivityUpdate");
|
| 72 | NautilusAi.updateActivity(this);
|
| 73 | profiler.pop();
|
| 74 | super.customServerAiStep(level);
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | protected SoundEvent getAmbientSound() {
|
| 79 | if (this.isBaby()) {
|
| 80 | return this.isUnderWater() ? SoundEvents.BABY_NAUTILUS_AMBIENT : SoundEvents.BABY_NAUTILUS_AMBIENT_ON_LAND;
|
| 81 | } else {
|
| 82 | return this.isUnderWater() ? SoundEvents.NAUTILUS_AMBIENT : SoundEvents.NAUTILUS_AMBIENT_ON_LAND;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 88 | if (this.isBaby()) {
|
| 89 | return this.isUnderWater() ? SoundEvents.BABY_NAUTILUS_HURT : SoundEvents.BABY_NAUTILUS_HURT_ON_LAND;
|
| 90 | } else {
|
| 91 | return this.isUnderWater() ? SoundEvents.NAUTILUS_HURT : SoundEvents.NAUTILUS_HURT_ON_LAND;
|
| 92 | }
|
| 93 | }
|
| 94 |
|
| 95 | @Override
|
| 96 | protected SoundEvent getDeathSound() {
|
| 97 | if (this.isBaby()) {
|
| 98 | return this.isUnderWater() ? SoundEvents.BABY_NAUTILUS_DEATH : SoundEvents.BABY_NAUTILUS_DEATH_ON_LAND;
|
| 99 | } else {
|
| 100 | return this.isUnderWater() ? SoundEvents.NAUTILUS_DEATH : SoundEvents.NAUTILUS_DEATH_ON_LAND;
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | @Override
|
| 105 | protected SoundEvent getDashSound() {
|
| 106 | return this.isUnderWater() ? SoundEvents.NAUTILUS_DASH : SoundEvents.NAUTILUS_DASH_ON_LAND;
|
| 107 | }
|
| 108 |
|
| 109 | @Override
|
| 110 | protected SoundEvent getDashReadySound() {
|
| 111 | return this.isUnderWater() ? SoundEvents.NAUTILUS_DASH_READY : SoundEvents.NAUTILUS_DASH_READY_ON_LAND;
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | protected void playEatingSound() {
|
| 116 | SoundEvent nautilusEatSound = this.isBaby() ? SoundEvents.BABY_NAUTILUS_EAT : SoundEvents.NAUTILUS_EAT;
|
| 117 | this.makeSound(nautilusEatSound);
|
| 118 | }
|
| 119 |
|
| 120 | @Override
|
| 121 | protected SoundEvent getSwimSound() {
|
| 122 | return this.isBaby() ? SoundEvents.BABY_NAUTILUS_SWIM : SoundEvents.NAUTILUS_SWIM;
|
| 123 | }
|
| 124 |
|
| 125 | @Override
|
| 126 | public int getMaxAirSupply() {
|
| 127 | return 300;
|
| 128 | }
|
| 129 |
|
| 130 | protected void handleAirSupply(final ServerLevel level, final int preTickAirSupply) {
|
| 131 | if (this.isAlive() && !this.isInWater()) {
|
| 132 | this.setAirSupply(preTickAirSupply - 1);
|
| 133 | if (this.getAirSupply() <= -20) {
|
| 134 | this.setAirSupply(0);
|
| 135 | this.hurtServer(level, this.damageSources().dryOut(), 2.0F);
|
| 136 | }
|
| 137 | } else {
|
| 138 | this.setAirSupply(300);
|
| 139 | }
|
| 140 | }
|
| 141 |
|
| 142 | @Override
|
| 143 | public void baseTick() {
|
| 144 | int airSupply = this.getAirSupply();
|
| 145 | super.baseTick();
|
| 146 | if (!this.isNoAi() && this.level() instanceof ServerLevel serverLevel) {
|
| 147 | this.handleAirSupply(serverLevel, airSupply);
|
| 148 | }
|
| 149 | }
|
| 150 |
|
| 151 | @Override
|
| 152 | public boolean canBeLeashed() {
|
| 153 | return !this.isAggravated();
|
| 154 | }
|
| 155 | }
|
| 156 |
|