aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/UseItemPacket.cpp
blob: d9699130a49c63c9f14e459ee8f9c62ddbc38678 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "net.minecraft.world.item.h"
#include "PacketListener.h"
#include "UseItemPacket.h"

const float UseItemPacket::CLICK_ACCURACY = 16.0f;

UseItemPacket::~UseItemPacket() 
{
}

UseItemPacket::UseItemPacket() 
{
	x = 0;
	y = 0;
	z = 0;
	face = 0;
	item = nullptr;
	clickX = 0.0f;
	clickY = 0.0f;
	clickZ = 0.0f;
}

UseItemPacket::UseItemPacket(int x, int y, int z, int face, shared_ptr<ItemInstance> item, float clickX, float clickY, float clickZ) 
{
	this->x = x;
	this->y = y;
	this->z = z;
	this->face = face;
	// 4J - take copy of item as we want our packets to have full ownership of any referenced data
	this->item = item ? item->copy() : shared_ptr<ItemInstance>();
	this->clickX = clickX;
	this->clickY = clickY;
	this->clickZ = clickZ;
}

void UseItemPacket::read(DataInputStream *dis) //throws IOException 
{
	x = dis->readInt();
	y = dis->read();
	z = dis->readInt();
	face = dis->read();
	item = readItem(dis);
	clickX = dis->read() / CLICK_ACCURACY;
	clickY = dis->read() / CLICK_ACCURACY;
	clickZ = dis->read() / CLICK_ACCURACY;
}

void UseItemPacket::write(DataOutputStream *dos) //throws IOException 
{
	dos->writeInt(x);
	dos->write(y);
	dos->writeInt(z);
	dos->write(face);

	writeItem(item, dos);
	dos->write((int) (clickX * CLICK_ACCURACY));
	dos->write((int) (clickY * CLICK_ACCURACY));
	dos->write((int)(clickZ * CLICK_ACCURACY));
}

void UseItemPacket::handle(PacketListener *listener)
{
	listener->handleUseItem(shared_from_this());
}

int UseItemPacket::getEstimatedSize()
{
	return 15;
}

int UseItemPacket::getX()
{
	return x;
}

int UseItemPacket::getY()
{
	return y;
}

int UseItemPacket::getZ()
{
	return z;
}

int UseItemPacket::getFace()
{
	return face;
}

shared_ptr<ItemInstance> UseItemPacket::getItem()
{
	return item;
}

float UseItemPacket::getClickX()
{
	return clickX;
}

float UseItemPacket::getClickY()
{
	return clickY;
}

float UseItemPacket::getClickZ()
{
	return clickZ;
}