Files
MinecraftConsoles/Minecraft.World/ContainerSetContentPacket.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

61 lines
1.4 KiB
C++

#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(static_cast<int>(newItems->size()));
for (unsigned int i = 0; i < items.length; i++)
{
shared_ptr<ItemInstance> item = newItems->at(i);
items[i] = item == nullptr ? 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;
}