diff --git a/Minecraft.World/Recipes.cpp b/Minecraft.World/Recipes.cpp index 94e5faac5..ca34b379b 100644 --- a/Minecraft.World/Recipes.cpp +++ b/Minecraft.World/Recipes.cpp @@ -1345,8 +1345,8 @@ Recipy::INGREDIENTS_REQUIRED *Recipes::getRecipeIngredientsArray(void) inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) { dos->writeInt(result->id); - dos->writeInt(result->count); - dos->writeInt(result->getAuxValue()); + dos->writeByte(result->count); + dos->writeShort(result->getAuxValue()); unsigned char itemFlags = 0; { @@ -1370,14 +1370,12 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) { } } } - - dos->writeByte(itemFlags); if (itemFlags & 0x01) { ListTag* list = result->getEnchantmentTags(); if (list != nullptr) { - dos->writeInt(list->size()); + dos->writeByte(list->size()); 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_LEVEL)); @@ -1391,8 +1389,8 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) { if (itemFlags & 0x03) { ListTag* lore = (ListTag *) result->tag->getCompound(L"display")->getList(L"Lore"); - dos->writeInt(lore->size()); - for (int i = 0; i < lore->size(); i++) + dos->writeByte(lore->size()); + for (int i = 0; i < ((unsigned char)lore->size()); i++) { dos->writeUTF(lore->get(i)->data); } @@ -1401,15 +1399,15 @@ inline void serializeItemInstance(DataOutputStream* dos, ItemInstance* result) { inline ItemInstance* parseItemInstance(DataInputStream* dis) { int itemId = dis->readInt(); - int itemCount = dis->readInt(); - int itemAux = dis->readInt(); + int itemCount = dis->readByte(); + int itemAux = dis->readShort(); unsigned char itemFlags = dis->readByte(); ItemInstance* item = new ItemInstance(itemId, itemCount, itemAux); if (itemFlags & 0x01) { - int enchantmentCount = dis->readInt(); + int enchantmentCount = dis->readByte(); if (enchantmentCount > 0) { if (item->tag == nullptr) item->setTag(new CompoundTag()); if (!item->tag->contains(L"ench")) item->tag->put(L"ench", new ListTag(L"ench")); @@ -1433,7 +1431,7 @@ inline ItemInstance* parseItemInstance(DataInputStream* dis) { } if (itemFlags & 0x03) { - int loreCount = dis->readInt(); + int loreCount = dis->readByte(); if (loreCount > 0) { if (item->tag == nullptr) item->setTag(new CompoundTag()); @@ -1467,18 +1465,18 @@ void Recipes::rebuildRecipeArray(std::shared_ptr packet) { int recipeCount = input.readInt(); for (int i = 0; i < recipeCount; i++) { - unsigned char group = input.readByte(); - unsigned char recipeType = input.readByte(); + unsigned char recipeHeader = input.readByte(); + int recipeType = recipeHeader & 0x0F; if (recipeType == 0) { // Shapeless recipe - int ingredientCount = input.readInt(); + int ingredientCount = input.readByte(); vector* ingredients = new vector(); for (int j = 0; j < ingredientCount; j++) { ingredients->emplace_back(parseItemInstance(&input)); } ItemInstance* result = parseItemInstance(&input); - ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast(group)); + ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast((recipeHeader >> 4) & 0x0F)); recipies->push_back(recipe); } } @@ -1495,22 +1493,31 @@ byteArray Recipes::buildSyncedRecipeArray() { dos.writeInt(iRecipeC); for (int i = 0; i < iRecipeC; i++) { Recipy* recipe = (*recipies)[i]; - dos.writeByte(recipe->getGroup()); + bool isShapeless = dynamic_cast(recipe) != nullptr; + dos.writeByte((recipe->getGroup() << 4) | ((isShapeless ? 0 : 1) & 0x0F)); - if (dynamic_cast(recipe) != nullptr) { + if (isShapeless) { ShapelessRecipy* shapeless = static_cast(recipe); - dos.writeByte(0); //0 for shapeless recipe std::vector* ingredients = shapeless->getIngredients(); - dos.writeInt(static_cast(ingredients->size())); + dos.writeByte(static_cast(ingredients->size())); for (auto& ingredient : *ingredients) { serializeItemInstance(&dos, ingredient); } - } else if (dynamic_cast(recipe) != nullptr) { + } else { ShapedRecipy* shapedRecipe = static_cast(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; }