1
0

Fixed xofts issues

This commit is contained in:
Tycho 2014-03-10 13:18:53 -07:00
parent e9e2852ce1
commit 98e15a34a4
5 changed files with 15 additions and 21 deletions

View File

@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
a_Metadata.push_back(x); a_Metadata.push_back(x);
while (x != 0x7f) while (x != 0x7f)
{ {
//int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index // int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type
int Length = 0; int Length = 0;
switch (Type) switch (Type)

View File

@ -124,9 +124,7 @@ public:
(z < Width) && (z > -1) (z < Width) && (z > -1)
) )
{ {
return MakeIndexNoCheck(static_cast<unsigned int>(x), return MakeIndexNoCheck(x, y, z);
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
} }
LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z);
ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
@ -134,13 +132,13 @@ public:
} }
inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) inline static unsigned int MakeIndexNoCheck(int x, int y, int z)
{ {
#if AXIS_ORDER == AXIS_ORDER_XZY #if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird. // For some reason, NOT using the Horner schema is faster. Weird.
return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 is XZY return static_cast<unsigned int>(x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width)); // 1.2 is XZY
#elif AXIS_ORDER == AXIS_ORDER_YZX #elif AXIS_ORDER == AXIS_ORDER_YZX
return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 is YZX return static_cast<unsigned int>(y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width)); // 1.1 is YZX
#endif #endif
} }
@ -168,9 +166,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width)); ASSERT((a_Z >= 0) && (a_Z < Width));
a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X), a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type;
static_cast<unsigned int>(a_Y),
static_cast<unsigned int>(a_Z))] = a_Type;
} }
@ -186,9 +182,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width)); ASSERT((a_Z >= 0) && (a_Z < Width));
return a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X), return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)];
static_cast<unsigned int>(a_Y),
static_cast<unsigned int>(a_Z))];
} }
@ -246,9 +240,7 @@ public:
{ {
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{ {
unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x), unsigned int Index = MakeIndexNoCheck(x, y, z);
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
} }
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@ -282,9 +274,7 @@ public:
return; return;
} }
unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x), unsigned int Index = MakeIndexNoCheck(x, y, z);
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
a_Buffer[Index / 2] = static_cast<NIBBLETYPE>( a_Buffer[Index / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set

View File

@ -294,7 +294,7 @@ AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8)
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
for (int i = 0; i < a_NumShorts; i++) for (int i = 0; i < a_NumShorts; i++)
{ {
int c = GetBEShort(a_RawData + i*2); int c = GetBEShort(&a_RawData[i * 2]);
if (c < 0x80) if (c < 0x80)
{ {
a_UTF8.push_back((char)c); a_UTF8.push_back((char)c);

View File

@ -510,7 +510,7 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si
size_t size = m_Result.length(); size_t size = m_Result.length();
if ((cap - size) < (4 + a_NumElements * 4)) if ((cap - size) < (4 + a_NumElements * 4))
{ {
m_Result.reserve(size +4 + a_NumElements * 4); m_Result.reserve(size + 4 + (a_NumElements * 4));
} }
m_Result.append((const char *)&len, 4); m_Result.append((const char *)&len, 4);
for (size_t i = 0; i < a_NumElements; i++) for (size_t i = 0; i < a_NumElements; i++)

View File

@ -91,6 +91,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
{ {
// Divide by four as data length returned in bytes // Divide by four as data length returned in bytes
int DataLength = a_NBT.GetDataLength(explosiontag); int DataLength = a_NBT.GetDataLength(explosiontag);
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0) if (DataLength == 0)
{ {
continue; continue;
@ -105,6 +107,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
else if (ExplosionName == "FadeColors") else if (ExplosionName == "FadeColors")
{ {
int DataLength = a_NBT.GetDataLength(explosiontag) / 4; int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0) if (DataLength == 0)
{ {
continue; continue;