shaped recipes

This commit is contained in:
DrPerkyLegit 2026-04-24 03:25:05 -04:00
parent 12d11a8b1a
commit 4cacbee4aa
2 changed files with 34 additions and 9 deletions

View file

@ -1440,10 +1440,10 @@ inline ItemInstance* parseItemInstance(DataInputStream* dis) {
if (!displayTag->contains(L"Lore")) displayTag->put(L"Lore", new ListTag<StringTag>(L"Lore"));
ListTag<StringTag>* list = static_cast<ListTag<StringTag> *>(item->tag->get(L"Lore"));
ListTag<StringTag>* list = static_cast<ListTag<StringTag> *>(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<CustomPayloadPacket> packet) {
ItemInstance* result = parseItemInstance(&input);
ShapelessRecipy* recipe = new ShapelessRecipy(result, ingredients, static_cast<Recipy::_eGroupType>((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<Recipy::_eGroupType>((recipeHeader >> 4) & 0x0F));
recipies->push_back(recipe);
}
}
@ -1508,17 +1528,18 @@ byteArray Recipes::buildSyncedRecipeArray() {
} else {
ShapedRecipy* shapedRecipe = static_cast<ShapedRecipy*>(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<ItemInstance*>(recipe->getResultItem()));

View file

@ -17,6 +17,10 @@ public:
virtual const int getGroup();
virtual bool matches(shared_ptr<CraftingContainer> craftSlots, Level *level);
int getWidth() { return width; }
int getHeight() { return height; }
ItemInstance** getRecipeItems() { return recipeItems; }
private:
bool matches(shared_ptr<CraftingContainer> craftSlots, int xOffs, int yOffs, bool xFlip);