Fill pattern with items from JEI

Just Enough Energistics overrides this
This commit is contained in:
Salomão
2021-02-11 23:07:26 -03:00
parent 97ae7e1f14
commit c10088d907
3 changed files with 73 additions and 2 deletions
@@ -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] );
}
}
}
}
@@ -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 )
@@ -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<T extends Container> 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<T extends Container> implements IRecipeTransferHandl
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
final NBTTagCompound recipe = new NBTTagCompound();
final NBTTagList outputs = new NBTTagList();
int slotIndex = 0;
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();
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<T extends Container> implements IRecipeTransferHandl
slotIndex++;
}
recipe.setTag( "outputs", outputs );
try
{
NetworkHandler.instance().sendToServer( new PacketJEIRecipe( recipe ) );