2014-04-17 08:15:56 +02:00
|
|
|
package appeng.items.misc;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2014-04-25 03:55:29 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-04-23 03:36:26 +02:00
|
|
|
import net.minecraftforge.client.MinecraftForgeClient;
|
2014-04-17 08:15:56 +02:00
|
|
|
import appeng.api.implementations.ICraftingPatternItem;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
2014-04-23 03:36:26 +02:00
|
|
|
import appeng.client.render.items.ItemEncodedPatternRenderer;
|
2014-04-17 08:15:56 +02:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.localization.GuiText;
|
2014-04-25 03:55:29 +02:00
|
|
|
import appeng.helpers.PatternHelper;
|
2014-04-17 08:15:56 +02:00
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
|
|
|
|
{
|
|
|
|
|
|
|
|
public ItemEncodedPattern() {
|
|
|
|
super( ItemEncodedPattern.class );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Crafting ) );
|
|
|
|
setMaxStackSize( 1 );
|
2014-04-23 03:36:26 +02:00
|
|
|
if ( Platform.isClient() )
|
|
|
|
MinecraftForgeClient.registerItemRenderer( this, new ItemEncodedPatternRenderer() );
|
2014-04-17 08:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean more)
|
|
|
|
{
|
|
|
|
NBTTagCompound encodedValue = is.getTagCompound();
|
|
|
|
|
|
|
|
if ( encodedValue == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
|
|
|
|
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
|
|
|
|
boolean isCrafting = encodedValue.getBoolean( "crafting" );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
|
|
|
|
String and = " " + GuiText.And.getLocal() + " ";
|
|
|
|
String with = GuiText.With.getLocal() + ": ";
|
|
|
|
|
|
|
|
boolean first = true;
|
|
|
|
for (int x = 0; x < out.length; x++)
|
|
|
|
{
|
|
|
|
if ( out[x] == null )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
l.add( (first ? label : and) + out[x].stackSize + " " + Platform.getItemDisplayName( out[x] ) );
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = true;
|
|
|
|
for (int x = 0; x < in.length; x++)
|
|
|
|
{
|
|
|
|
if ( in[x] == null )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
l.add( (first ? with : and) + in[x].stackSize + " " + Platform.getItemDisplayName( in[x] ) );
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 07:30:29 +02:00
|
|
|
public ItemStack getOutput(ItemStack item)
|
|
|
|
{
|
|
|
|
NBTTagCompound encodedValue = item.getTagCompound();
|
|
|
|
|
|
|
|
if ( encodedValue == null )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
|
|
|
|
|
|
|
|
if ( outTag.tagCount() == 0 )
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-17 08:15:56 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-25 03:55:29 +02:00
|
|
|
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w)
|
2014-04-17 08:15:56 +02:00
|
|
|
{
|
2014-04-25 03:55:29 +02:00
|
|
|
return new PatternHelper( is, w );
|
2014-04-17 08:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|