WaterAnimal .java

net.minecraft.world.entity.animal.fish.WaterAnimal (class): members: checkSurfaceWaterAnimalSpawnRules, AMBIENT_SOUND_INTERVAL, handleAirSupply, baseTick.

net.minecraft.world.entity.animal.fishclass81 linescommonextends PathfinderMob2.3 KB

API Surface (8)

boolean checkSpawnObstruction(final LevelReader level)
int getAmbientSoundInterval()
int getBaseExperienceReward(final ServerLevel level)
void handleAirSupply(final ServerLevel level, final int preTickAirSupply)
void baseTick()
boolean isPushedByFluid()
boolean canBeLeashed()
boolean checkSurfaceWaterAnimalSpawnRules(final EntityType<? extends WaterAnimal> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random)

Fields & Constants (2)

AMBIENT_SOUND_INTERVAL
pos

Full Source

WaterAnimal.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.fish;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.tags.FluidTags;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.entity.EntitySpawnReason;
8
import net.minecraft.world.entity.EntityType;
9
import net.minecraft.world.entity.PathfinderMob;
10
import net.minecraft.world.level.Level;
11
import net.minecraft.world.level.LevelAccessor;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.block.Blocks;
14
import net.minecraft.world.level.pathfinder.PathType;
15
16
public abstract class WaterAnimal extends PathfinderMob {
17
	public static final int AMBIENT_SOUND_INTERVAL = 120;
18
19
	protected WaterAnimal(final EntityType<? extends WaterAnimal> type, final Level level) {
20
		super(type, level);
21
		this.setPathfindingMalus(PathType.WATER, 0.0F);
22
	}
23
24
	@Override
25
	public boolean checkSpawnObstruction(final LevelReader level) {
26
		return level.isUnobstructed(this);
27
	}
28
29
	@Override
30
	public int getAmbientSoundInterval() {
31
		return 120;
32
	}
33
34
	@Override
35
	protected int getBaseExperienceReward(final ServerLevel level) {
36
		return 1 + this.random.nextInt(3);
37
	}
38
39
	protected void handleAirSupply(final ServerLevel level, final int preTickAirSupply) {
40
		if (this.isAlive() && !this.isInWater()) {
41
			this.setAirSupply(preTickAirSupply - 1);
42
			if (this.shouldTakeDrowningDamage()) {
43
				this.setAirSupply(0);
44
				this.hurtServer(level, this.damageSources().drown(), 2.0F);
45
			}
46
		} else {
47
			this.setAirSupply(300);
48
		}
49
	}
50
51
	@Override
52
	public void baseTick() {
53
		int airSupply = this.getAirSupply();
54
		super.baseTick();
55
		if (this.level() instanceof ServerLevel serverLevel) {
56
			this.handleAirSupply(serverLevel, airSupply);
57
		}
58
	}
59
60
	@Override
61
	public boolean isPushedByFluid() {
62
		return false;
63
	}
64
65
	@Override
66
	public boolean canBeLeashed() {
67
		return false;
68
	}
69
70
	public static boolean checkSurfaceWaterAnimalSpawnRules(
71
		final EntityType<? extends WaterAnimal> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
72
	) {
73
		int seaLevel = level.getSeaLevel();
74
		int minSpawnLevel = seaLevel - 13;
75
		return pos.getY() >= minSpawnLevel
76
			&& pos.getY() <= seaLevel
77
			&& level.getFluidState(pos.below()).is(FluidTags.WATER)
78
			&& level.getBlockState(pos.above()).is(Blocks.WATER);
79
	}
80
}
81

Decompiled Minecraft 26.3 source of WaterAnimal (net/minecraft/world/entity/animal/fish/WaterAnimal.java) with Mojang official mappings, stored verbatim on the site.