aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/UpdateMobEffectPacket.cpp
blob: e8879d7618d5feb9a02ff474ea3acad2b4dc9193 (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
65
66
67
68
69
70
71
72
73
74
75
#include "stdafx.h"
#include "net.minecraft.world.effect.h"
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "BasicTree.h"
#include "BasicTypeContainers.h"
#include "UpdateMobEffectPacket.h"



UpdateMobEffectPacket::UpdateMobEffectPacket()
{
	entityId = 0;
	effectId = 0;
	effectAmplifier = 0;
	effectDurationTicks = 0;
}

UpdateMobEffectPacket::UpdateMobEffectPacket(int entityId, MobEffectInstance *effect)
{
	this->entityId = entityId;
	effectId = static_cast<BYTE>(effect->getId() & 0xff);
	effectAmplifier = static_cast<char>(effect->getAmplifier() & 0xff);

	if (effect->getDuration() > Short::MAX_VALUE)
	{
		effectDurationTicks = Short::MAX_VALUE;
	}
	else
	{
		effectDurationTicks = static_cast<short>(effect->getDuration());
	}
}

void UpdateMobEffectPacket::read(DataInputStream *dis)
{
	entityId = dis->readInt();
	effectId = dis->readByte();
	effectAmplifier = dis->readByte();
	effectDurationTicks = dis->readShort();
}

void UpdateMobEffectPacket::write(DataOutputStream *dos)
{
	dos->writeInt(entityId);
	dos->writeByte(effectId);
	dos->writeByte(effectAmplifier);
	dos->writeShort(effectDurationTicks);
}

bool UpdateMobEffectPacket::isSuperLongDuration()
{
	return effectDurationTicks == Short::MAX_VALUE;
}

void UpdateMobEffectPacket::handle(PacketListener *listener)
{
	listener->handleUpdateMobEffect(shared_from_this());
}

int UpdateMobEffectPacket::getEstimatedSize()
{
	return 8;
}

bool UpdateMobEffectPacket::canBeInvalidated()
{
	return true;
}

bool UpdateMobEffectPacket::isInvalidatedBy(shared_ptr<Packet> packet)
{
	shared_ptr<UpdateMobEffectPacket> target = dynamic_pointer_cast<UpdateMobEffectPacket>(packet);
	return target->entityId == entityId && target->effectId == effectId;
}