the whole game

This commit is contained in:
Kolyah35
2026-03-02 22:04:18 +03:00
parent 816e9060b4
commit f0617a5d22
2069 changed files with 581500 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AddEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AddEntityPacket_H__
#include "../Packet.h"
#include "../../world/entity/Entity.h"
class AddEntityPacket : public Packet
{
public:
AddEntityPacket() {}
AddEntityPacket(const Entity* e, int data = 0)
: entityId(e->entityId),
type(e->getEntityTypeId()),
x(e->x),
y(e->y),
z(e->z),
_data(data)
{
if (hasMovementData()) {
xd = e->xd;
yd = e->yd;
zd = e->zd;
}
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADDENTITY));
bitStream->Write(entityId);
unsigned char bType = (unsigned char)type;
bitStream->Write(bType);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(_data);
if (hasMovementData()) {
const float M = 3.9f;
short xa = (short)(8000.0f * Mth::clamp(xd, -M, M));
short ya = (short)(8000.0f * Mth::clamp(yd, -M, M));
short za = (short)(8000.0f * Mth::clamp(zd, -M, M));
bitStream->Write(xa);
bitStream->Write(ya);
bitStream->Write(za);
}
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
unsigned char bType;
bitStream->Read(bType);
type = bType;
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(_data);
if (hasMovementData()) {
short xa, ya, za;
bitStream->Read(xa);
bitStream->Read(ya);
bitStream->Read(za);
xd = xa / 8000.0f;
yd = ya / 8000.0f;
zd = za / 8000.0f;
}
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AddEntityPacket*)this);
}
bool hasMovementData() {
return _data > 0;
}
int data() {
return _data;
}
public:
int entityId;
float x, y, z;
float xd, yd, zd;
int type;
private:
int _data;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AddEntityPacket_H__*/

View File

@@ -0,0 +1,78 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AddItemEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AddItemEntityPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/entity/item/ItemEntity.h"
#include "../../world/item/ItemInstance.h"
#include "../../util/Mth.h"
class AddItemEntityPacket: public Packet {
public:
AddItemEntityPacket() {
}
AddItemEntityPacket(const ItemEntity* itemEntity)
: id(itemEntity->entityId),
itemId(itemEntity->item.id),
itemCount(itemEntity->item.count),
auxValue(itemEntity->item.getAuxValue()),
x(itemEntity->x),
y(itemEntity->y),
z(itemEntity->z),
_xa((signed char) (itemEntity->xd * 128.0)),
_ya((signed char) (itemEntity->yd * 128.0)),
_za((signed char) (itemEntity->zd * 128.0))
{
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(id);
bitStream->Read(itemId);
bitStream->Read(itemCount);
bitStream->Read(auxValue);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(_xa);
bitStream->Read(_ya);
bitStream->Read(_za);
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADDITEMENTITY));
bitStream->Write(id);
bitStream->Write(itemId);
bitStream->Write(itemCount);
bitStream->Write(auxValue);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(_xa);
bitStream->Write(_ya);
bitStream->Write(_za);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AddItemEntityPacket*)this);
}
float xa() { return (float)(_xa) / 128.0f; }
float ya() { return (float)(_ya) / 128.0f; }
float za() { return (float)(_za) / 128.0f; }
int id;
float x, y, z;
short itemId;
short auxValue;
unsigned char itemCount;
private:
signed char _xa, _ya, _za;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AddItemEntityPacket_H__*/

View File

@@ -0,0 +1,78 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AddMobPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AddMobPacket_H__
#include "../Packet.h"
#include "../../world/entity/Mob.h"
#include "../../util/RakDataIO.h"
class AddMobPacket : public Packet
{
public:
AddMobPacket()
: _entityData(NULL)
{
}
~AddMobPacket() {
for (unsigned int i = 0; i < unpack.size(); ++i)
delete unpack[i];
}
AddMobPacket(const Mob* mob)
: entityId(mob->entityId),
type(mob->getEntityTypeId()),
x(mob->x),
y(mob->y),
z(mob->z),
xRot(mob->xRot),
yRot(mob->yRot),
_entityData(mob->getEntityData())
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADDMOB));
bitStream->Write(entityId);
bitStream->Write(type);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(PacketUtil::Rot_degreesToChar(yRot));
bitStream->Write(PacketUtil::Rot_degreesToChar(xRot));
RakDataOutput dos(*bitStream);
_entityData->packAll(&dos);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(type);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
char rx, ry;
bitStream->Read(ry);
bitStream->Read(rx);
RakDataInput dis(*bitStream);
unpack = SynchedEntityData::unpack(&dis);
yRot = PacketUtil::Rot_degreesToChar(ry);
xRot = PacketUtil::Rot_charToDegrees(rx);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AddMobPacket*)this);
}
public:
int entityId;
int type;
float x, y, z;
float xRot, yRot;
SynchedEntityData::DataList unpack;
private:
const SynchedEntityData* _entityData;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AddMobPacket_H__*/

View File

@@ -0,0 +1,48 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AddPaintingPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AddPaintingPacket_H__
#include "../Packet.h"
#include "../../world/entity/Painting.h"
class AddPaintingPacket : public Packet {
public:
AddPaintingPacket() : entityId(0), xTile(0), yTile(0), zTile(0), dir(-1) {
}
AddPaintingPacket(Painting* painting) {
entityId = painting->entityId;
xTile = painting->xTile;
yTile = painting->yTile;
zTile = painting->zTile;
dir = painting->dir;
motive = painting->motive->name;
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADDPAINTING));
bitStream->Write(entityId);
bitStream->Write(xTile);
bitStream->Write(yTile);
bitStream->Write(zTile);
bitStream->Write(dir);
RakNet::RakString rakMotive(motive.c_str());
bitStream->Write(rakMotive);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(entityId);
bitStream->Read(xTile);
bitStream->Read(yTile);
bitStream->Read(zTile);
bitStream->Read(dir);
RakNet::RakString rakMotive;
bitStream->Read(rakMotive);
motive = std::string(rakMotive.C_String());
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (AddPaintingPacket*)this);
}
public:
int entityId;
int xTile, yTile, zTile;
int dir;
std::string motive;
};
#endif /* NET_MINECRAFT_NETWORK_PACKET__AddPaintingPacket_H__ */

View File

@@ -0,0 +1,93 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AddPlayerPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AddPlayerPacket_H__
#include "../Packet.h"
#include "../../world/entity/player/Player.h"
#include "../../world/entity/player/Inventory.h"
class AddPlayerPacket : public Packet
{
public:
AddPlayerPacket()
: _entityData(NULL)
{}
AddPlayerPacket(const Player* p)
: owner(p->owner),
name(p->name.c_str()),
entityId(p->entityId),
x(p->x),
y(p->y - p->heightOffset),
z(p->z),
xRot(p->xRot),
yRot(p->yRot),
carriedItemId(0),
carriedItemAuxValue(0),
_entityData(p->getEntityData())
{
if (ItemInstance* item = p->inventory->getSelected()) {
carriedItemId = item->id;
carriedItemAuxValue = item->getAuxValue();
}
}
~AddPlayerPacket() {
for (unsigned int i = 0; i < unpack.size(); ++i)
delete unpack[i];
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADDPLAYER));
bitStream->Write(owner);
bitStream->Write(name);
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(PacketUtil::Rot_degreesToChar(yRot));
bitStream->Write(PacketUtil::Rot_degreesToChar(xRot));
bitStream->Write(carriedItemId);
bitStream->Write(carriedItemAuxValue);
RakDataOutput dos(*bitStream);
_entityData->packAll(&dos);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(owner);
bitStream->Read(name);
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
char rx, ry;
bitStream->Read(ry);
bitStream->Read(rx);
bitStream->Read(carriedItemId);
bitStream->Read(carriedItemAuxValue);
RakDataInput dis(*bitStream);
unpack = SynchedEntityData::unpack(&dis);
yRot = PacketUtil::Rot_degreesToChar(ry);
xRot = PacketUtil::Rot_charToDegrees(rx);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AddPlayerPacket*)this);
}
RakNet::RakNetGUID owner;
RakNet::RakString name;
int entityId;
float x, y, z;
float xRot, yRot;
short carriedItemId;
short carriedItemAuxValue;
SynchedEntityData::DataList unpack;
private:
const SynchedEntityData* _entityData;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AddPlayerPacket_H__*/

View File

@@ -0,0 +1,67 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AdventureSettingsPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AdventureSettingsPacket_H__
#include "../Packet.h"
#include "../../world/level/Level.h"
class AdventureSettingsPacket: public Packet
{
public:
enum Flags {
WorldImmutable = 1,
NoPvP = 2,
NoPvM = 4,
NoMvP = 8,
StaticTime = 16,
ShowNameTags = 32,
};
AdventureSettingsPacket() {}
AdventureSettingsPacket(const AdventureSettings& settings)
: flags(0)
{
set(WorldImmutable, settings.immutableWorld);
set(NoPvP, settings.noPvP);
set(NoPvM, settings.noPvM);
set(NoMvP, settings.noMvP);
set(StaticTime, !settings.doTickTime);
set(ShowNameTags, settings.showNameTags);
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ADVENTURESETTINGS));
bitStream->Write(flags);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(flags);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AdventureSettingsPacket*)this);
}
void fillIn( AdventureSettings& adventureSettings ) const
{
adventureSettings.immutableWorld= isSet(WorldImmutable);
adventureSettings.noPvP = isSet(NoPvP);
adventureSettings.noPvM = isSet(NoPvM);
adventureSettings.noMvP = isSet(NoMvP);
adventureSettings.doTickTime = !isSet(StaticTime);
adventureSettings.showNameTags = isSet(ShowNameTags);
}
unsigned int flags;
void set(Flags flag, bool status) { status? set(flag) : clear(flag); }
void set(Flags flag) { flags |= flag; }
void toggle(Flags flag){ flags ^= flag; }
void clear(Flags flag) { flags &= ~flag; }
bool isSet(Flags flag) const { return (flags & flag) != 0; }
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AdventureSettingsPacket_H__*/

View File

@@ -0,0 +1,46 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__AnimatePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__AnimatePacket_H__
#include "../Packet.h"
class AnimatePacket: public Packet
{
public:
static const int Swing = 1;
static const int WAKE_UP = 3;
int entityId;
char action;
AnimatePacket() {}
AnimatePacket(int action, int entityId)
: action(action),
entityId(entityId)
{}
AnimatePacket(int action, Entity* e)
: action(action),
entityId(e->entityId)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ANIMATE));
bitStream->Write(action);
bitStream->Write(entityId);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(action);
bitStream->Read(entityId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (AnimatePacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__AnimatePacket_H__*/

41
src/network/packet/ChatPacket.h Executable file
View File

@@ -0,0 +1,41 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ChatPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ChatPacket_H__
#include "../Packet.h"
#include "../..//world/entity/player/Player.h"
class ChatPacket: public Packet
{
public:
static const int MAX_CHAT_LENGTH = 100;
static const int MAX_LENGTH = MAX_CHAT_LENGTH + Player::MAX_NAME_LENGTH;
ChatPacket() {
}
ChatPacket(std::string message, bool isSystem = true) {
if(message.length() > MAX_LENGTH) {
message = message.substr(0, MAX_LENGTH);
}
this->message = message;
this->isSystem = isSystem;
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CHAT));
bitStream->Write(message.c_str());
}
void read(RakNet::BitStream* bitStream) {
char buff[MAX_LENGTH + 30];
bitStream->Read(buff);
message = buff;
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ChatPacket*)this);
}
std::string message;
bool isSystem;
};
#endif /* NET_MINECRAFT_NETWORK_PACKET__ChatPacket_H__ */

View File

@@ -0,0 +1,77 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ChunkDataPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ChunkDataPacket_H__
#include "../Packet.h"
#include "../../world/level/chunk/LevelChunk.h"
class ChunkDataPacket : public Packet
{
public:
int x, z;
RakNet::BitStream chunkData;
LevelChunk* chunk;
ChunkDataPacket()
{
}
ChunkDataPacket(int x, int z, LevelChunk* chunk)
: x(x),
z(z),
chunk(chunk)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CHUNKDATA));
bitStream->Write(x);
bitStream->Write(z);
unsigned char* blockIds = chunk->getBlockData();
DataLayer& blockData = chunk->data;
const int setSize = LEVEL_HEIGHT / 8;
const int setShift = 4; // power of LEVEL_HEIGHT / 8
chunkData.Reset();
for (int i = 0; i < CHUNK_COLUMNS; i++)
{
unsigned char updateBits = chunk->updateMap[i];
chunkData.Write(updateBits);
if (updateBits > 0)
{
int colDataPosition = (i % CHUNK_WIDTH) << 11 | (i / CHUNK_WIDTH) << 7;
for (int set = 0; set < 8; set++)
{
if ((updateBits & (1 << set)) != 0)
{
chunkData.Write((const char*)(&blockIds[colDataPosition + (set << setShift)]), setSize);
// block data is only 4 bits per block
chunkData.Write((const char*)(&blockData.data[(colDataPosition + (set << setShift)) >> 1]), setSize >> 1);
}
}
}
}
bitStream->Write(chunkData);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(z);
bitStream->Read(chunkData);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (ChunkDataPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ChunkDataPacket_H__*/

View File

@@ -0,0 +1,43 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerAckPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerAckPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class ContainerAckPacket: public Packet
{
public:
ContainerAckPacket() {
}
ContainerAckPacket(int containerId, short uid, bool accepted)
: containerId(containerId),
uid(uid),
accepted(accepted)
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINERACK));
bitStream->Write(containerId);
bitStream->Write(uid);
bitStream->Write(accepted);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
bitStream->Read(uid);
bitStream->Read(accepted);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerAckPacket*)this);
}
short uid;
unsigned char containerId;
bool accepted;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerAckPacket_H__*/

View File

@@ -0,0 +1,35 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerClosePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerClosePacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class ContainerClosePacket: public Packet
{
public:
ContainerClosePacket() {
}
ContainerClosePacket(int containerId)
: containerId(containerId)
{
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINERCLOSE));
bitStream->Write(containerId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerClosePacket*)this);
}
unsigned char containerId;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerClosePacket_H__*/

View File

@@ -0,0 +1,47 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerOpenPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerOpenPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class ContainerOpenPacket: public Packet
{
public:
ContainerOpenPacket() {
}
ContainerOpenPacket(int containerId, int type, const std::string& title, int size)
: containerId(containerId),
type(type),
title(title.c_str()),
size(size)
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINEROPEN));
bitStream->Write(containerId);
bitStream->Write(type);
bitStream->Write(size);
bitStream->Write(title);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
bitStream->Read(type);
bitStream->Read(size);
bitStream->Read(title);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerOpenPacket*)this);
}
RakNet::RakString title;
unsigned char containerId;
unsigned char type;
unsigned char size;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerOpenPacket_H__*/

View File

@@ -0,0 +1,44 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerSetContentPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerSetContentPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class ContainerSetContentPacket: public Packet
{
public:
ContainerSetContentPacket() {
}
ContainerSetContentPacket(int containerId, const std::vector<ItemInstance>& newItems)
: containerId(containerId),
items(newItems.begin(), newItems.end())
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINERSETCONTENT));
bitStream->Write(containerId);
bitStream->Write((short)items.size());
for (unsigned int i = 0; i < items.size(); ++i)
PacketUtil::writeItemInstance(items[i], bitStream);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
short numItems;
bitStream->Read(numItems);
for (int i = 0; i < numItems; ++i)
items.push_back( PacketUtil::readItemInstance(bitStream) );
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerSetContentPacket*)this);
}
unsigned char containerId;
std::vector<ItemInstance> items;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerSetContentPacket_H__*/

View File

@@ -0,0 +1,43 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerSetDataPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerSetDataPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class ContainerSetDataPacket: public Packet
{
public:
ContainerSetDataPacket() {
}
ContainerSetDataPacket(int containerId, int id, int value)
: containerId(containerId),
id(id),
value(value)
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINERSETDATA));
bitStream->Write(containerId);
bitStream->Write(id);
bitStream->Write(value);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
bitStream->Read(id);
bitStream->Read(value);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerSetDataPacket*)this);
}
short id;
short value;
unsigned char containerId;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerSetDataPacket_H__*/

View File

@@ -0,0 +1,64 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ContainerSetSlotPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ContainerSetSlotPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/item/ItemInstance.h"
// Note: This can be seen as "ContainerWantSetSlotPacket" when sent from
// client to server. Currently, the client handles side-effects relating
// to it's own inventory, regardless of the success of the operation.
class ContainerSetSlotPacket: public Packet
{
public:
static const char SETTYPE_SET = 0;
static const char SETTYPE_ADD = 1;
//static const int SETTYPE_SUB = 2;
static const char SETTYPE_TAKE = 5;
ContainerSetSlotPacket() {
}
//@todo: pointer parameter?
ContainerSetSlotPacket(int containerId, int slot, const ItemInstance& item)
: containerId(containerId),
slot(slot),
item(item),
setType(SETTYPE_SET)
//item(item? *item : ItemInstance())
{
}
ContainerSetSlotPacket(char setType, int containerId, int slot, const ItemInstance& item)
: setType(setType),
containerId(containerId),
slot(slot),
item(item)
//item(item? *item : ItemInstance())
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_CONTAINERSETSLOT));
bitStream->Write(containerId);
bitStream->Write(slot);
PacketUtil::writeItemInstance(item, bitStream);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(containerId);
bitStream->Read(slot);
item = PacketUtil::readItemInstance(bitStream);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (ContainerSetSlotPacket*)this);
}
unsigned char setType;
unsigned char containerId;
short slot;
ItemInstance item;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ContainerSetSlotPacket_H__*/

View File

@@ -0,0 +1,45 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__DropItemPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__DropItemPacket_H__
#include "../Packet.h"
class DropItemPacket: public Packet
{
public:
DropItemPacket()
{
}
DropItemPacket(int entityId, const ItemInstance& item)
: entityId(entityId),
item(item),
dropType(0)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_DROPITEM));
bitStream->Write(entityId);
bitStream->Write(dropType);
PacketUtil::writeItemInstance(item, bitStream);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(dropType);
item = PacketUtil::readItemInstance(bitStream);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (DropItemPacket*)this);
}
int entityId;
unsigned char dropType;
ItemInstance item;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__DropItemPacket_H__*/

View File

@@ -0,0 +1,40 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__EntityEventPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__EntityEventPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class EntityEventPacket: public Packet {
public:
EntityEventPacket() {}
EntityEventPacket(int entityId, char eventId)
: entityId(entityId),
eventId(eventId)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_ENTITYEVENT));
bitStream->Write(entityId);
bitStream->Write(eventId);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(eventId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (EntityEventPacket*)this);
}
int entityId;
unsigned char eventId;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__EntityEventPacket_H__*/

View File

@@ -0,0 +1,76 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ExplodePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ExplodePacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/level/Explosion.h"
class ExplodePacket: public Packet
{
public:
float x, y, z;
float r;
std::vector<TilePos> toBlow;
ExplodePacket() {}
ExplodePacket(float x, float y, float z, float r, const TilePosSet& tiles)
: x(x),
y(y),
z(z),
r(r),
toBlow(tiles.begin(), tiles.end())
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_EXPLODE));
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(r);
int xp = (int)x;
int yp = (int)y;
int zp = (int)z;
int count = (int)toBlow.size();
bitStream->Write(count);
for (int i = 0; i < count; ++i) {
const TilePos& tp = toBlow[i];
bitStream->Write((signed char)(tp.x - xp));
bitStream->Write((signed char)(tp.y - yp));
bitStream->Write((signed char)(tp.z - zp));
}
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(r);
int xp = (int)x;
int yp = (int)y;
int zp = (int)z;
// Write the tileset for the exploded tiles
int count;
bitStream->Read(count);
toBlow.reserve(count);
for (int i = 0; i < count; ++i) {
signed char xx,yy,zz;
bitStream->Read(xx);
bitStream->Read(yy);
bitStream->Read(zz);
toBlow.push_back( TilePos(xp + xx, yp + yy, zp + zz) );
}
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (ExplodePacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__ExplodePacket_H__*/

View File

@@ -0,0 +1,32 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__HurtArmorPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__HurtArmorPacket_H__
#include "../Packet.h"
class HurtArmorPacket: public Packet
{
public:
HurtArmorPacket() {}
HurtArmorPacket(int dmg)
: dmg(dmg)
{}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_HURTARMOR));
bitStream->Write(dmg);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(dmg);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (HurtArmorPacket*)this);
}
signed char dmg;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__HurtArmorPacket_H__*/

View File

@@ -0,0 +1,47 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__InteractPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__InteractPacket_H__
#include "../Packet.h"
class InteractPacket : public Packet
{
public:
static const int Interact = 1;
static const int Attack = 2;
char action;
int sourceId;
int targetId;
InteractPacket() {
}
InteractPacket(char action, int sourceId, int targetId)
: action(action),
sourceId(sourceId),
targetId(targetId)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_INTERACT));
bitStream->Write(action);
bitStream->Write(sourceId);
bitStream->Write(targetId);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(action);
bitStream->Read(sourceId);
bitStream->Read(targetId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (InteractPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__InteractPacket_H__*/

View File

@@ -0,0 +1,49 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__LevelEventPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__LevelEventPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class LevelEventPacket: public Packet {
public:
LevelEventPacket() {}
LevelEventPacket(int eventId, int x, int y, int z, int data)
: eventId(eventId),
x(x),
y(y),
z(z),
data(data)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_LEVELEVENT));
bitStream->Write(eventId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(data);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(eventId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(data);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (LevelEventPacket*)this);
}
short eventId;
short x, y, z;
int data;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__LevelEventPacket_H__*/

View File

@@ -0,0 +1,51 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__LoginPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__LoginPacket_H__
#include "../Packet.h"
class LoginPacket : public Packet
{
public:
RakNet::RakString clientName;
int clientNetworkVersion;
int clientNetworkLowestSupportedVersion;
LoginPacket()
: clientNetworkVersion(-1),
clientNetworkLowestSupportedVersion(-1)
{
}
LoginPacket(const RakNet::RakString& clientName, int clientVersion)
: clientName(clientName),
clientNetworkVersion(clientVersion),
clientNetworkLowestSupportedVersion(clientVersion)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_LOGIN));
bitStream->Write(clientName);
bitStream->Write(clientNetworkVersion);
bitStream->Write(clientNetworkLowestSupportedVersion);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(clientName);
// First versions didn't send the client version
//LOGI("unread: %d\n", bitStream->GetNumberOfUnreadBits());
if (bitStream->GetNumberOfUnreadBits() > 0) {
bitStream->Read(clientNetworkVersion);
bitStream->Read(clientNetworkLowestSupportedVersion);
}
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (LoginPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__LoginPacket_H__*/

View File

@@ -0,0 +1,40 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__LoginStatusPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__LoginStatusPacket_H__
#include "../Packet.h"
namespace LoginStatus {
const int Success = 0;
const int Failed_ClientOld = 1;
const int Failed_ServerOld = 2;
}
class LoginStatusPacket : public Packet {
public:
LoginStatusPacket()
{
}
LoginStatusPacket(int status)
: status(status)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_LOGINSTATUS));
bitStream->Write(status);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(status);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (LoginStatusPacket*)this);
}
int status;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__LoginStatusPacket_H__*/

View File

@@ -0,0 +1,39 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__MessagePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__MessagePacket_H__
#include "../Packet.h"
class MessagePacket : public Packet
{
public:
RakNet::RakString message;
MessagePacket()
{
}
MessagePacket(const RakNet::RakString& message)
: message(message)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_MESSAGE));
bitStream->Write(message);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(message);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (MessagePacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__MessagePacket_H__*/

View File

@@ -0,0 +1,78 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__MoveEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__MoveEntityPacket_H__
#include "../Packet.h"
class MoveEntityPacket: public Packet
{
public:
MoveEntityPacket()
: hasRot(false)
{}
// PACKET_MOVEENTITY is unknown and undefined (and not used)
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_MOVEENTITY));
}
void read(RakNet::BitStream* bitStream) {};
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (MoveEntityPacket*)this);
}
int entityId;
float x, y, z;
float xRot;
float yRot;
bool hasRot;
};
class MoveEntityPacket_PosRot: public MoveEntityPacket
{
typedef MoveEntityPacket super;
public:
MoveEntityPacket_PosRot() {
hasRot = true;
}
//MoveEntityPacket_PosRot(int entityId, float x, float y, float z, float yRot, float xRot) {
// set(entityId, x, y, z, yRot, xRot);
//}
MoveEntityPacket_PosRot(const Entity* e) {
set(e->entityId, e->x, e->y - e->heightOffset, e->z, e->yRot, e->xRot);
}
void set(int entityId, float x, float y, float z, float yRot, float xRot) {
this->entityId = entityId;
this->x = x;
this->y = y;
this->z = z;
this->xRot = xRot;
this->yRot = yRot;
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_MOVEENTITY_POSROT));
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(yRot);
bitStream->Write(xRot);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(yRot);
bitStream->Read(xRot);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__MoveEntityPacket_H__*/

View File

@@ -0,0 +1,54 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__MovePlayerPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__MovePlayerPacket_H__
#include "../Packet.h"
class MovePlayerPacket : public Packet
{
public:
int entityId;
float x, y, z, xRot, yRot;
MovePlayerPacket()
{
}
MovePlayerPacket(int entityId, float x, float y, float z, float xRot, float yRot)
: entityId(entityId),
x(x),
y(y),
z(z),
xRot(xRot),
yRot(yRot)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_MOVEPLAYER));
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(yRot);
bitStream->Write(xRot);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(yRot);
bitStream->Read(xRot);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (MovePlayerPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__MovePlayerPacket_H__*/

View File

@@ -0,0 +1,54 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__PacketInclude_H__
#define NET_MINECRAFT_NETWORK_PACKET__PacketInclude_H__
#include "AddEntityPacket.h"
#include "AddItemEntityPacket.h"
#include "AddMobPacket.h"
#include "AddPaintingPacket.h"
#include "AddPlayerPacket.h"
#include "AnimatePacket.h"
#include "AdventureSettingsPacket.h"
#include "ChatPacket.h"
#include "ContainerAckPacket.h"
#include "ContainerOpenPacket.h"
#include "ContainerClosePacket.h"
#include "ContainerSetDataPacket.h"
#include "ContainerSetSlotPacket.h"
#include "ContainerSetContentPacket.h"
#include "ChunkDataPacket.h"
#include "DropItemPacket.h"
#include "EntityEventPacket.h"
#include "ExplodePacket.h"
#include "HurtArmorPacket.h"
#include "InteractPacket.h"
#include "LevelEventPacket.h"
#include "LoginPacket.h"
#include "LoginStatusPacket.h"
#include "MessagePacket.h"
#include "MoveEntityPacket.h"
#include "MovePlayerPacket.h"
#include "PlaceBlockPacket.h"
#include "PlayerActionPacket.h"
#include "PlayerEquipmentPacket.h"
#include "PlayerArmorEquipmentPacket.h"
#include "ReadyPacket.h"
#include "RemoveBlockPacket.h"
#include "RemoveEntityPacket.h"
#include "RemovePlayerPacket.h"
#include "RespawnPacket.h"
#include "RequestChunkPacket.h"
#include "SendInventoryPacket.h"
#include "SetEntityDataPacket.h"
#include "SetEntityMotionPacket.h"
#include "SetHealthPacket.h"
#include "SetSpawnPositionPacket.h"
#include "SetTimePacket.h"
#include "SignUpdatePacket.h"
#include "StartGamePacket.h"
#include "TakeItemEntityPacket.h"
//#include "TeleportEntityPacket.h"
#include "TileEventPacket.h"
#include "UpdateBlockPacket.h"
#include "UseItemPacket.h"
#endif /*NET_MINECRAFT_NETWORK_PACKET__PacketInclude_H__*/

View File

@@ -0,0 +1,60 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__PlaceBlockPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__PlaceBlockPacket_H__
#include "../Packet.h"
class PlaceBlockPacket : public Packet
{
public:
// the id of the player who is placing the block, used to animate the player
int entityId;
int x, z;
unsigned char y, facing, blockId, blockData;
PlaceBlockPacket()
{
}
PlaceBlockPacket(int entityId, int x, int y, int z, int facing, int blockId, int blockData)
: entityId(entityId),
x(x),
y((unsigned char)(y & 0xff)),
z(z),
facing ((unsigned char)(facing & 0xff)),
blockId((unsigned char)(blockId & 0xff)),
blockData((unsigned char)(blockData & 0xff))
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_PLACEBLOCK));
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(z);
bitStream->Write(y);
bitStream->Write(facing);
bitStream->Write(blockId);
bitStream->Write(blockData);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(z);
bitStream->Read(y);
bitStream->Read(facing);
bitStream->Read(blockId);
bitStream->Read(blockData);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (PlaceBlockPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__PlaceBlockPacket_H__*/

View File

@@ -0,0 +1,62 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__PlayerActionPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__PlayerActionPacket_H__
#include "../Packet.h"
class PlayerActionPacket : public Packet
{
public:
static const int START_DESTROY_BLOCK = 0;
static const int ABORT_DESTROY_BLOCK = 1;
static const int STOP_DESTROY_BLOCK = 2;
static const int GET_UPDATED_BLOCK = 3;
static const int DROP_ITEM = 4;
static const int RELEASE_USE_ITEM = 5;
static const int STOP_SLEEPING = 6;
PlayerActionPacket()
: x(0),
y(0),
z(0),
action(0),
face(0),
entityId(0)
{}
PlayerActionPacket(int action, int x, int y, int z, int face, int entityId)
: x(x),
y(y),
z(z),
face(face),
action(action),
entityId(entityId)
{}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(action);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(face);
bitStream->Read(entityId);
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_PLAYERACTION));
bitStream->Write(action);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(face);
bitStream->Write(entityId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (PlayerActionPacket*)this);
}
int x, y, z, face, action, entityId;
};
#endif /* NET_MINECRAFT_NETWORK_PACKET__PlayerActionPacket_H__ */

View File

@@ -0,0 +1,78 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__PlayerArmorEquipmentPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__PlayerArmorEquipmentPacket_H__
#include "../Packet.h"
#include "../../world/entity/player/Player.h"
#include "../../world/item/ArmorItem.h"
#include "../../world/item/ItemInstance.h"
// @note: A visual update only
class PlayerArmorEquipmentPacket : public Packet
{
public:
int entityId;
signed char head;
signed char torso;
signed char legs;
signed char feet;
PlayerArmorEquipmentPacket() {
}
PlayerArmorEquipmentPacket(Player* player)
: entityId(player->entityId)
{
get(head, player->getArmor(ArmorItem::SLOT_HEAD));
get(torso, player->getArmor(ArmorItem::SLOT_TORSO));
get(legs, player->getArmor(ArmorItem::SLOT_LEGS));
get(feet, player->getArmor(ArmorItem::SLOT_FEET));
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_PLAYERARMOREQUIPMENT));
bitStream->Write(entityId);
bitStream->Write(head);
bitStream->Write(torso);
bitStream->Write(legs);
bitStream->Write(feet);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(entityId);
bitStream->Read(head);
bitStream->Read(torso);
bitStream->Read(legs);
bitStream->Read(feet);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (PlayerArmorEquipmentPacket*)this);
}
void fillIn(Player* player) {
set(player, head, ArmorItem::SLOT_HEAD);
set(player, torso, ArmorItem::SLOT_TORSO);
set(player, legs, ArmorItem::SLOT_LEGS);
set(player, feet, ArmorItem::SLOT_FEET);
}
private:
void get(signed char& s, const ItemInstance* item) {
if (item) {
s = item->id - 256;
} else {
s = -1;
}
}
void set(Player* p, signed char s, int slot) {
if (s < 0) p->setArmor(slot, NULL);
else {
ItemInstance item((int)s + 256, 1, 0);
p->setArmor(slot, &item);
}
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__PlayerArmorEquipmentPacket_H__*/

View File

@@ -0,0 +1,46 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__PlayerEquipmentPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__PlayerEquipmentPacket_H__
#include "../Packet.h"
class PlayerEquipmentPacket : public Packet
{
public:
int entityId;
unsigned short itemId;
unsigned short itemAuxValue;
PlayerEquipmentPacket()
{
}
PlayerEquipmentPacket(int entityId, int itemId, int data)
: entityId(entityId),
itemId(itemId),
itemAuxValue(data)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_PLAYEREQUIPMENT));
bitStream->Write(entityId);
bitStream->Write(itemId);
bitStream->Write(itemAuxValue);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(itemId);
bitStream->Read(itemAuxValue);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (PlayerEquipmentPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__PlayerEquipmentPacket_H__*/

View File

@@ -0,0 +1,42 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__ReadyPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__ReadyPacket_H__
#include "../Packet.h"
class ReadyPacket: public Packet
{
public:
static const char READY_UNDEFINED = 0;
static const char READY_CLIENTGENERATION = 1;
static const char READY_REQUESTEDCHUNKS = 2;
ReadyPacket()
: type(READY_UNDEFINED)
{
}
ReadyPacket(char type)
: type(type)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_READY));
bitStream->Write(type);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(type);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (ReadyPacket*)this);
}
char type;
};
#endif /*#NET_MINECRAFT_NETWORK_PACKET__ReadyPacket_H__*/

View File

@@ -0,0 +1,52 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__RemoveBlockPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__RemoveBlockPacket_H__
#include "../Packet.h"
#include "../../world/entity/player/Player.h"
class RemoveBlockPacket : public Packet
{
public:
// the id of the player who is placing the block, used to animate the player
int entityId;
int x, z;
unsigned char y;
RemoveBlockPacket()
{
}
RemoveBlockPacket(Player* p, int x, int y, int z)
: entityId(p->entityId),
x(x),
y((unsigned char)(y & 0xff)),
z(z)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_REMOVEBLOCK));
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(z);
bitStream->Write(y);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(z);
bitStream->Read(y);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (RemoveBlockPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__RemoveBlockPacket_H__*/

View File

@@ -0,0 +1,39 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__RemoveEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__RemoveEntityPacket_H__
#include "../Packet.h"
class RemoveEntityPacket : public Packet
{
public:
int entityId;
RemoveEntityPacket()
{
}
RemoveEntityPacket(int entityId)
: entityId(entityId)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_REMOVEENTITY));
bitStream->Write(entityId);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (RemoveEntityPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__RemoveEntityPacket_H__*/

View File

@@ -0,0 +1,41 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__RemovePlayerPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__RemovePlayerPacket_H__
#include "../Packet.h"
#include "../../world/entity/player/Player.h"
class RemovePlayerPacket : public Packet
{
public:
RemovePlayerPacket() {}
RemovePlayerPacket(const Player* p)
: entityId(p->entityId),
owner(p->owner)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_REMOVEPLAYER));
bitStream->Write(entityId);
bitStream->Write(owner);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(owner);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (RemovePlayerPacket*)this);
}
int entityId;
RakNet::RakNetGUID owner;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__RemovePlayerPacket_H__*/

View File

@@ -0,0 +1,42 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__RequestChunkPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__RequestChunkPacket_H__
#include "../Packet.h"
class RequestChunkPacket : public Packet
{
public:
int x, z;
RequestChunkPacket()
{
}
RequestChunkPacket(int _x, int _z)
{
x = _x;
z = _z;
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_REQUESTCHUNK));
bitStream->Write(x);
bitStream->Write(z);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(z);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (RequestChunkPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__RequestChunkPacket_H__*/

View File

@@ -0,0 +1,47 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__RespawnPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__RespawnPacket_H__
#include "../Packet.h"
class RespawnPacket: public Packet
{
public:
RespawnPacket()
{
}
RespawnPacket(const Player* p)
: x(p->x),y(p->y),z(p->z),
entityId(p->entityId)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_RESPAWN));
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (RespawnPacket*)this);
}
float x;
float y;
float z;
int entityId;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__RespawnPacket_H__*/

View File

@@ -0,0 +1,69 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SendInventoryPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SendInventoryPacket_H__
#include "../Packet.h"
class SendInventoryPacket: public Packet
{
public:
SendInventoryPacket()
{
}
SendInventoryPacket(Player* player, bool dropItems)
: entityId(player->entityId),
extra(dropItems? ExtraDrop : 0)
{
Inventory* inv = player->inventory;
numItems = 0;
for (int i = Inventory::MAX_SELECTION_SIZE; i < inv->getContainerSize(); ++i) {
++numItems;
ItemInstance* item = inv->getItem(i);
items.push_back(item? *item : ItemInstance());
}
for (int i = 0; i < NumArmorItems; ++i) {
ItemInstance* item = player->getArmor(i);
items.push_back(item? *item : ItemInstance());
}
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SENDINVENTORY));
bitStream->Write(entityId);
bitStream->Write(extra);
bitStream->Write(numItems);
// Inventory
for (int i = 0; i < numItems; ++i)
PacketUtil::writeItemInstance(items[i], bitStream);
// Armor
for (int i = 0; i < NumArmorItems; ++i)
PacketUtil::writeItemInstance(items[i + numItems], bitStream);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(entityId);
bitStream->Read(extra);
bitStream->Read(numItems);
items.clear();
// Inventory, Armor
for (int i = 0; i < numItems + NumArmorItems; ++i)
items.push_back(PacketUtil::readItemInstance(bitStream));
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SendInventoryPacket*)this);
}
int entityId;
std::vector<ItemInstance> items;
short numItems;
unsigned char extra;
static const int ExtraDrop = 1;
static const int NumArmorItems = 4;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SendInventoryPacket_H__*/

View File

@@ -0,0 +1,64 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SetEntityDataPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SetEntityDataPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/entity/SynchedEntityData.h"
#include "../../util/RakDataIO.h"
class SetEntityDataPacket: public Packet
{
public:
SetEntityDataPacket()
: deletePackedItems(false)
{}
SetEntityDataPacket(int id, SynchedEntityData& entityData)
: id(id),
deletePackedItems(false),
packedItems(entityData.packDirty())
{
}
~SetEntityDataPacket() {
if (deletePackedItems)
for (unsigned int i = 0; i < packedItems.size(); ++i)
delete packedItems[i];
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SETENTITYDATA));
bitStream->Write(id);
RakDataOutput dos(*bitStream);
SynchedEntityData::pack(&packedItems, &dos);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(id);
RakDataInput dis(*bitStream);
packedItems = SynchedEntityData::unpack(&dis);
deletePackedItems = true;
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SetEntityDataPacket*)this);
}
SynchedEntityData::DataList& getUnpackedData() {
return packedItems;
}
public:
int id;
private:
bool deletePackedItems;
SynchedEntityData::DataList packedItems;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SetEntityDataPacket_H__*/

View File

@@ -0,0 +1,68 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SetEntityMotionPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SetEntityMotionPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/entity/Entity.h"
class SetEntityMotionPacket: public Packet
{
public:
SetEntityMotionPacket() {}
SetEntityMotionPacket(Entity* e) {
init(e->entityId, e->xd, e->yd, e->zd);
}
SetEntityMotionPacket(int id, float xd, float yd, float zd) {
init(id, xd, yd, zd);
}
void write(RakNet::BitStream* bitStream)
{
const float M = 3.9f;
short xa = (short)(8000.0f * Mth::clamp(xd, -M, M));
short ya = (short)(8000.0f * Mth::clamp(yd, -M, M));
short za = (short)(8000.0f * Mth::clamp(zd, -M, M));
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SETENTITYMOTION));
bitStream->Write(id);
bitStream->Write(xa);
bitStream->Write(ya);
bitStream->Write(za);
}
void read(RakNet::BitStream* bitStream)
{
short xa, ya, za;
bitStream->Read(id);
bitStream->Read(xa);
bitStream->Read(ya);
bitStream->Read(za);
xd = xa / 8000.0f;
yd = ya / 8000.0f;
zd = za / 8000.0f;
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SetEntityMotionPacket*)this);
}
private:
void init(int entityId, float xd, float yd, float zd) {
this->id = entityId;
this->xd = xd;
this->yd = yd;
this->zd = zd;
}
public:
int id;
float xd, yd, zd;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SetEntityMotionPacket_H__*/

View File

@@ -0,0 +1,41 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SetHealthPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SetHealthPacket_H__
#include "../Packet.h"
//package net.minecraft.network.packet;
class SetHealthPacket: public Packet {
public:
static const int HEALTH_MODIFY_OFFSET = -64;
SetHealthPacket() {
}
SetHealthPacket(int health)
: health(health)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SETHEALTH));
bitStream->Write((signed char)health);
}
void read(RakNet::BitStream* bitStream)
{
signed char tmpHealth;
bitStream->Read(tmpHealth);
health = tmpHealth;
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SetHealthPacket*)this);
}
int health;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SetHealthPacket_H__*/

View File

@@ -0,0 +1,52 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SetSpawnPositionPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SetSpawnPositionPacket_H__
#include "../Packet.h"
class SetSpawnPositionPacket : public Packet
{
public:
int entityId;
int x, z;
unsigned char y;
SetSpawnPositionPacket()
{
}
SetSpawnPositionPacket(int x, int y, int z)
: x(x),
y((unsigned char)(y & 0xff)),
z(z)
{
}
SetSpawnPositionPacket(const Pos& pos)
: x(pos.x),
y((unsigned char)(pos.y & 0xff)),
z(pos.z)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SETSPAWNPOSITION));
bitStream->Write(x);
bitStream->Write(z);
bitStream->Write(y);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(z);
bitStream->Read(y);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SetSpawnPositionPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SetSpawnPositionPacket_H__*/

View File

@@ -0,0 +1,36 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SetTimePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SetTimePacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class SetTimePacket: public Packet {
public:
SetTimePacket() {
}
SetTimePacket(long time)
: time(time)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SETTIME));
bitStream->Write(time);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(time);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (SetTimePacket*)this);
}
long time;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SetTimePacket_H__*/

View File

@@ -0,0 +1,68 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__SignUpdatePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__SignUpdatePacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../util/RakDataIO.h"
#include "../../world/level/tile/entity/SignTileEntity.h"
class SignUpdatePacket: public Packet
{
public:
SignUpdatePacket() {}
SignUpdatePacket(int x, int y, int z, const std::string lines[])
: x(x),
y(y),
z(z)
{
for (int i = 0; i < 4; ++i)
this->lines[i] = lines[i];
}
/*@Override*/
void read(RakNet::BitStream* bitStream) {
short xx, zz;
unsigned char yy;
bitStream->Read(xx);
bitStream->Read(yy);
bitStream->Read(zz);
x = xx;
z = zz;
y = yy;
RakDataInput dis(*bitStream);
for (int i = 0; i < 4; ++i) {
lines[i] = dis.readString();
if (lines[i].length() > SignTileEntity::MAX_LINE_LENGTH)
lines[i].resize(SignTileEntity::MAX_LINE_LENGTH);
}
}
/*@Override*/
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_SIGNUPDATE));
short xx = x;
short zz = z;
unsigned char yy = y;
bitStream->Write(xx);
bitStream->Write(yy);
bitStream->Write(zz);
RakDataOutput dos(*bitStream);
for (int i = 0; i < 4; ++i)
dos.writeString(lines[i]);
}
/*@Override*/
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (SignUpdatePacket*)this);
}
public:
int x, y, z;
std::string lines[4];
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__SignUpdatePacket_H__*/

View File

@@ -0,0 +1,61 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__
#include "../Packet.h"
class StartGamePacket : public Packet
{
public:
long levelSeed;
int levelGeneratorVersion;
int gameType;
int entityId;
float x, y, z;
StartGamePacket()
{
}
StartGamePacket(long seed, int levelGeneratorVersion, int gameType, int entityId, float x, float y, float z)
: levelSeed(seed),
levelGeneratorVersion(levelGeneratorVersion),
gameType(gameType),
entityId(entityId),
x(x),
y(y),
z(z)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_STARTGAME));
bitStream->Write(levelSeed);
bitStream->Write(levelGeneratorVersion);
bitStream->Write(gameType);
bitStream->Write(entityId);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(levelSeed);
bitStream->Read(levelGeneratorVersion);
bitStream->Read(gameType);
bitStream->Read(entityId);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (StartGamePacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__*/

View File

@@ -0,0 +1,42 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__TakeItemEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__TakeItemEntityPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class TakeItemEntityPacket: public Packet
{
public:
TakeItemEntityPacket() {
}
TakeItemEntityPacket(int itemId, int playerId)
: itemId(itemId),
playerId(playerId)
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_TAKEITEMENTITY));
bitStream->Write(itemId);
bitStream->Write(playerId);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(itemId);
bitStream->Read(playerId);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (TakeItemEntityPacket*)this);
}
int itemId;
int playerId;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__TakeItemEntityPacket_H__*/

View File

@@ -0,0 +1,77 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__TeleportEntityPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__TeleportEntityPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/entity/Entity.h"
#include "../../util/Mth.h"
class TeleportEntityPacket: public Packet
{
public:
TeleportEntityPacket() {
}
TeleportEntityPacket(Entity* e, char cause)
: id(e->entityId),
x(e->x),
y(e->y),
z(e->z),
yRot(e->yRot),
xRot(e->xRot),
cause(cause)
{
}
TeleportEntityPacket(int id, float x, float y, float z, float yRot, float xRot, char cause)
: id(id),
x(x),
y(y),
z(z),
yRot(yRot),
xRot(xRot),
cause(cause)
{
}
void write(RakNet::BitStream* bitStream) {
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_TELEPORTENTITY));
bitStream->Write(id);
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(PacketUtil::Rot_degreesToChar(yRot));
bitStream->Write(PacketUtil::Rot_degreesToChar(xRot));
bitStream->Write(cause);
}
void read(RakNet::BitStream* bitStream) {
bitStream->Read(id);
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
char rx, ry;
bitStream->Read(ry);
bitStream->Read(rx);
bitStream->Read(cause);
yRot = PacketUtil::Rot_degreesToChar(ry);
xRot = PacketUtil::Rot_charToDegrees(rx);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (TeleportEntityPacket*)this);
}
int id;
float x, y, z;
float xRot, yRot; // sent as byte
char cause;
static const int WANT_RESPAWN = 1;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__TeleportEntityPacket_H__*/

View File

@@ -0,0 +1,48 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__TileEventPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__TileEventPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
class TileEventPacket: public Packet {
public:
TileEventPacket() {}
TileEventPacket(int x, int y, int z, int b0, int b1)
: x(x),
y(y),
z(z),
b0(b0),
b1(b1)
{}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_TILEEVENT));
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(b0);
bitStream->Write(b1);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(b0);
bitStream->Read(b1);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (TileEventPacket*)this);
}
int x, y, z;
int b0, b1;
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__TileEventPacket_H__*/

View File

@@ -0,0 +1,28 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__UpdateArmorPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__UpdateArmorPacket_H__
#include "../Packet.h"
class UpdateArmorPacket: public Packet
{
public:
UpdateArmorPacket(Player* player)
{
}
void write(RakNet::BitStream* bitStream){
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_UPDATEARMOR));
//bitStream->Write();
}
void read(RakNet::BitStream* bitStream) {
//bitStream->Read();
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) {
callback->handle(source, (UpdateArmorPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__UpdateArmorPacket_H__*/

View File

@@ -0,0 +1,55 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__UpdateBlockPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__UpdateBlockPacket_H__
#include "../Packet.h"
class UpdateBlockPacket : public Packet
{
public:
int x, z;
unsigned char y;
unsigned char blockId;
unsigned char blockData;
UpdateBlockPacket()
{
}
UpdateBlockPacket(int _x, int _y, int _z, int _blockId, int _blockData)
{
x = _x;
y = (unsigned char)(_y & 0xff);
z = _z;
blockId = (unsigned char)(_blockId & 0xff);
blockData = (unsigned char)(_blockData & 0xff);
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_UPDATEBLOCK));
bitStream->Write(x);
bitStream->Write(z);
bitStream->Write(y);
bitStream->Write(blockId);
bitStream->Write(blockData);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(z);
bitStream->Read(y);
bitStream->Read(blockId);
bitStream->Read(blockData);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (UpdateBlockPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__UpdateBlockPacket_H__*/

View File

@@ -0,0 +1,86 @@
#ifndef NET_MINECRAFT_NETWORK_PACKET__UseItemPacket_H__
#define NET_MINECRAFT_NETWORK_PACKET__UseItemPacket_H__
//package net.minecraft.network.packet;
#include "../Packet.h"
#include "../../world/item/ItemInstance.h"
class UseItemPacket: public Packet
{
public:
int x, y, z, face;
float clickX, clickY, clickZ;
int entityId;
short itemId;
unsigned char itemData;
ItemInstance item;
UseItemPacket() {}
UseItemPacket(int x, int y, int z, int face, const ItemInstance* item, int entityId, float clickX, float clickY, float clickZ)
: x(x),
y(y),
z(z),
face(face),
itemId(item? item->id : 0),
itemData(item? item->getAuxValue() : 0),
entityId(entityId),
clickX(clickX),
clickY(clickY),
clickZ(clickZ)
{}
UseItemPacket(const ItemInstance* item, int entityId, const Vec3& aim)
: face(255),
itemId(item? item->id : 0),
itemData(item? item->getAuxValue() : 0),
entityId(entityId),
x((int)(aim.x * 32768.0f)),
y((int)(aim.y * 32768.0f)),
z((int)(aim.z * 32768.0f))
{
}
void write(RakNet::BitStream* bitStream)
{
bitStream->Write((RakNet::MessageID)(ID_USER_PACKET_ENUM + PACKET_USEITEM));
bitStream->Write(x);
bitStream->Write(y);
bitStream->Write(z);
bitStream->Write(face);
bitStream->Write(itemId);
bitStream->Write(itemData);
bitStream->Write(entityId);
bitStream->Write(clickX);
bitStream->Write(clickY);
bitStream->Write(clickZ);
}
void read(RakNet::BitStream* bitStream)
{
bitStream->Read(x);
bitStream->Read(y);
bitStream->Read(z);
bitStream->Read(face);
bitStream->Read(itemId);
bitStream->Read(itemData);
bitStream->Read(entityId);
bitStream->Read(clickX);
bitStream->Read(clickY);
bitStream->Read(clickZ);
item.id = itemId;
item.setAuxValue(itemData);
item.count = (itemId == 0 && itemData == 0)? 0 : 1;
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
{
callback->handle(source, (UseItemPacket*)this);
}
};
#endif /*NET_MINECRAFT_NETWORK_PACKET__UseItemPacket_H__*/