aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ContainerSetContentPacket.cpp
blob: 13cfebd7c66dc1c06cc5fdf4ed8cf9a0061cdd01 (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
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "net.minecraft.world.item.h"
#include "PacketListener.h"
#include "ContainerSetContentPacket.h"



ContainerSetContentPacket::~ContainerSetContentPacket()
{
	delete[] items.data;
}

ContainerSetContentPacket::ContainerSetContentPacket() 
{
	containerId = 0;
}

ContainerSetContentPacket::ContainerSetContentPacket(int containerId, vector<shared_ptr<ItemInstance> > *newItems)
{
	this->containerId = containerId;
	items = ItemInstanceArray((int)newItems->size());
	for (unsigned int i = 0; i < items.length; i++)
	{
		shared_ptr<ItemInstance> item = newItems->at(i);
		items[i] = item == NULL ? nullptr : item->copy();
	}
}

void ContainerSetContentPacket::read(DataInputStream *dis) //throws IOException 
{
	containerId = dis->readByte();
	int count = dis->readShort();
	items = ItemInstanceArray(count);
	for (int i = 0; i < count; i++) 
	{
		items[i] = readItem(dis);
	}
}

void ContainerSetContentPacket::write(DataOutputStream *dos) //throws IOException
{
	dos->writeByte(containerId);
	dos->writeShort(items.length);
	for (unsigned int i = 0; i < items.length; i++) 
	{
		writeItem(items[i], dos);
	}
}

void ContainerSetContentPacket::handle(PacketListener *listener)
{
	listener->handleContainerContent(shared_from_this());
}

int ContainerSetContentPacket::getEstimatedSize() 
{
	return 3 + items.length * 5;
}