giant batch BOOOOM

This commit is contained in:
Nikita Edel 2026-03-11 17:28:13 +01:00
parent ed13020cf3
commit 69a8ce84b9
8 changed files with 31 additions and 19 deletions

View file

@ -702,12 +702,12 @@ void MultiPlayerLevel::animateTickDoWork()
for( AUTO_VAR(it, chunksToAnimate.begin()); it != chunksToAnimate.end(); it++ )
{
int packed = *it;
int cx = ( packed << 8 ) >> 24;
int cy = ( packed << 16 ) >> 24;
int cz = ( packed << 24 ) >> 24;
cx <<= 3;
cy <<= 3;
cz <<= 3;
// 4jcraft changed the extraction logic to be safe
// constantly shifting a signed integer
int cx = (int8_t)(packed >> 16) * 8;
int cy = (int8_t)(packed >> 8) * 8;
int cz = (int8_t)packed * 8;
int x = cx + random->nextInt(8);
int y = cy + random->nextInt(8);
int z = cz + random->nextInt(8);

View file

@ -475,7 +475,8 @@ void ServerLevel::tickTiles()
// 4J - changes here brought forrward from 1.2.3
if (random->nextInt(16) == 0)
{
randValue = randValue * 3 + addend;
//4jcraft added cast to unsigned
randValue = (unsigned)randValue * 3 + (unsigned)addend;
int val = (randValue >> 2);
int x = (val & 15);
int z = ((val >> 8) & 15);
@ -1414,7 +1415,8 @@ int ServerLevel::runUpdate(void* lpParam)
for (int j = 0; j < 80; j++)
{
m_randValue[iLev] = m_randValue[iLev] * 3 + m_level[iLev]->addend;
// 4jcraft added cast to unsigned
m_randValue[iLev] = (unsigned) m_randValue[iLev] * 3 + (unsigned) m_level[iLev]->addend;
int val = (m_randValue[iLev] >> 2);
int x = (val & 15);
if( ( x < minx ) || ( x > maxx ) ) continue;

View file

@ -343,6 +343,9 @@ Tutorial::Tutorial(int iPad, bool isFullTutorial /*= false*/) : m_iPad( iPad )
m_bHasTickedOnce = false;
m_firstTickTime = 0;
// 4jcraft added, not initialized
m_bSceneIsSplitscreen = false;
m_lastMessage = NULL;
lastMessageTime = 0;
@ -1258,7 +1261,7 @@ void Tutorial::tick()
else
{
// if we've changed mode, we may need to change scene
if(m_bSceneIsSplitscreen!=(app.GetLocalPlayerCount()>1))
if(m_bSceneIsSplitscreen != (app.GetLocalPlayerCount() > 1))
{
#ifdef _XBOX
app.TutorialSceneNavigateBack(m_iPad);

View file

@ -45,6 +45,9 @@ ServerPlayer::ServerPlayer(MinecraftServer *server, Level *level, const std::wst
m_enteredEndExitPortal = false;
lastCarried = ItemInstanceArray(5);
viewDistance = 10;
// 4jcraft added (0 initialized)
m_lastDamageSource = eTelemetryChallenges_Unknown;
// gameMode->player = this; // 4J - removed to avoid use of shared_from_this in ctor, now set up externally
this->gameMode = gameMode;
@ -540,7 +543,7 @@ void ServerPlayer::doTickB(bool ignorePortal)
if (getHealth() != lastSentHealth || lastSentFood != foodData.getFoodLevel() || ((foodData.getSaturationLevel() == 0) != lastFoodSaturationZero))
{
// 4J Stu - Added m_lastDamageSource for telemetry
// 4J Stu - Added m_lastDamageSource for telemetry //4jcraft, nice but you never initialized it
connection->send( std::shared_ptr<SetHealthPacket>( new SetHealthPacket(getHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel(), m_lastDamageSource) ) );
lastSentHealth = getHealth();
lastSentFood = foodData.getFoodLevel();

View file

@ -30,7 +30,8 @@ hash(createHash(x, y, z))
int Node::createHash(const int x, const int y, const int z)
{
return (y & 0xff) | ((x & 0x7fff) << 8) | ((z & 0x7fff) << 24) | ((x < 0) ? 0x0080000000 : 0) | ((z < 0) ? 0x0000008000 : 0);
// 4jcraft added cast to higher value to be representable after shift
return (y & 0xff) | (((int64_t)x & 0x7fff) << 8) | (((int64_t)z & 0x7fff) << 24) | ((x < 0) ? 0x0080000000 : 0) | ((z < 0) ? 0x0000008000 : 0);
}
float Node::distanceTo(Node *to)
@ -72,4 +73,4 @@ bool Node::inOpenSet()
std::wstring Node::toString()
{
return _toString<int>(x) + L", " + _toString<int>(y) + L", " + _toString<int>(z);
}
}

View file

@ -54,8 +54,9 @@ void ChunkTilesUpdatePacket::read(DataInputStream *dis) //throws IOException
#ifdef _LARGE_WORLDS
xc = dis->readShort();
zc = dis->readShort();
xc = ( xc << 16 ) >> 16;
zc = ( zc << 16 ) >> 16;
// 4jcraft changed shift back and forth to a down cast
xc = (int16_t) xc;
zc = (int16_t) zc;
#else
xc = dis->read();
zc = dis->read();

View file

@ -9,11 +9,12 @@ struct IntKeyHash
{
int operator() (const int &k) const
{
int h = k;
// 4jcraft added h to be unsigned, to not cast it later
unsigned int h = k;
h += ~(h << 9);
h ^= (((unsigned int)h) >> 14);
h ^= (h >> 14);
h += (h << 4);
h ^= (((unsigned int)h) >> 10);
h ^= (h >> 10);
return h;
}
};

View file

@ -88,7 +88,7 @@ int Random::nextInt(int n)
if ((n & -n) == n) // i.e., n is a power of 2
// 4jcraft added casts to unsigned
// 4jcraft added casts to unsigned (and uint64)
return (unsigned int)(((__uint64)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long
int bits, val;
@ -96,7 +96,8 @@ int Random::nextInt(int n)
{
bits = next(31);
val = bits % n;
} while(bits - val + (n-1) < 0);
// 4jcraft added a cast to prevent overflow
} while((int64_t) bits - val + (n-1) < 0);
return val;
}