2014-05-11 18:27:32 +02:00
|
|
|
package appeng.integration.modules.NEIHelpers;
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2014-09-17 06:23:19 +02:00
|
|
|
import java.util.LinkedList;
|
2014-05-01 06:01:22 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.inventory.Slot;
|
2014-09-17 06:23:19 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-05-01 06:01:22 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-08-20 04:02:37 +02:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.client.gui.implementations.GuiCraftingTerm;
|
2014-07-06 08:52:29 +02:00
|
|
|
import appeng.client.gui.implementations.GuiPatternTerm;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.container.slot.SlotCraftingMatrix;
|
2014-07-06 08:52:29 +02:00
|
|
|
import appeng.container.slot.SlotFakeCraftingMatrix;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.core.sync.packets.PacketNEIRecipe;
|
2014-09-17 06:23:19 +02:00
|
|
|
import appeng.util.Platform;
|
2014-05-01 06:01:22 +02:00
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
import codechicken.nei.api.IOverlayHandler;
|
|
|
|
import codechicken.nei.recipe.IRecipeHandler;
|
|
|
|
|
|
|
|
public class NEICraftingHandler implements IOverlayHandler
|
|
|
|
{
|
|
|
|
|
2014-09-17 06:23:19 +02:00
|
|
|
public NEICraftingHandler(int x, int y)
|
|
|
|
{
|
2014-05-01 06:01:22 +02:00
|
|
|
offsetx = x;
|
|
|
|
offsety = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offsetx;
|
|
|
|
int offsety;
|
|
|
|
|
2014-07-10 05:18:50 +02:00
|
|
|
@Override
|
2014-05-01 06:01:22 +02:00
|
|
|
public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeIndex, boolean shift)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
List ingredients = recipe.getIngredientStacks( recipeIndex );
|
|
|
|
overlayRecipe( gui, ingredients, shift );
|
|
|
|
}
|
|
|
|
catch (Exception err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch (Error err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void overlayRecipe(GuiContainer gui, List<PositionedStack> ingredients, boolean shift)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NBTTagCompound recipe = new NBTTagCompound();
|
|
|
|
|
2014-07-06 08:52:29 +02:00
|
|
|
if ( gui instanceof GuiCraftingTerm || gui instanceof GuiPatternTerm )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < ingredients.size(); i++)// identify slots
|
|
|
|
{
|
|
|
|
PositionedStack pstack = ingredients.get( i );
|
|
|
|
int col = (pstack.relx - 25) / 18;
|
|
|
|
int row = (pstack.rely - 6) / 18;
|
2014-08-19 22:00:32 +02:00
|
|
|
if ( pstack.items != null && pstack.items.length > 0 )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
|
|
|
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
|
|
|
|
{
|
2014-07-06 08:52:29 +02:00
|
|
|
if ( slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-07-06 08:52:29 +02:00
|
|
|
Slot ctSlot = (Slot) slot;
|
2014-05-01 06:01:22 +02:00
|
|
|
if ( ctSlot.getSlotIndex() == col + row * 3 )
|
|
|
|
{
|
2014-08-19 22:00:32 +02:00
|
|
|
NBTTagList ilist = new NBTTagList();
|
2014-09-17 06:23:19 +02:00
|
|
|
List<ItemStack> list = new LinkedList();
|
|
|
|
|
|
|
|
// prefer pure crystals.
|
2014-08-20 04:02:37 +02:00
|
|
|
for (int x = 0; x < pstack.items.length; x++)
|
2014-09-17 06:23:19 +02:00
|
|
|
{
|
|
|
|
if ( Platform.isRecipePrioritized( pstack.items[x] ) )
|
|
|
|
list.add( 0, pstack.items[x] );
|
|
|
|
else
|
|
|
|
list.add( pstack.items[x] );
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ItemStack is : list)
|
2014-08-19 22:00:32 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound inbt = new NBTTagCompound();
|
2014-09-17 06:23:19 +02:00
|
|
|
is.writeToNBT( inbt );
|
2014-08-20 04:02:37 +02:00
|
|
|
ilist.appendTag( inbt );
|
2014-08-19 22:00:32 +02:00
|
|
|
}
|
2014-09-17 06:23:19 +02:00
|
|
|
|
2014-08-19 22:00:32 +02:00
|
|
|
recipe.setTag( "#" + ctSlot.getSlotIndex(), ilist );
|
2014-05-01 06:01:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketNEIRecipe( recipe ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch (Error err)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|