aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ContainerOpenPacket.cpp
blob: d52689224f453e5e4abd3e18cfcc20083c68e557 (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
76
77
78
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "ContainerOpenPacket.h"

void ContainerOpenPacket::_init(int containerId, int type, const wstring &title, int size, bool customName, int entityId)
{
	this->containerId = containerId;
	this->type = type;
	this->title = title;
	this->size = size;
	this->customName = customName;
	this->entityId = entityId;
}

ContainerOpenPacket::ContainerOpenPacket()
{
	_init(0, 0, L"", 0, false, 0);

}

ContainerOpenPacket::ContainerOpenPacket(int containerId, int type, const wstring &title, int size, bool customName) 
{
	_init(containerId, type, title, size, customName, 0);
}

ContainerOpenPacket::ContainerOpenPacket(int containerId, int type, const wstring &title, int size, bool customName, int entityId)
{
	_init(containerId, type, title, size, customName, entityId);
}

void ContainerOpenPacket::handle(PacketListener *listener)
{
	listener->handleContainerOpen(shared_from_this());
}


void ContainerOpenPacket::read(DataInputStream *dis) //throws IOException 
{
	containerId = dis->readByte() & 0xff;
	type = dis->readByte() & 0xff;
	size = dis->readByte() & 0xff;
	customName = dis->readBoolean();
	if (type == HORSE)
	{
		entityId = dis->readInt();
	}
	if(customName)
	{
		title = readUtf(dis,64);
	}
}

void ContainerOpenPacket::write(DataOutputStream *dos) //throws IOException
{
	dos->writeByte(containerId & 0xff);
	dos->writeByte(type & 0xff);
	dos->writeByte(size & 0xff);
	dos->writeBoolean(customName);
	if (type == HORSE)
	{
		dos->writeInt(entityId);
	}
	if(customName)
	{
		writeUtf(title, dos);
	}
}

int ContainerOpenPacket::getEstimatedSize() 
{
	if (type == HORSE)
	{
		return 10;
	}
	return 6;
}