AgeableWaterCreature .java

net.minecraft.world.entity.animal.AgeableWaterCreature (class): members: checkSurfaceAgeableWaterCreatureSpawnRules, handleAirSupply, baseTick, pos, level.

net.minecraft.world.entity.animalclass81 linescommonextends AgeableMob2.2 KB

API Surface (8)

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

Fields & Constants (4)

type
level
spawnReason
pos

Full Source

AgeableWaterCreature.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal;
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.AgeableMob;
8
import net.minecraft.world.entity.EntitySpawnReason;
9
import net.minecraft.world.entity.EntityType;
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 AgeableWaterCreature extends AgeableMob {
17
	protected AgeableWaterCreature(final EntityType<? extends AgeableWaterCreature> type, final Level level) {
18
		super(type, level);
19
		this.setPathfindingMalus(PathType.WATER, 0.0F);
20
	}
21
22
	@Override
23
	public boolean checkSpawnObstruction(final LevelReader level) {
24
		return level.isUnobstructed(this);
25
	}
26
27
	@Override
28
	public int getAmbientSoundInterval() {
29
		return 120;
30
	}
31
32
	@Override
33
	public int getBaseExperienceReward(final ServerLevel level) {
34
		return 1 + this.random.nextInt(3);
35
	}
36
37
	protected void handleAirSupply(final int preTickAirSupply) {
38
		if (this.isAlive() && !this.isInWater()) {
39
			this.setAirSupply(preTickAirSupply - 1);
40
			if (this.shouldTakeDrowningDamage()) {
41
				this.setAirSupply(0);
42
				this.hurt(this.damageSources().drown(), 2.0F);
43
			}
44
		} else {
45
			this.setAirSupply(300);
46
		}
47
	}
48
49
	@Override
50
	public void baseTick() {
51
		int airSupply = this.getAirSupply();
52
		super.baseTick();
53
		this.handleAirSupply(airSupply);
54
	}
55
56
	@Override
57
	public boolean isPushedByFluid() {
58
		return false;
59
	}
60
61
	@Override
62
	public boolean canBeLeashed() {
63
		return false;
64
	}
65
66
	public static boolean checkSurfaceAgeableWaterCreatureSpawnRules(
67
		final EntityType<? extends AgeableWaterCreature> type,
68
		final LevelAccessor level,
69
		final EntitySpawnReason spawnReason,
70
		final BlockPos pos,
71
		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 AgeableWaterCreature (net/minecraft/world/entity/animal/AgeableWaterCreature.java) with Mojang official mappings, stored verbatim on the site.