Files
MinecraftConsoles/Minecraft.World/IntArrayTag.h
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

72 lines
1.3 KiB
C++

#pragma once
#include "Tag.h"
#include "System.h"
class IntArrayTag : public Tag
{
public:
intArray data;
IntArrayTag(const wstring &name) : Tag(name)
{
data = intArray();
}
IntArrayTag(const wstring &name, intArray data) : Tag(name)
{
this->data = data;
}
~IntArrayTag()
{
delete [] data.data;
}
void write(DataOutput *dos)
{
dos->writeInt(data.length);
for (unsigned int i = 0; i < data.length; i++)
{
dos->writeInt(data[i]);
}
}
void load(DataInput *dis, int tagDepth)
{
int length = dis->readInt();
if ( data.data ) delete[] data.data;
data = intArray(length);
for (int i = 0; i < length; i++)
{
data[i] = dis->readInt();
}
}
byte getId() { return TAG_Int_Array; }
wstring toString()
{
static wchar_t buf[32];
swprintf(buf, 32, L"[%d bytes]",data.length);
return wstring( buf );
}
bool equals(Tag *obj)
{
if (Tag::equals(obj))
{
IntArrayTag *o = static_cast<IntArrayTag *>(obj);
return ((data.data == nullptr && o->data.data == nullptr) || (data.data != nullptr && data.length == o->data.length && memcmp(data.data, o->data.data, data.length * sizeof(int)) == 0) );
}
return false;
}
Tag *copy()
{
intArray cp = intArray(data.length);
System::arraycopy(data, 0, &cp, 0, data.length);
return new IntArrayTag(getName(), cp);
}
};