aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/SynchedEntityData.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-07 21:56:03 -0500
committerGitHub <noreply@github.com>2026-03-08 09:56:03 +0700
commita9be52c41a02d207233199e98898fe7483d7e817 (patch)
tree71dfaec3a86b05e9ca409b97d8eb9d7f993bfdd0 /Minecraft.World/SynchedEntityData.cpp
parent1be5faaea781402e7de06b263eeca4c688b7712c (diff)
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
Diffstat (limited to 'Minecraft.World/SynchedEntityData.cpp')
-rw-r--r--Minecraft.World/SynchedEntityData.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/Minecraft.World/SynchedEntityData.cpp b/Minecraft.World/SynchedEntityData.cpp
index 655fa0c3..69d419b0 100644
--- a/Minecraft.World/SynchedEntityData.cpp
+++ b/Minecraft.World/SynchedEntityData.cpp
@@ -19,7 +19,7 @@ void SynchedEntityData::define(int id, int value)
MemSect(17);
checkId(id);
int type = TYPE_INT;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, value);
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -30,7 +30,7 @@ void SynchedEntityData::define(int id, byte value)
MemSect(17);
checkId(id);
int type = TYPE_BYTE;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, value);
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -41,7 +41,7 @@ void SynchedEntityData::define(int id, short value)
MemSect(17);
checkId(id);
int type = TYPE_SHORT;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, value);
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -52,7 +52,7 @@ void SynchedEntityData::define(int id, float value)
MemSect(17);
checkId(id);
int type = TYPE_FLOAT;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, value);
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -63,7 +63,7 @@ void SynchedEntityData::define(int id, const wstring& value)
MemSect(17);
checkId(id);
int type = TYPE_STRING;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, value);
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -74,7 +74,7 @@ void SynchedEntityData::defineNULL(int id, void *pVal)
MemSect(17);
checkId(id);
int type = TYPE_ITEMINSTANCE;
- shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, shared_ptr<ItemInstance>()) );
+ shared_ptr<DataItem> dataItem = std::make_shared<DataItem>(type, id, shared_ptr<ItemInstance>());
itemsById[id] = dataItem;
MemSect(0);
m_isEmpty = false;
@@ -128,7 +128,7 @@ shared_ptr<ItemInstance> SynchedEntityData::getItemInstance(int id)
Pos *SynchedEntityData::getPos(int id)
{
assert(false); // 4J - not currently implemented
- return NULL;
+ return nullptr;
}
void SynchedEntityData::set(int id, int value)
@@ -238,18 +238,18 @@ void SynchedEntityData::pack(vector<shared_ptr<DataItem> > *items, DataOutputStr
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::packDirty()
{
- vector<shared_ptr<DataItem> > *result = NULL;
+ vector<shared_ptr<DataItem> > *result = nullptr;
if (m_isDirty)
{
for( int i = 0; i <= MAX_ID_VALUE; i++ )
{
shared_ptr<DataItem> dataItem = itemsById[i];
- if ((dataItem != NULL) && dataItem->isDirty())
+ if ((dataItem != nullptr) && dataItem->isDirty())
{
dataItem->setDirty(false);
- if (result == NULL)
+ if (result == nullptr)
{
result = new vector<shared_ptr<DataItem> >();
}
@@ -267,7 +267,7 @@ void SynchedEntityData::packAll(DataOutputStream *output) // throws IOException
for( int i = 0; i <= MAX_ID_VALUE; i++ )
{
shared_ptr<DataItem> dataItem = itemsById[i];
- if(dataItem != NULL)
+ if(dataItem != nullptr)
{
writeDataItem(output, dataItem);
}
@@ -279,14 +279,14 @@ void SynchedEntityData::packAll(DataOutputStream *output) // throws IOException
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::getAll()
{
- vector<shared_ptr<DataItem> > *result = NULL;
+ vector<shared_ptr<DataItem> > *result = nullptr;
for( int i = 0; i <= MAX_ID_VALUE; i++ )
{
shared_ptr<DataItem> dataItem = itemsById[i];
- if(dataItem != NULL)
+ if(dataItem != nullptr)
{
- if (result == NULL)
+ if (result == nullptr)
{
result = new vector<shared_ptr<DataItem> >();
}
@@ -338,14 +338,14 @@ void SynchedEntityData::writeDataItem(DataOutputStream *output, shared_ptr<DataI
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(DataInputStream *input) //throws IOException
{
- vector<shared_ptr<DataItem> > *result = NULL;
+ vector<shared_ptr<DataItem> > *result = nullptr;
int currentHeader = input->readByte();
while (currentHeader != EOF_MARKER)
{
- if (result == NULL)
+ if (result == nullptr)
{
result = new vector<shared_ptr<DataItem> >();
}
@@ -360,40 +360,40 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(Data
case TYPE_BYTE:
{
byte dataRead = input->readByte();
- item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
+ item = std::make_shared<DataItem>(itemType, itemId, dataRead);
}
break;
case TYPE_SHORT:
{
short dataRead = input->readShort();
- item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
+ item = std::make_shared<DataItem>(itemType, itemId, dataRead);
}
break;
case TYPE_INT:
{
int dataRead = input->readInt();
- item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
+ item = std::make_shared<DataItem>(itemType, itemId, dataRead);
}
break;
case TYPE_FLOAT:
{
float dataRead = input->readFloat();
- item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
+ item = std::make_shared<DataItem>(itemType, itemId, dataRead);
}
break;
case TYPE_STRING:
- item = shared_ptr<DataItem>( new DataItem(itemType, itemId, Packet::readUtf(input, MAX_STRING_DATA_LENGTH)) );
+ item = std::make_shared<DataItem>(itemType, itemId, Packet::readUtf(input, MAX_STRING_DATA_LENGTH));
break;
case TYPE_ITEMINSTANCE:
{
- item = shared_ptr<DataItem>(new DataItem(itemType, itemId, Packet::readItem(input)));
+ item = std::make_shared<DataItem>(itemType, itemId, Packet::readItem(input));
}
break;
default:
app.DebugPrintf(" ------ garbage data, or early end of stream due to an incomplete packet\n");
delete result;
- return NULL;
+ return nullptr;
break;
}
result->push_back(item);
@@ -415,7 +415,7 @@ void SynchedEntityData::assignValues(vector<shared_ptr<DataItem> > *items)
for (auto& item : *items)
{
shared_ptr<DataItem> itemFromId = itemsById[item->getId()];
- if( itemFromId != NULL )
+ if( itemFromId != nullptr )
{
switch(item->getType())
{
@@ -465,7 +465,7 @@ int SynchedEntityData::getSizeInBytes()
for( int i = 0; i <= MAX_ID_VALUE; i++ )
{
shared_ptr<DataItem> dataItem = itemsById[i];
- if(dataItem != NULL)
+ if(dataItem != nullptr)
{
size += 1;
@@ -485,7 +485,7 @@ int SynchedEntityData::getSizeInBytes()
size += 4;
break;
case TYPE_STRING:
- size += (int)dataItem->getValue_wstring().length() + 2; // Estimate, assuming all ascii chars
+ size += static_cast<int>(dataItem->getValue_wstring().length()) + 2; // Estimate, assuming all ascii chars
break;
case TYPE_ITEMINSTANCE:
// short + byte + short