aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/WaterAnimal.cpp
blob: fe94b628e9fe6e1991c6c20510887a11982bf2b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "stdafx.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.damagesource.h"
#include "WaterAnimal.h"



WaterAnimal::WaterAnimal(Level *level) : PathfinderMob( level )
{
	// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
	// the derived version of the function is called

	// This should only be called for the most derive classes
	//this->defineSynchedData();
}

bool WaterAnimal::isWaterMob()
{
	return true; //prevent drowning
}

bool WaterAnimal::canSpawn()
{
	return level->isUnobstructed(bb);
}

int WaterAnimal::getAmbientSoundInterval()
{
	return 20 * 6;
}

bool WaterAnimal::removeWhenFarAway()
{
	return true;
}

int WaterAnimal::getExperienceReward(shared_ptr<Player> killedBy)
{
	return 1 + level->random->nextInt(3);
}

void WaterAnimal::baseTick()
{
	int airSupply = getAirSupply();

	PathfinderMob::baseTick(); // this modified the airsupply

	if (isAlive() && !isInWater())
	{
		setAirSupply(--airSupply);
		if (getAirSupply() == -20)
		{
			setAirSupply(0);
			hurt(DamageSource::drown, 2);
		}
	}
	else
	{
		setAirSupply(TOTAL_AIR_SUPPLY);
	}
}