2014-04-17 08:15:56 +02:00
|
|
|
package appeng.items.misc;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2014-08-15 02:59:09 +02:00
|
|
|
import java.util.WeakHashMap;
|
2014-04-17 08:15:56 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-07-02 03:44:54 +02:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-04-17 08:15:56 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-07-24 17:59:57 +02:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
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-07-02 03:44:54 +02:00
|
|
|
import appeng.api.AEApi;
|
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-07-24 17:59:57 +02:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2014-04-23 03:36:26 +02:00
|
|
|
import appeng.client.render.items.ItemEncodedPatternRenderer;
|
2014-07-24 17:59:57 +02:00
|
|
|
import appeng.core.CommonHelper;
|
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 );
|
2014-09-20 23:26:30 +02:00
|
|
|
setFeature( EnumSet.of( AEFeature.Patterns ) );
|
2014-04-17 08:15:56 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-07-12 21:27:06 +02:00
|
|
|
private boolean clearPattern(ItemStack stack, EntityPlayer player)
|
2014-07-02 03:44:54 +02:00
|
|
|
{
|
2014-07-12 21:27:06 +02:00
|
|
|
if ( player.isSneaking() )
|
2014-07-02 03:44:54 +02:00
|
|
|
{
|
2014-07-12 21:27:06 +02:00
|
|
|
if ( Platform.isClient() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InventoryPlayer inv = player.inventory;
|
|
|
|
|
|
|
|
for (int s = 0; s < player.inventory.getSizeInventory(); s++)
|
2014-07-02 03:44:54 +02:00
|
|
|
{
|
2014-07-12 21:27:06 +02:00
|
|
|
if ( inv.getStackInSlot( s ) == stack )
|
|
|
|
{
|
|
|
|
inv.setInventorySlotContents( s, AEApi.instance().materials().materialBlankPattern.stack( stack.stackSize ) );
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-02 03:44:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-12 21:27:06 +02:00
|
|
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
return clearPattern( stack, player );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer player)
|
2014-07-02 03:44:54 +02:00
|
|
|
{
|
2014-07-12 21:27:06 +02:00
|
|
|
clearPattern( stack, player );
|
|
|
|
return stack;
|
2014-07-02 03:44:54 +02:00
|
|
|
}
|
|
|
|
|
2014-04-17 08:15:56 +02:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean more)
|
|
|
|
{
|
2014-07-24 17:59:57 +02:00
|
|
|
ICraftingPatternDetails details = getPatternForItem( is, p.worldObj );
|
2014-04-17 08:15:56 +02:00
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
if ( details == null )
|
|
|
|
{
|
|
|
|
l.add( EnumChatFormatting.RED + GuiText.InvalidPattern.getLocal() );
|
2014-04-17 08:15:56 +02:00
|
|
|
return;
|
2014-07-24 17:59:57 +02:00
|
|
|
}
|
2014-04-17 08:15:56 +02:00
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
boolean isCrafting = details.isCraftable();
|
2014-04-17 08:15:56 +02:00
|
|
|
|
2014-09-20 22:30:31 +02:00
|
|
|
IAEItemStack[] in = details.getCondensedInputs();
|
2014-09-20 22:30:12 +02:00
|
|
|
IAEItemStack[] out = details.getCondensedOutputs();
|
2014-04-17 08:15:56 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
l.add( (first ? label : and) + out[x].getStackSize() + " " + Platform.getItemDisplayName( out[x] ) );
|
2014-04-17 08:15:56 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = true;
|
|
|
|
for (int x = 0; x < in.length; x++)
|
|
|
|
{
|
|
|
|
if ( in[x] == null )
|
|
|
|
continue;
|
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
l.add( (first ? with : and) + in[x].getStackSize() + " " + Platform.getItemDisplayName( in[x] ) );
|
2014-04-17 08:15:56 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 02:59:09 +02:00
|
|
|
// rather simple client side cacheing.
|
2014-08-15 03:23:37 +02:00
|
|
|
static WeakHashMap<ItemStack, ItemStack> simpleCache = new WeakHashMap<ItemStack, ItemStack>();
|
2014-08-15 02:59:09 +02:00
|
|
|
|
2014-04-23 07:30:29 +02:00
|
|
|
public ItemStack getOutput(ItemStack item)
|
|
|
|
{
|
2014-08-15 03:23:37 +02:00
|
|
|
ItemStack out = simpleCache.get( item );
|
|
|
|
if ( out != null )
|
|
|
|
return out;
|
2014-08-15 02:59:09 +02:00
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
World w = CommonHelper.proxy.getWorld();
|
|
|
|
if ( w == null )
|
2014-04-23 07:30:29 +02:00
|
|
|
return null;
|
|
|
|
|
2014-08-15 03:23:37 +02:00
|
|
|
ICraftingPatternDetails details = getPatternForItem( item, w );
|
2014-04-23 07:30:29 +02:00
|
|
|
|
2014-07-24 17:59:57 +02:00
|
|
|
if ( details == null )
|
2014-04-23 07:30:29 +02:00
|
|
|
return null;
|
|
|
|
|
2014-09-20 22:30:12 +02:00
|
|
|
simpleCache.put( item, out = details.getCondensedOutputs()[0].getItemStack() );
|
2014-08-15 03:23:37 +02:00
|
|
|
return out;
|
2014-04-17 08:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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-07-24 17:59:57 +02:00
|
|
|
try
|
|
|
|
{
|
2014-07-02 03:44:54 +02:00
|
|
|
return new PatternHelper( is, w );
|
2014-07-24 17:59:57 +02:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2014-04-17 08:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|