This commit is contained in:
AlgorithmX2 2014-07-24 22:48:06 -05:00
commit 0244bb943f
5 changed files with 41 additions and 70 deletions

View file

@ -27,7 +27,8 @@ public class SlotDisconnected extends AppEngSlot
{
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ItemStack out = iep.getOutput( is );
return out;
if ( out != null )
return out;
}
}
return super.getStack();

View file

@ -102,7 +102,8 @@ public class SlotRestrictedInput extends AppEngSlot
{
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ItemStack out = iep.getOutput( is );
return out;
if ( out != null )
return out;
}
}
return super.getStack();

View file

@ -32,7 +32,7 @@ public enum GuiText
OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting,
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean;
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean, InvalidPattern;
String root;

View file

@ -142,8 +142,13 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
if ( isCrafting )
{
standardRecipe = Platform.findMatchingRecipe( crafting, w );
correctOutput = standardRecipe.getCraftingResult( crafting );
out.add( AEApi.instance().storage().createItemStack( correctOutput ) );
if ( standardRecipe != null )
{
correctOutput = standardRecipe.getCraftingResult( crafting );
out.add( AEApi.instance().storage().createItemStack( correctOutput ) );
}
else
throw new RuntimeException( "No pattern here!" );
}
else
{
@ -186,7 +191,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
else
g.add( io );
}
if ( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
throw new RuntimeException( "No pattern here!" );
int offset = 0;
condencedInputs = new IAEItemStack[tmpInputs.size()];
for (IAEItemStack io : tmpInputs.values())

View file

@ -6,14 +6,15 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import appeng.api.AEApi;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.render.items.ItemEncodedPatternRenderer;
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.helpers.PatternHelper;
@ -69,24 +70,18 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
@Override
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean more)
{
NBTTagCompound encodedValue = is.getTagCompound();
ICraftingPatternDetails details = getPatternForItem( is, p.worldObj );
if ( encodedValue == null )
if ( details == null )
{
l.add( EnumChatFormatting.RED + GuiText.InvalidPattern.getLocal() );
return;
}
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
boolean isCrafting = encodedValue.getBoolean( "crafting" );
boolean isCrafting = details.isCraftable();
// kinda needs info..
if ( inTag.tagCount() == 0 || outTag.tagCount() == 0 )
return;
ItemStack[] in = new ItemStack[inTag.tagCount()];
ItemStack[] out = new ItemStack[outTag.tagCount()];
readItems( in, inTag );
readItems( out, outTag );
IAEItemStack[] in = details.getCondencedInputs();
IAEItemStack[] out = details.getCondencedOutputs();
String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
String and = " " + GuiText.And.getLocal() + " ";
@ -98,7 +93,7 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
if ( out[x] == null )
continue;
l.add( (first ? label : and) + out[x].stackSize + " " + Platform.getItemDisplayName( out[x] ) );
l.add( (first ? label : and) + out[x].getStackSize() + " " + Platform.getItemDisplayName( out[x] ) );
first = false;
}
@ -108,70 +103,36 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
if ( in[x] == null )
continue;
l.add( (first ? with : and) + in[x].stackSize + " " + Platform.getItemDisplayName( in[x] ) );
l.add( (first ? with : and) + in[x].getStackSize() + " " + Platform.getItemDisplayName( in[x] ) );
first = false;
}
}
public ItemStack getOutput(ItemStack item)
{
NBTTagCompound encodedValue = item.getTagCompound();
if ( encodedValue == null )
World w = CommonHelper.proxy.getWorld();
if ( w == null )
return null;
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
ICraftingPatternDetails details = getPatternForItem( item, w );
if ( outTag.tagCount() == 0 )
if ( details == null )
return null;
ItemStack out = null;
for (int x = 0; x < outTag.tagCount(); x++)
{
ItemStack readItem = ItemStack.loadItemStackFromNBT( outTag.getCompoundTagAt( x ) );
if ( readItem != null )
{
if ( out == null )
out = readItem;
else if ( out != null && Platform.isSameItemPrecise( readItem, out ) )
out.stackSize += readItem.stackSize;
}
}
return out;
}
private void readItems(ItemStack[] itemList, NBTTagList tagSrc)
{
for (int x = 0; x < itemList.length; x++)
{
ItemStack readItem = ItemStack.loadItemStackFromNBT( tagSrc.getCompoundTagAt( x ) );
if ( readItem != null )
{
boolean used = false;
for (int y = 0; y < x; y++)
{
if ( itemList[y] != null && Platform.isSameItemPrecise( readItem, itemList[y] ) )
{
itemList[y].stackSize += readItem.stackSize;
used = true;
}
}
if ( !used )
itemList[x] = readItem;
}
}
return details.getCondencedOutputs()[0].getItemStack();
}
@Override
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w)
{
if ( is.hasTagCompound() )
try
{
return new PatternHelper( is, w );
return null;
}
catch (Throwable t)
{
return null;
}
}
}