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;
|
2014-01-31 07:33:04 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
|
|
|
import appeng.api.implementations.items.IBiometricCard;
|
2014-01-29 06:28:39 +01:00
|
|
|
import appeng.client.render.items.ToolBiometricCardRender;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.localization.GuiText;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2014-01-31 07:33:04 +01:00
|
|
|
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
2014-01-29 06:28:39 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public ToolBiometricCard() {
|
|
|
|
super( ToolBiometricCard.class );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Security ) );
|
|
|
|
setMaxStackSize( 1 );
|
|
|
|
if ( Platform.isClient() )
|
2014-02-09 02:34:52 +01:00
|
|
|
MinecraftForgeClient.registerItemRenderer( this, new ToolBiometricCardRender() );
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public String getItemStackDisplayName(ItemStack is)
|
2014-01-29 06:28:39 +01:00
|
|
|
{
|
2014-02-01 06:37:27 +01:00
|
|
|
String username = getUsername( is );
|
2014-02-09 02:34:52 +01:00
|
|
|
return username.length() > 0 ? super.getItemStackDisplayName( is ) + " - " + username : super.getItemStackDisplayName( is );
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean itemInteractionForEntity(ItemStack is, EntityPlayer par2EntityPlayer, EntityLivingBase target)
|
|
|
|
{
|
2014-01-31 03:02:18 +01:00
|
|
|
if ( target instanceof EntityPlayer && !par2EntityPlayer.isSneaking() )
|
2014-01-29 06:28:39 +01:00
|
|
|
{
|
|
|
|
if ( par2EntityPlayer.capabilities.isCreativeMode )
|
|
|
|
is = par2EntityPlayer.getCurrentEquippedItem();
|
|
|
|
encode( is, (EntityPlayer) target );
|
2014-01-31 03:02:18 +01:00
|
|
|
par2EntityPlayer.swingItem();
|
2014-01-29 06:28:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-31 03:02:18 +01:00
|
|
|
public ItemStack onItemRightClick(ItemStack is, World w, EntityPlayer p)
|
2014-01-29 06:28:39 +01:00
|
|
|
{
|
|
|
|
if ( p.isSneaking() )
|
|
|
|
{
|
|
|
|
encode( is, p );
|
2014-01-31 03:02:18 +01:00
|
|
|
p.swingItem();
|
|
|
|
return is;
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 03:02:18 +01:00
|
|
|
return is;
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void encode(ItemStack is, EntityPlayer p)
|
|
|
|
{
|
2014-02-01 06:37:27 +01:00
|
|
|
String username = getUsername( is );
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( p.getCommandSenderName().equals( username ) )
|
2014-02-01 06:37:27 +01:00
|
|
|
setUsername( is, "" );
|
2014-01-29 06:28:39 +01:00
|
|
|
else
|
2014-02-09 02:34:52 +01:00
|
|
|
setUsername( is, p.getCommandSenderName() );
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean b)
|
|
|
|
{
|
2014-02-06 06:17:06 +01:00
|
|
|
// String username = getUsername( is );
|
|
|
|
// if ( username.length() > 0 )
|
|
|
|
// l.add( username );
|
2014-02-01 06:37:27 +01:00
|
|
|
|
|
|
|
EnumSet<SecurityPermissions> perms = getPermissions( is );
|
|
|
|
if ( perms.isEmpty() )
|
|
|
|
l.add( GuiText.NoPermissions.getLocal() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String msg = null;
|
|
|
|
|
|
|
|
for (SecurityPermissions sp : perms)
|
|
|
|
{
|
|
|
|
if ( msg == null )
|
|
|
|
msg = Platform.gui_localize( sp.getUnlocalizedName() );
|
|
|
|
else
|
|
|
|
msg = msg + ", " + Platform.gui_localize( sp.getUnlocalizedName() );
|
|
|
|
}
|
|
|
|
l.add( msg );
|
|
|
|
}
|
|
|
|
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:33:04 +01:00
|
|
|
@Override
|
2014-02-01 06:37:27 +01:00
|
|
|
public String getUsername(ItemStack is)
|
2014-01-31 07:33:04 +01:00
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( is );
|
|
|
|
return tag.getString( "username" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<SecurityPermissions> getPermissions(ItemStack is)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( is );
|
|
|
|
EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
|
|
|
|
|
|
|
|
for (SecurityPermissions sp : SecurityPermissions.values())
|
|
|
|
{
|
|
|
|
if ( tag.getBoolean( sp.name() ) )
|
|
|
|
result.add( sp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(ItemStack is, SecurityPermissions permission)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( is );
|
|
|
|
return tag.getBoolean( permission.name() );
|
|
|
|
}
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
@Override
|
|
|
|
public void setUsername(ItemStack itemStack, String username)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
|
|
|
tag.setString( "username", username );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removePermission(ItemStack itemStack, SecurityPermissions permission)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
|
|
|
if ( tag.hasKey( permission.name() ) )
|
|
|
|
tag.removeTag( permission.name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addPermission(ItemStack itemStack, SecurityPermissions permission)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
|
|
|
tag.setBoolean( permission.name(), true );
|
|
|
|
}
|
|
|
|
|
2014-01-29 06:28:39 +01:00
|
|
|
}
|