Merge pull request #2 from leahanderson1/dev

to whoever at 4j made this code not adhere to any C standard: why
This commit is contained in:
DecalOverdose 2026-03-02 21:45:09 +04:00 committed by GitHub
commit 143865600c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 59 additions and 59 deletions

View file

@ -21,7 +21,7 @@ ChunkTilesUpdatePacket::ChunkTilesUpdatePacket()
shouldDelay = true; shouldDelay = true;
xc = 0; xc = 0;
zc = 0; zc = 0;
count = 0; count = (std::byte)0;
} }
ChunkTilesUpdatePacket::ChunkTilesUpdatePacket(int xc, int zc, shortArray positions, byte count, Level *level) ChunkTilesUpdatePacket::ChunkTilesUpdatePacket(int xc, int zc, shortArray positions, byte count, Level *level)
@ -30,12 +30,12 @@ ChunkTilesUpdatePacket::ChunkTilesUpdatePacket(int xc, int zc, shortArray positi
this->xc = xc; this->xc = xc;
this->zc = zc; this->zc = zc;
this->count = count; this->count = count;
this->positions = shortArray(count); this->positions = shortArray((short int)count);
this->blocks = byteArray(count); this->blocks = byteArray((unsigned int)count);
this->data = byteArray(count); this->data = byteArray((unsigned int)count);
LevelChunk *levelChunk = level->getChunk(xc, zc); LevelChunk *levelChunk = level->getChunk(xc, zc);
for (int i = 0; i < count; i++) for (int i = 0; (std::byte)i < count; i++)
{ {
int x = (positions[i] >> 12) & 15; int x = (positions[i] >> 12) & 15;
int z = (positions[i] >> 8) & 15; int z = (positions[i] >> 8) & 15;
@ -63,33 +63,33 @@ void ChunkTilesUpdatePacket::read(DataInputStream *dis) //throws IOException
zc = ( zc << 24 ) >> 24; zc = ( zc << 24 ) >> 24;
#endif #endif
int countAndFlags = dis->readByte(); int countAndFlags = (int)dis->readByte();
bool dataAllZero = (( countAndFlags & 0x80 ) == 0x80 ); bool dataAllZero = (( countAndFlags & 0x80 ) == 0x80 );
levelIdx = ( countAndFlags >> 5 ) & 3; levelIdx = ( countAndFlags >> 5 ) & 3;
count = countAndFlags & 0x1f; count = (std::byte)countAndFlags & (std::byte)0x1f;
positions = shortArray(count); positions = shortArray((short int)count);
blocks = byteArray(count); blocks = byteArray((unsigned int)count);
data = byteArray(count); data = byteArray((unsigned int)count);
int currentBlockType = -1; int currentBlockType = -1;
for( int i = 0; i < count; i++ ) for( int i = 0; (std::byte)i < count; i++ )
{ {
int xzAndFlag = dis->readShort(); int xzAndFlag = dis->readShort();
int y = dis->readByte(); int y = (int)dis->readByte();
positions[i] = (xzAndFlag & 0xff00) | (y & 0xff); positions[i] = (xzAndFlag & 0xff00) | (y & 0xff);
if( ( xzAndFlag & 0x0080 ) == 0x0080 ) if( ( xzAndFlag & 0x0080 ) == 0x0080 )
{ {
currentBlockType = dis->read(); currentBlockType = dis->read();
} }
blocks[i] = currentBlockType; blocks[i] = (std::byte)currentBlockType;
if( !dataAllZero) if( !dataAllZero)
{ {
data[i] = dis->read(); data[i] = (std::byte)dis->read();
} }
else else
{ {
data[i] = 0; data[i] = (std::byte)0;
} }
} }
} }
@ -107,22 +107,22 @@ void ChunkTilesUpdatePacket::write(DataOutputStream *dos) //throws IOException
// Determine if we've got any data elements that are non-zero - a large % of these packets set all data to zero, so we don't // Determine if we've got any data elements that are non-zero - a large % of these packets set all data to zero, so we don't
// bother sending all those zeros in that case. // bother sending all those zeros in that case.
bool dataAllZero = true; bool dataAllZero = true;
for( int i = 0; i < count; i++ ) for( int i = 0; i < (int)count; i++ )
{ {
if( data[i] ) dataAllZero = false; if( (bool)data[i] ) dataAllZero = false;
} }
int countAndFlags = count; int countAndFlags = (int)count;
if( dataAllZero ) countAndFlags |= 0x80; if( (bool)dataAllZero ) countAndFlags |= 0x80;
countAndFlags |= ( levelIdx << 5 ); countAndFlags |= ( levelIdx << 5 );
dos->write(countAndFlags); dos->write(countAndFlags);
int lastBlockType = -1; int lastBlockType = -1;
// Each block is represented by 15 bits of position, a flag to say whether the current block type is to change, and a possible data value. // Each block is represented by 15 bits of position, a flag to say whether the current block type is to change, and a possible data value.
// A large % of these packets set the same block type to a several positions, so no point resending the block type when not necessary. // A large % of these packets set the same block type to a several positions, so no point resending the block type when not necessary.
for( int i = 0; i < count; i++ ) for( int i = 0; i < (int)count; i++ )
{ {
int xzAndFlag = positions[i] &0xff00; int xzAndFlag = positions[i] &0xff00;
int y = positions[i] & 0xff; int y = positions[i] & 0xff;
int thisBlockType = blocks[i]; int thisBlockType = (int)blocks[i];
if( thisBlockType != lastBlockType ) if( thisBlockType != lastBlockType )
{ {
xzAndFlag |= 0x0080; // Use top bit of y as a flag, we only need 7 bits for that xzAndFlag |= 0x0080; // Use top bit of y as a flag, we only need 7 bits for that
@ -138,7 +138,7 @@ void ChunkTilesUpdatePacket::write(DataOutputStream *dos) //throws IOException
} }
if( !dataAllZero ) if( !dataAllZero )
{ {
dos->write(data[i]); dos->write((unsigned int)data[i]);
} }
} }
} }
@ -153,20 +153,20 @@ int ChunkTilesUpdatePacket::getEstimatedSize()
bool dataAllZero = true; bool dataAllZero = true;
int lastBlockType = -1; int lastBlockType = -1;
int blockTypeChanges = 0; int blockTypeChanges = 0;
for( int i = 0; i < count; i++ ) for( int i = 0; i < (int)count; i++ )
{ {
if( data[i] ) dataAllZero = false; if( (bool)data[i] ) dataAllZero = false;
int thisBlockType = blocks[i]; int thisBlockType = (int)blocks[i];
if( thisBlockType != lastBlockType ) if( thisBlockType != lastBlockType )
{ {
blockTypeChanges++; blockTypeChanges++;
lastBlockType = thisBlockType; lastBlockType = thisBlockType;
} }
} }
int byteCount = 3 + 2 * count + blockTypeChanges; int byteCount = 3 + 2 * (int)count + blockTypeChanges;
if( !dataAllZero ) if( !dataAllZero )
{ {
byteCount += count; byteCount += (unsigned char) count;
} }
return byteCount; return byteCount;

View file

@ -14,12 +14,12 @@ ClientCommandPacket::ClientCommandPacket(int action)
void ClientCommandPacket::read(DataInputStream *dis) void ClientCommandPacket::read(DataInputStream *dis)
{ {
action = dis->readByte(); action = (int)dis->readByte();
} }
void ClientCommandPacket::write(DataOutputStream *dos) void ClientCommandPacket::write(DataOutputStream *dos)
{ {
dos->writeByte(action & 0xff); dos->writeByte((std::byte)action & (std::byte)0xff);
} }
void ClientCommandPacket::handle(PacketListener *listener) void ClientCommandPacket::handle(PacketListener *listener)
@ -30,4 +30,4 @@ void ClientCommandPacket::handle(PacketListener *listener)
int ClientCommandPacket::getEstimatedSize() int ClientCommandPacket::getEstimatedSize()
{ {
return 1; return 1;
} }

View file

@ -27,16 +27,16 @@ void ContainerAckPacket::handle(PacketListener *listener)
void ContainerAckPacket::read(DataInputStream *dis) //throws IOException void ContainerAckPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
uid = dis->readShort(); uid = dis->readShort();
accepted = dis->readByte() != 0; accepted = (int)dis->readByte() != 0;
} }
void ContainerAckPacket::write(DataOutputStream *dos) //throws IOException void ContainerAckPacket::write(DataOutputStream *dos) //throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeShort(uid); dos->writeShort(uid);
dos->writeByte(accepted ? 1 : 0); dos->writeByte((std::byte)(accepted ? 1 : 0));
} }
int ContainerAckPacket::getEstimatedSize() int ContainerAckPacket::getEstimatedSize()

View file

@ -24,17 +24,17 @@ void ContainerButtonClickPacket::handle(PacketListener *listener)
void ContainerButtonClickPacket::read(DataInputStream *dis) void ContainerButtonClickPacket::read(DataInputStream *dis)
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
buttonId = dis->readByte(); buttonId = (int)dis->readByte();
} }
void ContainerButtonClickPacket::write(DataOutputStream *dos) void ContainerButtonClickPacket::write(DataOutputStream *dos)
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeByte(buttonId); dos->writeByte((std::byte)buttonId);
} }
int ContainerButtonClickPacket::getEstimatedSize() int ContainerButtonClickPacket::getEstimatedSize()
{ {
return 2; return 2;
} }

View file

@ -39,9 +39,9 @@ void ContainerClickPacket::handle(PacketListener *listener)
void ContainerClickPacket::read(DataInputStream *dis) //throws IOException void ContainerClickPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
slotNum = dis->readShort(); slotNum = dis->readShort();
buttonNum = dis->readByte(); buttonNum = (int)dis->readByte();
uid = dis->readShort(); uid = dis->readShort();
quickKey = dis->readBoolean(); quickKey = dis->readBoolean();
@ -50,9 +50,9 @@ void ContainerClickPacket::read(DataInputStream *dis) //throws IOException
void ContainerClickPacket::write(DataOutputStream *dos) // throws IOException void ContainerClickPacket::write(DataOutputStream *dos) // throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeShort(slotNum); dos->writeShort(slotNum);
dos->writeByte(buttonNum); dos->writeByte((std::byte)buttonNum);
dos->writeShort(uid); dos->writeShort(uid);
dos->writeBoolean(quickKey); dos->writeBoolean(quickKey);

View file

@ -23,12 +23,12 @@ void ContainerClosePacket::handle(PacketListener *listener)
void ContainerClosePacket::read(DataInputStream *dis) //throws IOException void ContainerClosePacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
} }
void ContainerClosePacket::write(DataOutputStream *dos) //throws IOException void ContainerClosePacket::write(DataOutputStream *dos) //throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
} }
int ContainerClosePacket::getEstimatedSize() int ContainerClosePacket::getEstimatedSize()

View file

@ -28,18 +28,18 @@ void ContainerOpenPacket::handle(PacketListener *listener)
void ContainerOpenPacket::read(DataInputStream *dis) //throws IOException void ContainerOpenPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte() & 0xff; containerId = (int)(dis->readByte() & (std::byte)0xff);
type = dis->readByte() & 0xff; type = (int)(dis->readByte() & (std::byte)0xff);
title = dis->readShort(); title = dis->readShort();
size = dis->readByte() & 0xff; size = (int)(dis->readByte() & (std::byte)0xff);
} }
void ContainerOpenPacket::write(DataOutputStream *dos) //throws IOException void ContainerOpenPacket::write(DataOutputStream *dos) //throws IOException
{ {
dos->writeByte(containerId & 0xff); dos->writeByte((std::byte)containerId & (std::byte)0xff);
dos->writeByte(type & 0xff); dos->writeByte((std::byte)type & (std::byte)0xff);
dos->writeShort(title & 0xffff); dos->writeShort(title & 0xffff);
dos->writeByte(size & 0xff); dos->writeByte((std::byte)size & (std::byte)0xff);
} }
int ContainerOpenPacket::getEstimatedSize() int ContainerOpenPacket::getEstimatedSize()

View file

@ -30,7 +30,7 @@ ContainerSetContentPacket::ContainerSetContentPacket(int containerId, vector<sha
void ContainerSetContentPacket::read(DataInputStream *dis) //throws IOException void ContainerSetContentPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
int count = dis->readShort(); int count = dis->readShort();
items = ItemInstanceArray(count); items = ItemInstanceArray(count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -41,7 +41,7 @@ void ContainerSetContentPacket::read(DataInputStream *dis) //throws IOException
void ContainerSetContentPacket::write(DataOutputStream *dos) //throws IOException void ContainerSetContentPacket::write(DataOutputStream *dos) //throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeShort(items.length); dos->writeShort(items.length);
for (unsigned int i = 0; i < items.length; i++) for (unsigned int i = 0; i < items.length; i++)
{ {

View file

@ -27,14 +27,14 @@ void ContainerSetDataPacket::handle(PacketListener *listener)
void ContainerSetDataPacket::read(DataInputStream *dis) //throws IOException void ContainerSetDataPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = (int)dis->readByte();
id = dis->readShort(); id = dis->readShort();
value = dis->readShort(); value = dis->readShort();
} }
void ContainerSetDataPacket::write(DataOutputStream *dos) // throws IOException void ContainerSetDataPacket::write(DataOutputStream *dos) // throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeShort(id); dos->writeShort(id);
dos->writeShort(value); dos->writeShort(value);
} }

View file

@ -34,7 +34,7 @@ void ContainerSetSlotPacket::read(DataInputStream *dis) //throws IOException
{ {
// 4J Stu - TU-1 hotfix // 4J Stu - TU-1 hotfix
// Fix for #13142 - Holding down the A button on the furnace ingredient slot causes the UI to display incorrect item counts // Fix for #13142 - Holding down the A button on the furnace ingredient slot causes the UI to display incorrect item counts
BYTE byteId = dis->readByte(); std::byte byteId = dis->readByte();
containerId = *(char *)&byteId; containerId = *(char *)&byteId;
slot = dis->readShort(); slot = dis->readShort();
item = readItem(dis); item = readItem(dis);
@ -42,7 +42,7 @@ void ContainerSetSlotPacket::read(DataInputStream *dis) //throws IOException
void ContainerSetSlotPacket::write(DataOutputStream *dos) //throws IOException void ContainerSetSlotPacket::write(DataOutputStream *dos) //throws IOException
{ {
dos->writeByte(containerId); dos->writeByte((std::byte)containerId);
dos->writeShort(slot); dos->writeShort(slot);
writeItem(item, dos); writeItem(item, dos);
} }

View file

@ -3,7 +3,7 @@
#include "PacketListener.h" #include "PacketListener.h"
#include "BasicTypeContainers.h" #include "BasicTypeContainers.h"
#include "CustomPayloadPacket.h" #include "CustomPayloadPacket.h"
#include "../Minecraft.Client/Windows64/Windows64_App.h"
// Mojang-defined custom packets // Mojang-defined custom packets
const wstring CustomPayloadPacket::CUSTOM_BOOK_PACKET = L"MC|BEdit"; const wstring CustomPayloadPacket::CUSTOM_BOOK_PACKET = L"MC|BEdit";
const wstring CustomPayloadPacket::CUSTOM_BOOK_SIGN_PACKET = L"MC|BSign"; const wstring CustomPayloadPacket::CUSTOM_BOOK_SIGN_PACKET = L"MC|BSign";
@ -72,4 +72,4 @@ void CustomPayloadPacket::handle(PacketListener *listener)
int CustomPayloadPacket::getEstimatedSize() int CustomPayloadPacket::getEstimatedSize()
{ {
return 2 + identifier.length() * 2 + 2 + length; return 2 + identifier.length() * 2 + 2 + length;
} }