mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
lighten packet size
This commit is contained in:
parent
f2b304fad5
commit
12d11a8b1a
|
|
@ -1345,8 +1345,8 @@ Recipy::INGREDIENTS_REQUIRED *Recipes::getRecipeIngredientsArray(void)
|
||||||
|
|
||||||
inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) {
|
inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) {
|
||||||
dos->writeInt(result->id);
|
dos->writeInt(result->id);
|
||||||
dos->writeInt(result->count);
|
dos->writeByte(result->count);
|
||||||
dos->writeInt(result->getAuxValue());
|
dos->writeShort(result->getAuxValue());
|
||||||
|
|
||||||
unsigned char itemFlags = 0;
|
unsigned char itemFlags = 0;
|
||||||
{
|
{
|
||||||
|
|
@ -1370,14 +1370,12 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dos->writeByte(itemFlags);
|
dos->writeByte(itemFlags);
|
||||||
|
|
||||||
if (itemFlags & 0x01) {
|
if (itemFlags & 0x01) {
|
||||||
ListTag<CompoundTag>* list = result->getEnchantmentTags();
|
ListTag<CompoundTag>* list = result->getEnchantmentTags();
|
||||||
if (list != nullptr) {
|
if (list != nullptr) {
|
||||||
dos->writeInt(list->size());
|
dos->writeByte(list->size());
|
||||||
for (int i = 0; i < list->size(); i++) {
|
for (int i = 0; i < list->size(); i++) {
|
||||||
dos->writeShort(list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_ID));
|
dos->writeShort(list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_ID));
|
||||||
dos->writeShort(list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL));
|
dos->writeShort(list->get(i)->getShort((wchar_t*)ItemInstance::TAG_ENCH_LEVEL));
|
||||||
|
|
@ -1391,8 +1389,8 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) {
|
||||||
|
|
||||||
if (itemFlags & 0x03) {
|
if (itemFlags & 0x03) {
|
||||||
ListTag<StringTag>* lore = (ListTag<StringTag> *) result->tag->getCompound(L"display")->getList(L"Lore");
|
ListTag<StringTag>* lore = (ListTag<StringTag> *) result->tag->getCompound(L"display")->getList(L"Lore");
|
||||||
dos->writeInt(lore->size());
|
dos->writeByte(lore->size());
|
||||||
for (int i = 0; i < lore->size(); i++)
|
for (int i = 0; i < ((unsigned char)lore->size()); i++)
|
||||||
{
|
{
|
||||||
dos->writeUTF(lore->get(i)->data);
|
dos->writeUTF(lore->get(i)->data);
|
||||||
}
|
}
|
||||||
|
|
@ -1401,15 +1399,15 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) {
|
||||||
|
|
||||||
inline ItemInstance* parseItemInstance(DataInputStream* dis) {
|
inline ItemInstance* parseItemInstance(DataInputStream* dis) {
|
||||||
int itemId = dis->readInt();
|
int itemId = dis->readInt();
|
||||||
int itemCount = dis->readInt();
|
int itemCount = dis->readByte();
|
||||||
int itemAux = dis->readInt();
|
int itemAux = dis->readShort();
|
||||||
|
|
||||||
unsigned char itemFlags = dis->readByte();
|
unsigned char itemFlags = dis->readByte();
|
||||||
|
|
||||||
ItemInstance* item = new ItemInstance(itemId, itemCount, itemAux);
|
ItemInstance* item = new ItemInstance(itemId, itemCount, itemAux);
|
||||||
|
|
||||||
if (itemFlags & 0x01) {
|
if (itemFlags & 0x01) {
|
||||||
int enchantmentCount = dis->readInt();
|
int enchantmentCount = dis->readByte();
|
||||||
if (enchantmentCount > 0) {
|
if (enchantmentCount > 0) {
|
||||||
if (item->tag == nullptr) item->setTag(new CompoundTag());
|
if (item->tag == nullptr) item->setTag(new CompoundTag());
|
||||||
if (!item->tag->contains(L"ench")) item->tag->put(L"ench", new ListTag<CompoundTag>(L"ench"));
|
if (!item->tag->contains(L"ench")) item->tag->put(L"ench", new ListTag<CompoundTag>(L"ench"));
|
||||||
|
|
@ -1433,7 +1431,7 @@ inline ItemInstance* parseItemInstance(DataInputStream* dis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemFlags & 0x03) {
|
if (itemFlags & 0x03) {
|
||||||
int loreCount = dis->readInt();
|
int loreCount = dis->readByte();
|
||||||
|
|
||||||
if (loreCount > 0) {
|
if (loreCount > 0) {
|
||||||
if (item->tag == nullptr) item->setTag(new CompoundTag());
|
if (item->tag == nullptr) item->setTag(new CompoundTag());
|
||||||
|
|
@ -1467,18 +1465,18 @@ void Recipes::rebuildRecipeArray(std::shared_ptr<CustomPayloadPacket> packet) {
|
||||||
|
|
||||||
int recipeCount = input.readInt();
|
int recipeCount = input.readInt();
|
||||||
for (int i = 0; i < recipeCount; i++) {
|
for (int i = 0; i < recipeCount; i++) {
|
||||||
unsigned char group = input.readByte();
|
unsigned char recipeHeader = input.readByte();
|
||||||
unsigned char recipeType = input.readByte();
|
int recipeType = recipeHeader & 0x0F;
|
||||||
|
|
||||||
if (recipeType == 0) { // Shapeless recipe
|
if (recipeType == 0) { // Shapeless recipe
|
||||||
int ingredientCount = input.readInt();
|
int ingredientCount = input.readByte();
|
||||||
vector<ItemInstance*>* ingredients = new vector<ItemInstance*>();
|
vector<ItemInstance*>* ingredients = new vector<ItemInstance*>();
|
||||||
for (int j = 0; j < ingredientCount; j++) {
|
for (int j = 0; j < ingredientCount; j++) {
|
||||||
ingredients->emplace_back(parseItemInstance(&input));
|
ingredients->emplace_back(parseItemInstance(&input));
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemInstance* result = parseItemInstance(&input);
|
ItemInstance* result = parseItemInstance(&input);
|
||||||
ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast<Recipy::_eGroupType>(group));
|
ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast<Recipy::_eGroupType>((recipeHeader >> 4) & 0x0F));
|
||||||
recipies->push_back(recipe);
|
recipies->push_back(recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1495,22 +1493,31 @@ byteArray Recipes::buildSyncedRecipeArray() {
|
||||||
dos.writeInt(iRecipeC);
|
dos.writeInt(iRecipeC);
|
||||||
for (int i = 0; i < iRecipeC; i++) {
|
for (int i = 0; i < iRecipeC; i++) {
|
||||||
Recipy* recipe = (*recipies)[i];
|
Recipy* recipe = (*recipies)[i];
|
||||||
dos.writeByte(recipe->getGroup());
|
bool isShapeless = dynamic_cast<ShapelessRecipy*>(recipe) != nullptr;
|
||||||
|
dos.writeByte((recipe->getGroup() << 4) | ((isShapeless ? 0 : 1) & 0x0F));
|
||||||
|
|
||||||
if (dynamic_cast<ShapelessRecipy*>(recipe) != nullptr) {
|
if (isShapeless) {
|
||||||
ShapelessRecipy* shapeless = static_cast<ShapelessRecipy*>(recipe);
|
ShapelessRecipy* shapeless = static_cast<ShapelessRecipy*>(recipe);
|
||||||
dos.writeByte(0); //0 for shapeless recipe
|
|
||||||
|
|
||||||
std::vector<ItemInstance*>* ingredients = shapeless->getIngredients();
|
std::vector<ItemInstance*>* ingredients = shapeless->getIngredients();
|
||||||
dos.writeInt(static_cast<int>(ingredients->size()));
|
dos.writeByte(static_cast<int>(ingredients->size()));
|
||||||
|
|
||||||
for (auto& ingredient : *ingredients) {
|
for (auto& ingredient : *ingredients) {
|
||||||
serializeItemInstance(&dos, ingredient);
|
serializeItemInstance(&dos, ingredient);
|
||||||
}
|
}
|
||||||
} else if (dynamic_cast<ShapedRecipy*>(recipe) != nullptr) {
|
} else {
|
||||||
ShapedRecipy* shapedRecipe = static_cast<ShapedRecipy*>(recipe);
|
ShapedRecipy* shapedRecipe = static_cast<ShapedRecipy*>(recipe);
|
||||||
dos.writeByte(1); //1 for shaped recipe
|
|
||||||
|
|
||||||
|
/*int width = shapedRecipe->getWidth();
|
||||||
|
int height = shapedRecipe->getHeight();
|
||||||
|
dos.writeByte((width << 4) | (height & 0x0F));
|
||||||
|
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue