1
0
Fork 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);
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 Length = 0;
switch (Type)

View File

@ -124,9 +124,7 @@ public:
(z < Width) && (z > -1)
)
{
return MakeIndexNoCheck(static_cast<unsigned int>(x),
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
return MakeIndexNoCheck(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!");
@ -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
// 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
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
}
@ -168,9 +166,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X),
static_cast<unsigned int>(a_Y),
static_cast<unsigned int>(a_Z))] = a_Type;
a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type;
}
@ -186,9 +182,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
return a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X),
static_cast<unsigned int>(a_Y),
static_cast<unsigned int>(a_Z))];
return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)];
}
@ -246,9 +240,7 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x),
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
unsigned int Index = MakeIndexNoCheck(x, y, z);
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@ -282,9 +274,7 @@ public:
return;
}
unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x),
static_cast<unsigned int>(y),
static_cast<unsigned int>(z));
unsigned int Index = MakeIndexNoCheck(x, y, z);
a_Buffer[Index / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
((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
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)
{
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();
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);
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
int DataLength = a_NBT.GetDataLength(explosiontag);
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0)
{
continue;
@ -105,6 +107,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
else if (ExplosionName == "FadeColors")
{
int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0)
{
continue;