Skip to content

Commit

Permalink
implement multi-crafting with shift
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jan 30, 2025
1 parent 876b785 commit 8d92a30
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -215,21 +221,20 @@ 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()) {
player.unlockRecipes(Lists.newArrayList(cachedRecipe));
}
if (cachedRecipe != null) {
ItemStack resultStack = cachedRecipe.getCraftingResult(inventoryCrafting);
// itemsCrafted += resultStack.getCount();
this.slot.notifyRecipePerformed(resultStack);
}
}
Expand Down

0 comments on commit 8d92a30

Please sign in to comment.