Fixes #675 No disabled feature should log spam or crash anymore.
Deprecates the old usage of the AEItemDefinitions via the direct method access of * blocks() * parts() * items() * materials() and thus use the new re-direct via definitions(). All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
@@ -18,11 +18,10 @@
|
||||
|
||||
package appeng.items.tools;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -31,6 +30,8 @@ import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
@@ -41,26 +42,33 @@ import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
{
|
||||
|
||||
public ToolBiometricCard() {
|
||||
super( ToolBiometricCard.class );
|
||||
public ToolBiometricCard()
|
||||
{
|
||||
this.setFeature( EnumSet.of( AEFeature.Security ) );
|
||||
this.setMaxStackSize( 1 );
|
||||
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new ToolBiometricCardRender() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
public ItemStack onItemRightClick( ItemStack is, World w, EntityPlayer p )
|
||||
{
|
||||
GameProfile username = this.getProfile( is );
|
||||
return username != null ? super.getItemStackDisplayName( is ) + " - " + username.getName() : super.getItemStackDisplayName( is );
|
||||
if ( p.isSneaking() )
|
||||
{
|
||||
this.encode( is, p );
|
||||
p.swingItem();
|
||||
return is;
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean itemInteractionForEntity(ItemStack is, EntityPlayer par2EntityPlayer, EntityLivingBase target)
|
||||
public boolean itemInteractionForEntity( ItemStack is, EntityPlayer par2EntityPlayer, EntityLivingBase target )
|
||||
{
|
||||
if ( target instanceof EntityPlayer && !par2EntityPlayer.isSneaking() )
|
||||
{
|
||||
@@ -74,66 +82,53 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack is, World w, EntityPlayer p)
|
||||
public String getItemStackDisplayName( ItemStack is )
|
||||
{
|
||||
if ( p.isSneaking() )
|
||||
{
|
||||
this.encode( is, p );
|
||||
p.swingItem();
|
||||
return is;
|
||||
}
|
||||
|
||||
return is;
|
||||
GameProfile username = this.getProfile( is );
|
||||
return username != null ? super.getItemStackDisplayName( is ) + " - " + username.getName() : super.getItemStackDisplayName( is );
|
||||
}
|
||||
|
||||
private void encode(ItemStack is, EntityPlayer p)
|
||||
private void encode( ItemStack is, EntityPlayer p )
|
||||
{
|
||||
GameProfile username = this.getProfile( is );
|
||||
|
||||
if (username != null && username.equals(p.getGameProfile()))
|
||||
if ( username != null && username.equals( p.getGameProfile() ) )
|
||||
this.setProfile( is, null );
|
||||
else
|
||||
this.setProfile( is, p.getGameProfile() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
public void setProfile( ItemStack itemStack, GameProfile profile )
|
||||
{
|
||||
EnumSet<SecurityPermissions> perms = this.getPermissions( stack );
|
||||
if ( perms.isEmpty() )
|
||||
lines.add( GuiText.NoPermissions.getLocal() );
|
||||
else
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
|
||||
if ( profile != null )
|
||||
{
|
||||
String msg = null;
|
||||
|
||||
for (SecurityPermissions sp : perms)
|
||||
{
|
||||
if ( msg == null )
|
||||
msg = Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
else
|
||||
msg = msg + ", " + Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
}
|
||||
lines.add( msg );
|
||||
NBTTagCompound pNBT = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a( pNBT, profile );
|
||||
tag.setTag( "profile", pNBT );
|
||||
}
|
||||
|
||||
else
|
||||
tag.removeTag( "profile" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getProfile(ItemStack is)
|
||||
public GameProfile getProfile( ItemStack is )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
if ( tag.hasKey("profile") )
|
||||
return NBTUtil.func_152459_a(tag.getCompoundTag("profile") );
|
||||
if ( tag.hasKey( "profile" ) )
|
||||
return NBTUtil.func_152459_a( tag.getCompoundTag( "profile" ) );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<SecurityPermissions> getPermissions(ItemStack is)
|
||||
public EnumSet<SecurityPermissions> getPermissions( ItemStack is )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
|
||||
|
||||
for (SecurityPermissions sp : SecurityPermissions.values())
|
||||
for ( SecurityPermissions sp : SecurityPermissions.values() )
|
||||
{
|
||||
if ( tag.getBoolean( sp.name() ) )
|
||||
result.add( sp );
|
||||
@@ -143,29 +138,14 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(ItemStack is, SecurityPermissions permission)
|
||||
public boolean hasPermission( ItemStack is, SecurityPermissions permission )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( is );
|
||||
return tag.getBoolean( permission.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProfile(ItemStack itemStack, GameProfile profile)
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
|
||||
if ( profile!= null )
|
||||
{
|
||||
NBTTagCompound pNBT = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a( pNBT, profile );
|
||||
tag.setTag( "profile", pNBT );
|
||||
}
|
||||
else
|
||||
tag.removeTag("profile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePermission(ItemStack itemStack, SecurityPermissions permission)
|
||||
public void removePermission( ItemStack itemStack, SecurityPermissions permission )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
if ( tag.hasKey( permission.name() ) )
|
||||
@@ -173,15 +153,36 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPermission(ItemStack itemStack, SecurityPermissions permission)
|
||||
public void addPermission( ItemStack itemStack, SecurityPermissions permission )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
tag.setBoolean( permission.name(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPermissions(ISecurityRegistry register, IPlayerRegistry pr, ItemStack is)
|
||||
public void registerPermissions( ISecurityRegistry register, IPlayerRegistry pr, ItemStack is )
|
||||
{
|
||||
register.addPlayer( pr.getID( this.getProfile( is ) ), this.getPermissions( is ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
{
|
||||
EnumSet<SecurityPermissions> perms = this.getPermissions( stack );
|
||||
if ( perms.isEmpty() )
|
||||
lines.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() );
|
||||
}
|
||||
lines.add( msg );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user