Fill pattern with items from JEI
Just Enough Energistics overrides this
This commit is contained in:
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import appeng.container.implementations.ContainerPatternTerm;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
@@ -64,6 +65,8 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
{
|
{
|
||||||
|
|
||||||
private ItemStack[][] recipe;
|
private ItemStack[][] recipe;
|
||||||
|
private ItemStack[] output;
|
||||||
|
|
||||||
|
|
||||||
// automatic.
|
// automatic.
|
||||||
public PacketJEIRecipe( final ByteBuf stream ) throws IOException
|
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
|
// api
|
||||||
@@ -220,12 +235,28 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
currentItem = ad.simulateRemove( 1, this.recipe[x][y], null );
|
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 );
|
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] );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.Optional;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import mezz.jei.config.Constants;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ public class JEIPlugin implements IModPlugin
|
|||||||
VanillaRecipeCategoryUid.CRAFTING );
|
VanillaRecipeCategoryUid.CRAFTING );
|
||||||
registry.getRecipeTransferRegistry()
|
registry.getRecipeTransferRegistry()
|
||||||
.addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ),
|
.addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ),
|
||||||
VanillaRecipeCategoryUid.CRAFTING );
|
Constants.UNIVERSAL_RECIPE_TRANSFER_UID );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerDescriptions( IDefinitions definitions, IModRegistry registry )
|
private void registerDescriptions( IDefinitions definitions, IModRegistry registry )
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
@@ -66,6 +71,29 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
@Override
|
@Override
|
||||||
public IRecipeTransferError transferRecipe( T container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer )
|
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 )
|
if( !doTransfer )
|
||||||
{
|
{
|
||||||
@@ -75,6 +103,8 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
|
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||||
|
|
||||||
final NBTTagCompound recipe = new NBTTagCompound();
|
final NBTTagCompound recipe = new NBTTagCompound();
|
||||||
|
final NBTTagList outputs = new NBTTagList();
|
||||||
|
|
||||||
|
|
||||||
int slotIndex = 0;
|
int slotIndex = 0;
|
||||||
for( Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ingredientEntry : ingredients.entrySet() )
|
for( Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ingredientEntry : ingredients.entrySet() )
|
||||||
@@ -82,6 +112,13 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
IGuiIngredient<ItemStack> ingredient = ingredientEntry.getValue();
|
IGuiIngredient<ItemStack> ingredient = ingredientEntry.getValue();
|
||||||
if( !ingredient.isInput() )
|
if( !ingredient.isInput() )
|
||||||
{
|
{
|
||||||
|
ItemStack output = ingredient.getDisplayedIngredient();
|
||||||
|
if( output != null )
|
||||||
|
{
|
||||||
|
final NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
output.writeToNBT( tag );
|
||||||
|
outputs.appendTag( tag );
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +167,8 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
slotIndex++;
|
slotIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recipe.setTag( "outputs", outputs );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NetworkHandler.instance().sendToServer( new PacketJEIRecipe( recipe ) );
|
NetworkHandler.instance().sendToServer( new PacketJEIRecipe( recipe ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user