diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index 85f765145..e7e3c4546 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import appeng.container.implementations.ContainerPatternTerm; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -64,6 +65,8 @@ public class PacketJEIRecipe extends AppEngPacket { private ItemStack[][] recipe; + private ItemStack[] output; + // automatic. public PacketJEIRecipe( final ByteBuf stream ) throws IOException @@ -86,7 +89,19 @@ public class PacketJEIRecipe extends AppEngPacket } } } + if ( comp.hasKey("outputs") ) { + final NBTTagList outputList = comp.getTagList("outputs", 10); + this.output = new ItemStack[3]; + for( int x = 0; x < this.output.length; x++ ) + { + if( outputList.tagCount() > 0 ) + { + this.output[x] = new ItemStack(outputList.getCompoundTagAt( x )); + } + } + } } + } // api @@ -220,12 +235,28 @@ public class PacketJEIRecipe extends AppEngPacket currentItem = ad.simulateRemove( 1, this.recipe[x][y], null ); } } + if( currentItem.isEmpty() && con instanceof ContainerPatternTerm ) + { + currentItem = this.recipe[x][y].copy(); + } } } } ItemHandlerUtil.setStackInSlot( craftMatrix, x, currentItem ); } - con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) ); + if( this.output == null ) + { + con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) ); + } + + if( this.output != null && !( (ContainerPatternTerm) con ).isCraftingMode() ) + { + IItemHandler outputSlots = cct.getInventoryByName( "output" ); + for( int i = 0; i < this.output.length; ++i ) + { + ItemHandlerUtil.setStackInSlot( outputSlots, i, this.output[i] ); + } + } } } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index 08c6630e4..3a3dc2692 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -26,6 +26,7 @@ import java.util.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import mezz.jei.config.Constants; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -91,7 +92,7 @@ public class JEIPlugin implements IModPlugin VanillaRecipeCategoryUid.CRAFTING ); registry.getRecipeTransferRegistry() .addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ), - VanillaRecipeCategoryUid.CRAFTING ); + Constants.UNIVERSAL_RECIPE_TRANSFER_UID ); } private void registerDescriptions( IDefinitions definitions, IModRegistry registry ) diff --git a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java index 4bda1835e..6accaa084 100644 --- a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java +++ b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java @@ -26,6 +26,11 @@ import java.util.Map; import javax.annotation.Nullable; +import appeng.container.implementations.ContainerPatternTerm; +import mezz.jei.api.recipe.VanillaRecipeCategoryUid; +import mezz.jei.transfer.RecipeTransferErrorInternal; +import mezz.jei.transfer.RecipeTransferErrorTooltip; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; @@ -66,6 +71,29 @@ class RecipeTransferHandler implements IRecipeTransferHandl @Override public IRecipeTransferError transferRecipe( T container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer ) { + final String recipeType = recipeLayout.getRecipeCategory().getUid(); + + if (!recipeType.equals( VanillaRecipeCategoryUid.INFORMATION) && !recipeType.equals(VanillaRecipeCategoryUid.FUEL)) + { + if( container instanceof ContainerPatternTerm ) + { + if( !( (ContainerPatternTerm) container ).isCraftingMode() ) + { + if( recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) ) + { + return new RecipeTransferErrorTooltip( I18n.format( "gui.appliedenergistics2.CraftingPattern" ) ); + } + } + else if( !recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) ) + { + return new RecipeTransferErrorTooltip( I18n.format( "gui.appliedenergistics2.ProcessingPattern" ) ); + } + } + else + { + return RecipeTransferErrorInternal.INSTANCE; + } + } if( !doTransfer ) { @@ -75,6 +103,8 @@ class RecipeTransferHandler implements IRecipeTransferHandl Map> ingredients = recipeLayout.getItemStacks().getGuiIngredients(); final NBTTagCompound recipe = new NBTTagCompound(); + final NBTTagList outputs = new NBTTagList(); + int slotIndex = 0; for( Map.Entry> ingredientEntry : ingredients.entrySet() ) @@ -82,6 +112,13 @@ class RecipeTransferHandler implements IRecipeTransferHandl IGuiIngredient ingredient = ingredientEntry.getValue(); if( !ingredient.isInput() ) { + ItemStack output = ingredient.getDisplayedIngredient(); + if( output != null ) + { + final NBTTagCompound tag = new NBTTagCompound(); + output.writeToNBT( tag ); + outputs.appendTag( tag ); + } continue; } @@ -130,6 +167,8 @@ class RecipeTransferHandler implements IRecipeTransferHandl slotIndex++; } + recipe.setTag( "outputs", outputs ); + try { NetworkHandler.instance().sendToServer( new PacketJEIRecipe( recipe ) );