Skip to content

Commit

Permalink
Add better handling for recipe transfer into restricted slots
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 10, 2016
1 parent ce47226 commit b3a0559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Expand Up @@ -129,12 +129,6 @@ public IRecipeTransferError transferRecipe(C container, IRecipeLayout recipeLayo
Log.error("Recipes Transfer Helper {} references slot {} outside of the inventory's size {}", transferHelper.getClass(), slotNumber, container.inventorySlots.size());
return handlerHelper.createInternalError();
}
Slot slot = container.getSlot(slotNumber);
ItemStack stack = container.getSlot(entry.getValue()).getStack();
if (!slot.isItemValid(stack)) {
Log.error("The ItemStack {} is not valid for the slot number {}", stack, slotNumber);
return handlerHelper.createInternalError();
}
}

if (doTransfer) {
Expand Down
Expand Up @@ -4,7 +4,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -76,12 +75,21 @@ public static void setItems(EntityPlayer player, Map<Integer, Integer> slotIdMap

ItemStack stack = entry.getValue();
stack.stackSize *= removedSets;
slot.putStack(stack);
if (slot.isItemValid(stack)) {
slot.putStack(stack);
} else {
clearedCraftingItems.add(stack);
}
}

// put cleared items back into the player's inventory
// put cleared items back into the inventory
for (ItemStack oldCraftingItem : clearedCraftingItems) {
InventoryHelper.addStack(container, inventorySlots, oldCraftingItem, true);
int added = InventoryHelper.addStack(container, inventorySlots, oldCraftingItem, true);
if (added < oldCraftingItem.stackSize) {
if (!player.inventory.addItemStackToInventory(oldCraftingItem)) {
player.dropItem(oldCraftingItem, false);
}
}
}

container.detectAndSendChanges();
Expand Down

0 comments on commit b3a0559

Please sign in to comment.