From 8d92a30d0a633e4176c54a2ddbf5e1d4e7d9149b Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 29 Jan 2025 19:16:49 -0700 Subject: [PATCH] implement multi-crafting with shift --- .../widget/workbench/CraftingOutputSlot.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index a5aee5ad315..a7aaa0d9bd4 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -126,14 +126,20 @@ public void readOnServer(int id, PacketBuffer buf) { if (recipeLogic.isRecipeValid() && this.slot.canTakeStack(getSyncManager().getPlayer())) { if (recipeLogic.performRecipe()) { - ItemStack craftedStack = this.slot.getStack(); + ItemStack craftedStack = getOutputStack(); if (data.shift) { - quickTransfer(craftedStack); + ItemStack finalStack = craftedStack.copy(); + while (finalStack.getCount() < craftedStack.getMaxStackSize()) { + if (!recipeLogic.performRecipe()) break; + finalStack.setCount(finalStack.getCount() + craftedStack.getCount()); + handleItemCraft(craftedStack, getSyncManager().getPlayer()); + } + quickTransfer(finalStack); } else { syncToClient(SYNC_STACK, this::syncCraftedStack); + handleItemCraft(craftedStack, getSyncManager().getPlayer()); } - handleItemCraft(craftedStack, getSyncManager().getPlayer()); } } } @@ -215,13 +221,13 @@ public ItemStack getOutputStack() { return slot.getStack(); } - public void handleItemCraft(ItemStack itemStack, EntityPlayer player) { - itemStack.onCrafting(player.world, player, 1); + public void handleItemCraft(ItemStack craftedStack, EntityPlayer player) { + craftedStack.onCrafting(player.world, player, 1); var inventoryCrafting = recipeLogic.getCraftingMatrix(); // if we're not simulated, fire the event, unlock recipe and add crafted items, and play sounds - FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, inventoryCrafting); + FMLCommonHandler.instance().firePlayerCraftingEvent(player, craftedStack, inventoryCrafting); var cachedRecipe = recipeLogic.getCachedRecipe(); if (cachedRecipe != null && !cachedRecipe.isDynamic()) { @@ -229,7 +235,6 @@ public void handleItemCraft(ItemStack itemStack, EntityPlayer player) { } if (cachedRecipe != null) { ItemStack resultStack = cachedRecipe.getCraftingResult(inventoryCrafting); - // itemsCrafted += resultStack.getCount(); this.slot.notifyRecipePerformed(resultStack); } }