1.15 port
This commit is contained in:
@@ -25,17 +25,18 @@ import java.util.List;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
@@ -50,32 +51,32 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
{
|
||||
public ToolBiometricCard()
|
||||
{
|
||||
this.setMaxStackSize( 1 );
|
||||
super( new Properties().maxStackSize( 1 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer p, final EnumHand hand )
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final Hand hand )
|
||||
{
|
||||
if( p.isSneaking() )
|
||||
if( p.isShiftKeyDown() )
|
||||
{
|
||||
this.encode( p.getHeldItem( hand ), p );
|
||||
p.swingArm( hand );
|
||||
return new ActionResult<>( EnumActionResult.SUCCESS, p.getHeldItem( hand ) );
|
||||
return ActionResult.resultSuccess( p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
return new ActionResult<>( EnumActionResult.PASS, p.getHeldItem( hand ) );
|
||||
return ActionResult.resultPass( p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean itemInteractionForEntity( ItemStack is, final EntityPlayer player, final EntityLivingBase target, final EnumHand hand )
|
||||
public boolean itemInteractionForEntity( ItemStack is, final PlayerEntity player, final LivingEntity target, final Hand hand )
|
||||
{
|
||||
if( target instanceof EntityPlayer && !player.isSneaking() )
|
||||
if( target instanceof PlayerEntity && !player.isShiftKeyDown() )
|
||||
{
|
||||
if( player.capabilities.isCreativeMode )
|
||||
if( player.isCreative() )
|
||||
{
|
||||
is = player.getHeldItem( hand );
|
||||
}
|
||||
this.encode( is, (EntityPlayer) target );
|
||||
this.encode( is, (PlayerEntity) target );
|
||||
player.swingArm( hand );
|
||||
return true;
|
||||
}
|
||||
@@ -83,13 +84,13 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName( final ItemStack is )
|
||||
public ITextComponent getDisplayName( final ItemStack is )
|
||||
{
|
||||
final GameProfile username = this.getProfile( is );
|
||||
return username != null ? super.getItemStackDisplayName( is ) + " - " + username.getName() : super.getItemStackDisplayName( is );
|
||||
return username != null ? super.getDisplayName( is ).appendText( " - " + username.getName() ) : super.getDisplayName( is );
|
||||
}
|
||||
|
||||
private void encode( final ItemStack is, final EntityPlayer p )
|
||||
private void encode( final ItemStack is, final PlayerEntity p )
|
||||
{
|
||||
final GameProfile username = this.getProfile( is );
|
||||
|
||||
@@ -106,27 +107,27 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
@Override
|
||||
public void setProfile( final ItemStack itemStack, final GameProfile profile )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
final CompoundNBT tag = Platform.openNbtData( itemStack );
|
||||
|
||||
if( profile != null )
|
||||
{
|
||||
final NBTTagCompound pNBT = new NBTTagCompound();
|
||||
final CompoundNBT pNBT = new CompoundNBT();
|
||||
NBTUtil.writeGameProfile( pNBT, profile );
|
||||
tag.setTag( "profile", pNBT );
|
||||
tag.put( "profile", pNBT );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.removeTag( "profile" );
|
||||
tag.remove( "profile" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getProfile( final ItemStack is )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( is );
|
||||
if( tag.hasKey( "profile" ) )
|
||||
final CompoundNBT tag = Platform.openNbtData( is );
|
||||
if( tag.contains( "profile" ) )
|
||||
{
|
||||
return NBTUtil.readGameProfileFromNBT( tag.getCompoundTag( "profile" ) );
|
||||
return NBTUtil.readGameProfile( tag.getCompound( "profile" ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -134,7 +135,7 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
@Override
|
||||
public EnumSet<SecurityPermissions> getPermissions( final ItemStack is )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( is );
|
||||
final CompoundNBT tag = Platform.openNbtData( is );
|
||||
final EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
|
||||
|
||||
for( final SecurityPermissions sp : SecurityPermissions.values() )
|
||||
@@ -151,25 +152,25 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
@Override
|
||||
public boolean hasPermission( final ItemStack is, final SecurityPermissions permission )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( is );
|
||||
final CompoundNBT tag = Platform.openNbtData( is );
|
||||
return tag.getBoolean( permission.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePermission( final ItemStack itemStack, final SecurityPermissions permission )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
if( tag.hasKey( permission.name() ) )
|
||||
final CompoundNBT tag = Platform.openNbtData( itemStack );
|
||||
if( tag.contains( permission.name() ) )
|
||||
{
|
||||
tag.removeTag( permission.name() );
|
||||
tag.remove( permission.name() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPermission( final ItemStack itemStack, final SecurityPermissions permission )
|
||||
{
|
||||
final NBTTagCompound tag = Platform.openNbtData( itemStack );
|
||||
tag.setBoolean( permission.name(), true );
|
||||
final CompoundNBT tag = Platform.openNbtData( itemStack );
|
||||
tag.putBoolean( permission.name(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,27 +180,27 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final EnumSet<SecurityPermissions> perms = this.getPermissions( stack );
|
||||
if( perms.isEmpty() )
|
||||
{
|
||||
lines.add( GuiText.NoPermissions.getLocal() );
|
||||
lines.add( new TranslationTextComponent( GuiText.NoPermissions.getLocal() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = null;
|
||||
ITextComponent msg = null;
|
||||
|
||||
for( final SecurityPermissions sp : perms )
|
||||
{
|
||||
if( msg == null )
|
||||
{
|
||||
msg = Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
msg = new TranslationTextComponent( sp.getTranslatedName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = msg + ", " + Platform.gui_localize( sp.getUnlocalizedName() );
|
||||
msg = msg.appendText( ", " ).appendSibling( new TranslationTextComponent( sp.getTranslatedName() ) );
|
||||
}
|
||||
}
|
||||
lines.add( msg );
|
||||
|
||||
Reference in New Issue
Block a user