Applied-Energistics-2-tiler.../items/tools/ToolBiometricCard.java

82 lines
2.2 KiB
Java
Raw Normal View History

2014-01-29 06:28:39 +01:00
package appeng.items.tools;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import appeng.client.render.items.ToolBiometricCardRender;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolBiometricCard extends AEBaseItem
{
public ToolBiometricCard() {
super( ToolBiometricCard.class );
setfeature( EnumSet.of( AEFeature.Security ) );
setMaxStackSize( 1 );
if ( Platform.isClient() )
MinecraftForgeClient.registerItemRenderer( itemID, new ToolBiometricCardRender() );
}
@Override
public String getItemDisplayName(ItemStack is)
{
NBTTagCompound tag = Platform.openNbtData( is );
String username = tag.getString( "username" );
2014-01-30 19:54:32 +01:00
return username.length() > 0 ? super.getItemDisplayName( is ) + " - " + GuiText.Encoded.getLocal() : super.getItemDisplayName( is );
2014-01-29 06:28:39 +01:00
}
@Override
public boolean itemInteractionForEntity(ItemStack is, EntityPlayer par2EntityPlayer, EntityLivingBase target)
{
if ( target instanceof EntityPlayer )
{
if ( par2EntityPlayer.capabilities.isCreativeMode )
is = par2EntityPlayer.getCurrentEquippedItem();
encode( is, (EntityPlayer) target );
return true;
}
return false;
}
@Override
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitx, float hity, float hitz)
{
if ( p.isSneaking() )
{
encode( is, p );
return true;
}
return false;
}
private void encode(ItemStack is, EntityPlayer p)
{
NBTTagCompound tag = Platform.openNbtData( is );
String username = tag.getString( "username" );
if ( p.username.equals( username ) )
is.setTagCompound( null );
else
tag.setString( "username", p.username );
}
@Override
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean b)
{
NBTTagCompound tag = Platform.openNbtData( is );
String username = tag.getString( "username" );
if ( username.length() > 0 )
l.add( username );
}
}