| 1 | package net.minecraft.world.entity.animal.nautilus;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.Holder;
|
| 5 | import net.minecraft.core.component.DataComponentGetter;
|
| 6 | import net.minecraft.core.component.DataComponentType;
|
| 7 | import net.minecraft.core.component.DataComponents;
|
| 8 | import net.minecraft.core.registries.Registries;
|
| 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.util.profiling.Profiler;
|
| 16 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 17 | import net.minecraft.world.DifficultyInstance;
|
| 18 | import net.minecraft.world.damagesource.DamageSource;
|
| 19 | import net.minecraft.world.entity.AgeableMob;
|
| 20 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 21 | import net.minecraft.world.entity.EntityType;
|
| 22 | import net.minecraft.world.entity.EquipmentSlot;
|
| 23 | import net.minecraft.world.entity.SpawnGroupData;
|
| 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.memory.MemoryModuleType;
|
| 28 | import net.minecraft.world.entity.ai.sensing.SensorType;
|
| 29 | import net.minecraft.world.entity.variant.SpawnContext;
|
| 30 | import net.minecraft.world.entity.variant.VariantUtils;
|
| 31 | import net.minecraft.world.level.Level;
|
| 32 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 33 | import net.minecraft.world.level.storage.ValueInput;
|
| 34 | import net.minecraft.world.level.storage.ValueOutput;
|
| 35 | import org.jspecify.annotations.Nullable;
|
| 36 |
|
| 37 | public class ZombieNautilus extends AbstractNautilus {
|
| 38 | private static final Brain.Provider<ZombieNautilus> BRAIN_PROVIDER = Brain.provider(
|
| 39 | List.of(MemoryModuleType.ANGRY_AT, MemoryModuleType.ATTACK_TARGET_COOLDOWN),
|
| 40 | List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_ADULT, SensorType.NEAREST_PLAYERS, SensorType.HURT_BY, SensorType.NAUTILUS_TEMPTATIONS),
|
| 41 | var0 -> ZombieNautilusAi.getActivities()
|
| 42 | );
|
| 43 | private static final EntityDataAccessor<Holder<ZombieNautilusVariant>> DATA_VARIANT_ID = SynchedEntityData.defineId(
|
| 44 | ZombieNautilus.class, EntityDataSerializers.ZOMBIE_NAUTILUS_VARIANT
|
| 45 | );
|
| 46 |
|
| 47 | public ZombieNautilus(final EntityType<? extends ZombieNautilus> type, final Level level) {
|
| 48 | super(type, level);
|
| 49 | }
|
| 50 |
|
| 51 | public static AttributeSupplier.Builder createAttributes() {
|
| 52 | return AbstractNautilus.createAttributes().add(Attributes.MOVEMENT_SPEED, 1.1F);
|
| 53 | }
|
| 54 |
|
| 55 | public @Nullable ZombieNautilus getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
|
| 56 | return null;
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected EquipmentSlot sunProtectionSlot() {
|
| 61 | return EquipmentSlot.BODY;
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | protected Brain<ZombieNautilus> makeBrain(final Brain.Packed packedBrain) {
|
| 66 | return BRAIN_PROVIDER.makeBrain(this, packedBrain);
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public Brain<ZombieNautilus> getBrain() {
|
| 71 | return super.getBrain();
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | protected void customServerAiStep(final ServerLevel level) {
|
| 76 | ProfilerFiller profiler = Profiler.get();
|
| 77 | profiler.push("zombieNautilusBrain");
|
| 78 | this.getBrain().tick(level, this);
|
| 79 | profiler.pop();
|
| 80 | profiler.push("zombieNautilusActivityUpdate");
|
| 81 | ZombieNautilusAi.updateActivity(this);
|
| 82 | profiler.pop();
|
| 83 | super.customServerAiStep(level);
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | protected SoundEvent getAmbientSound() {
|
| 88 | return this.isUnderWater() ? SoundEvents.ZOMBIE_NAUTILUS_AMBIENT : SoundEvents.ZOMBIE_NAUTILUS_AMBIENT_ON_LAND;
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 93 | return this.isUnderWater() ? SoundEvents.ZOMBIE_NAUTILUS_HURT : SoundEvents.ZOMBIE_NAUTILUS_HURT_ON_LAND;
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | protected SoundEvent getDeathSound() {
|
| 98 | return this.isUnderWater() ? SoundEvents.ZOMBIE_NAUTILUS_DEATH : SoundEvents.ZOMBIE_NAUTILUS_DEATH_ON_LAND;
|
| 99 | }
|
| 100 |
|
| 101 | @Override
|
| 102 | protected SoundEvent getDashSound() {
|
| 103 | return this.isUnderWater() ? SoundEvents.ZOMBIE_NAUTILUS_DASH : SoundEvents.ZOMBIE_NAUTILUS_DASH_ON_LAND;
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | protected SoundEvent getDashReadySound() {
|
| 108 | return this.isUnderWater() ? SoundEvents.ZOMBIE_NAUTILUS_DASH_READY : SoundEvents.ZOMBIE_NAUTILUS_DASH_READY_ON_LAND;
|
| 109 | }
|
| 110 |
|
| 111 | @Override
|
| 112 | protected void playEatingSound() {
|
| 113 | this.makeSound(SoundEvents.ZOMBIE_NAUTILUS_EAT);
|
| 114 | }
|
| 115 |
|
| 116 | @Override
|
| 117 | protected SoundEvent getSwimSound() {
|
| 118 | return SoundEvents.ZOMBIE_NAUTILUS_SWIM;
|
| 119 | }
|
| 120 |
|
| 121 | @Override
|
| 122 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 123 | super.defineSynchedData(entityData);
|
| 124 | entityData.define(DATA_VARIANT_ID, VariantUtils.getDefaultOrAny(this.registryAccess(), ZombieNautilusVariants.TEMPERATE));
|
| 125 | }
|
| 126 |
|
| 127 | @Override
|
| 128 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 129 | super.readAdditionalSaveData(input);
|
| 130 | VariantUtils.readVariant(input, Registries.ZOMBIE_NAUTILUS_VARIANT).ifPresent(this::setVariant);
|
| 131 | }
|
| 132 |
|
| 133 | @Override
|
| 134 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 135 | super.addAdditionalSaveData(output);
|
| 136 | VariantUtils.writeVariant(output, this.getVariant());
|
| 137 | }
|
| 138 |
|
| 139 | public void setVariant(final Holder<ZombieNautilusVariant> variant) {
|
| 140 | this.entityData.set(DATA_VARIANT_ID, variant);
|
| 141 | }
|
| 142 |
|
| 143 | public Holder<ZombieNautilusVariant> getVariant() {
|
| 144 | return this.entityData.get(DATA_VARIANT_ID);
|
| 145 | }
|
| 146 |
|
| 147 | @Override
|
| 148 | public <T> @Nullable T get(final DataComponentType<? extends T> type) {
|
| 149 | return type == DataComponents.ZOMBIE_NAUTILUS_VARIANT ? castComponentValue((DataComponentType<T>)type, this.getVariant()) : super.get(type);
|
| 150 | }
|
| 151 |
|
| 152 | @Override
|
| 153 | protected void applyImplicitComponents(final DataComponentGetter components) {
|
| 154 | this.applyImplicitComponentIfPresent(components, DataComponents.ZOMBIE_NAUTILUS_VARIANT);
|
| 155 | super.applyImplicitComponents(components);
|
| 156 | }
|
| 157 |
|
| 158 | @Override
|
| 159 | protected <T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value) {
|
| 160 | if (type == DataComponents.ZOMBIE_NAUTILUS_VARIANT) {
|
| 161 | Holder<ZombieNautilusVariant> variant = castComponentValue(DataComponents.ZOMBIE_NAUTILUS_VARIANT, value);
|
| 162 | this.setVariant(variant);
|
| 163 | return true;
|
| 164 | } else {
|
| 165 | return super.applyImplicitComponent(type, value);
|
| 166 | }
|
| 167 | }
|
| 168 |
|
| 169 | @Override
|
| 170 | public SpawnGroupData finalizeSpawn(
|
| 171 | final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
|
| 172 | ) {
|
| 173 | VariantUtils.selectVariantToSpawn(SpawnContext.create(level, this.blockPosition()), Registries.ZOMBIE_NAUTILUS_VARIANT).ifPresent(this::setVariant);
|
| 174 | return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
|
| 175 | }
|
| 176 |
|
| 177 | @Override
|
| 178 | public boolean canBeLeashed() {
|
| 179 | return !this.isAggravated() && !this.isMobControlled();
|
| 180 | }
|
| 181 |
|
| 182 | @Override
|
| 183 | protected boolean canBeABaby() {
|
| 184 | return false;
|
| 185 | }
|
| 186 | }
|
| 187 |
|