diff --git a/Minecraft.World/Recipes.cpp b/Minecraft.World/Recipes.cpp index ca34b379b..848f4b73d 100644 --- a/Minecraft.World/Recipes.cpp +++ b/Minecraft.World/Recipes.cpp @@ -1440,10 +1440,10 @@ inline ItemInstance* parseItemInstance(DataInputStream* dis) { if (!displayTag->contains(L"Lore")) displayTag->put(L"Lore", new ListTag(L"Lore")); - ListTag* list = static_cast *>(item->tag->get(L"Lore")); + ListTag* list = static_cast *>(displayTag->get(L"Lore")); for (int i = 0; i < loreCount; i++) { wstring loreLine = dis->readUTF(); - list->add(new StringTag(loreLine)); + list->add(new StringTag(L"", loreLine)); } } } @@ -1478,6 +1478,26 @@ void Recipes::rebuildRecipeArray(std::shared_ptr packet) { ItemInstance* result = parseItemInstance(&input); ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast((recipeHeader >> 4) & 0x0F)); recipies->push_back(recipe); + } else if (recipeType == 1) { // Shaped recipe + unsigned char shapedRecipeHeader = input.readByte(); + + int width = (shapedRecipeHeader >> 4) & 0x0F; + int height = shapedRecipeHeader & 0x0F; + + ItemInstance** ids = new ItemInstance * [width * height]; + for (int j = 0; j < width * height; j++) { + byte isIngredientValid = input.readByte(); + + if (isIngredientValid) { + ids[j] = parseItemInstance(&input); + } else { + ids[j] = nullptr; + } + } + + ItemInstance* result = parseItemInstance(&input); + ShapedRecipy* recipe = new ShapedRecipy(width, height, ids, result, static_cast((recipeHeader >> 4) & 0x0F)); + recipies->push_back(recipe); } } @@ -1508,17 +1528,18 @@ byteArray Recipes::buildSyncedRecipeArray() { } else { ShapedRecipy* shapedRecipe = static_cast(recipe); - /*int width = shapedRecipe->getWidth(); + 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++) { - - } + ItemInstance** ingredients = shapedRecipe->getRecipeItems(); + for (int j = 0; j < width * height; j++) { + ItemInstance* ingredient = ingredients[j]; + dos.writeByte((ingredient == nullptr ? 0 : 1)); + if (ingredient == nullptr) continue; + + serializeItemInstance(&dos, ingredient); } - */ - continue; } serializeItemInstance(&dos, const_cast(recipe->getResultItem())); diff --git a/Minecraft.World/ShapedRecipy.h b/Minecraft.World/ShapedRecipy.h index c111b7c77..33087ab69 100644 --- a/Minecraft.World/ShapedRecipy.h +++ b/Minecraft.World/ShapedRecipy.h @@ -17,6 +17,10 @@ public: virtual const int getGroup(); virtual bool matches(shared_ptr craftSlots, Level *level); + int getWidth() { return width; } + int getHeight() { return height; } + ItemInstance** getRecipeItems() { return recipeItems; } + private: bool matches(shared_ptr craftSlots, int xOffs, int yOffs, bool xFlip);