When shift clicking a recipe in the Crafting Grid, the player's inventory is now leveraged as well, fixes #299

This commit is contained in:
Raoul Van den Berge
2016-09-01 22:21:20 +02:00
parent 29a309b202
commit 85856a4eeb
3 changed files with 28 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
- Reworked Crafting Monitor GUI (raoulvdberge) - Reworked Crafting Monitor GUI (raoulvdberge)
- Fixed problems relating to Crafting Upgrade (scheduling a task wrongly, blocking other tasks, etc) (raoulvdberge) - Fixed problems relating to Crafting Upgrade (scheduling a task wrongly, blocking other tasks, etc) (raoulvdberge)
- Interface now supports Crafting Upgrade (raoulvdberge) - Interface now supports Crafting Upgrade (raoulvdberge)
- When shift clicking a recipe in the Crafting Grid, the player's inventory is now leveraged as well (raoulvdberge)
### 0.9.4 ### 0.9.4
- Little fixes in German translation (ThexXTURBOXx) - Little fixes in German translation (ThexXTURBOXx)

View File

@@ -53,7 +53,7 @@ public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<Me
} }
} }
((TileGrid) grid).onRecipeTransfer(actualRecipe); ((TileGrid) grid).onRecipeTransfer(player, actualRecipe);
} }
} }
} }

View File

@@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.InvWrapper;
import refinedstorage.RefinedStorage; import refinedstorage.RefinedStorage;
@@ -333,7 +334,7 @@ public class TileGrid extends TileNode implements IGrid {
return result.getStackInSlot(0) != null && patterns.getStackInSlot(1) == null && patterns.getStackInSlot(0) != null; return result.getStackInSlot(0) != null && patterns.getStackInSlot(1) == null && patterns.getStackInSlot(0) != null;
} }
public void onRecipeTransfer(ItemStack[][] recipe) { public void onRecipeTransfer(EntityPlayer player, ItemStack[][] recipe) {
if (isConnected()) { if (isConnected()) {
for (int i = 0; i < matrix.getSizeInventory(); ++i) { for (int i = 0; i < matrix.getSizeInventory(); ++i) {
ItemStack slot = matrix.getStackInSlot(i); ItemStack slot = matrix.getStackInSlot(i);
@@ -356,15 +357,39 @@ public class TileGrid extends TileNode implements IGrid {
ItemStack[] possibilities = recipe[i]; ItemStack[] possibilities = recipe[i];
if (getType() == EnumGridType.CRAFTING) { if (getType() == EnumGridType.CRAFTING) {
boolean found = false;
for (ItemStack possibility : possibilities) { for (ItemStack possibility : possibilities) {
ItemStack took = NetworkUtils.extractItem(network, possibility, 1); ItemStack took = NetworkUtils.extractItem(network, possibility, 1);
if (took != null) { if (took != null) {
matrix.setInventorySlotContents(i, took); matrix.setInventorySlotContents(i, took);
found = true;
break; break;
} }
} }
if (!found) {
for (ItemStack possibility : possibilities) {
for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
if (CompareUtils.compareStackNoQuantity(possibility, player.inventory.getStackInSlot(j))) {
matrix.setInventorySlotContents(i, ItemHandlerHelper.copyStackWithSize(player.inventory.getStackInSlot(j), 1));
player.inventory.decrStackSize(j, 1);
found = true;
break;
}
}
if (found) {
break;
}
}
}
} else if (getType() == EnumGridType.PATTERN) { } else if (getType() == EnumGridType.PATTERN) {
matrix.setInventorySlotContents(i, possibilities[0]); matrix.setInventorySlotContents(i, possibilities[0]);
} }