From 66e39a0e29095216b8e6ae5f679ac8be2381eec1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= <tseeker@nocternity.net>
Date: Fri, 24 Jun 2016 09:15:36 +0200
Subject: [PATCH] Alloy furnace - Shift-clicking

---
 TODO.txt                                      |  2 +-
 src/java/mmm/materials/MAlloyRecipe.java      | 11 ++++
 .../tech/base/TBAlloyFurnaceContainer.java    | 52 +++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/TODO.txt b/TODO.txt
index e4011f5..2daa507 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -41,11 +41,11 @@ materials.ores	No		Tin
 materials.ores	No		Zinc
 -------------------------------------------------------------------------------------------------------
 tech.base		No		Alloy furnace
-							-> fix shift+click crash
 							-> support hoppers
 							-> comparator output
 							-> search recipe
 							-> I18n
+							-> XP
 							-> code clean-up
 tech.base		No		Coke oven
 -------------------------------------------------------------------------------------------------------
diff --git a/src/java/mmm/materials/MAlloyRecipe.java b/src/java/mmm/materials/MAlloyRecipe.java
index 328de06..9af085f 100644
--- a/src/java/mmm/materials/MAlloyRecipe.java
+++ b/src/java/mmm/materials/MAlloyRecipe.java
@@ -293,4 +293,15 @@ public class MAlloyRecipe
 		return sum;
 	}
 
+
+	public boolean hasInput( ItemStack stack )
+	{
+		for ( int i = 0 ; i < this.inputs.length ; i++ ) {
+			if ( this.inputs[ i ].isItemEqual( stack ) ) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 }
diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java b/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java
index afb7df7..9952b41 100644
--- a/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java
+++ b/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java
@@ -13,6 +13,8 @@ import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.InventoryPlayer;
 import net.minecraft.inventory.Container;
 import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntityFurnace;
 import net.minecraft.util.ResourceLocation;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.World;
@@ -81,6 +83,56 @@ public class TBAlloyFurnaceContainer
 	}
 
 
+	@Override
+	public ItemStack transferStackInSlot( final EntityPlayer playerIn , final int index )
+	{
+		final Slot slot = this.inventorySlots.get( index );
+		if ( slot == null || !slot.getHasStack( ) ) {
+			return null;
+		}
+
+		final ItemStack slotStack = slot.getStack( );
+		final ItemStack slotStackCopy = slotStack.copy( );
+		if ( slot.inventory == playerIn.inventory ) {
+			boolean checkInput;
+			if ( TileEntityFurnace.isItemFuel( slotStack ) ) {
+				checkInput = !this.mergeItemStack( slotStackCopy , 51 , 55 , false );
+			} else {
+				checkInput = true;
+			}
+			if ( checkInput ) {
+				if ( this.tileEntity.recipe.hasInput( slotStack ) ) {
+					if ( !this.mergeItemStack( slotStackCopy , 36 , 51 , false ) ) {
+						return null;
+					}
+				} else {
+					return null;
+				}
+			}
+		} else {
+			if ( !this.mergeItemStack( slotStackCopy , 0 , 36 , false ) ) {
+				return null;
+			}
+			if ( slot.inventory == this.output ) {
+				slot.onSlotChange( slotStackCopy , slotStack );
+			}
+		}
+
+		if ( slotStackCopy.stackSize == 0 ) {
+			slot.putStack( null );
+		} else {
+			slot.onSlotChanged( );
+		}
+
+		if ( slotStackCopy.stackSize == slotStack.stackSize ) {
+			return null;
+		}
+		slot.onPickupFromSlot( playerIn , slotStackCopy );
+
+		return slotStack;
+	}
+
+
 	public void setCurrentRecipe( final ResourceLocation name , final boolean confirm )
 	{
 		final MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name );