aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/TileEntityDataPacket.cpp
blob: a30f7873a1352fe44fa8e5b47b9ea63657d02e18 (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
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "TileEntityDataPacket.h"



void TileEntityDataPacket::_init()
{
	x = y = z = 0;
	type = TYPE_MOB_SPAWNER;
	tag = nullptr;
}


TileEntityDataPacket::TileEntityDataPacket()
{
	_init();
	shouldDelay = true;
}

TileEntityDataPacket::TileEntityDataPacket(int x, int y, int z, int type, CompoundTag *tag)
{
	_init();
	shouldDelay = true;
	this->x = x;
	this->y = y;
	this->z = z;
	this->type = type;
	this->tag = tag;
}

TileEntityDataPacket::~TileEntityDataPacket()
{
	delete tag;
}

void TileEntityDataPacket::read(DataInputStream *dis)
{
	x = dis->readInt();
	y = dis->readShort();
	z = dis->readInt();
	type = dis->readByte();
	tag = readNbt(dis);
}

void TileEntityDataPacket::write(DataOutputStream *dos)
{
	dos->writeInt(x);
	dos->writeShort(y);
	dos->writeInt(z);
	dos->writeByte(static_cast<byte>(type));
	writeNbt(tag, dos);
}

void TileEntityDataPacket::handle(PacketListener *listener)
{
	listener->handleTileEntityData(shared_from_this());
}

int TileEntityDataPacket::getEstimatedSize()
{
	return 6 * 4 + 1;
}