minecraft-src/net/minecraft/world/entity/animal/WaterAnimal.java
2025-07-04 01:41:11 +03:00

72 lines
1.9 KiB
Java

package net.minecraft.world.entity.animal;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.pathfinder.PathType;
public abstract class WaterAnimal extends PathfinderMob {
protected WaterAnimal(EntityType<? extends WaterAnimal> entityType, Level level) {
super(entityType, level);
this.setPathfindingMalus(PathType.WATER, 0.0F);
}
@Override
public boolean checkSpawnObstruction(LevelReader level) {
return level.isUnobstructed(this);
}
@Override
public int getAmbientSoundInterval() {
return 120;
}
@Override
protected int getBaseExperienceReward() {
return 1 + this.level().random.nextInt(3);
}
protected void handleAirSupply(int airSupply) {
if (this.isAlive() && !this.isInWaterOrBubble()) {
this.setAirSupply(airSupply - 1);
if (this.getAirSupply() == -20) {
this.setAirSupply(0);
this.hurt(this.damageSources().drown(), 2.0F);
}
} else {
this.setAirSupply(300);
}
}
@Override
public void baseTick() {
int i = this.getAirSupply();
super.baseTick();
this.handleAirSupply(i);
}
@Override
public boolean isPushedByFluid() {
return false;
}
@Override
public boolean canBeLeashed() {
return false;
}
public static boolean checkSurfaceWaterAnimalSpawnRules(
EntityType<? extends WaterAnimal> waterAnimal, LevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random
) {
int i = level.getSeaLevel();
int j = i - 13;
return pos.getY() >= j && pos.getY() <= i && level.getFluidState(pos.below()).is(FluidTags.WATER) && level.getBlockState(pos.above()).is(Blocks.WATER);
}
}