Fixes #2542: Prevent memory card from opening a GUI

Some additional cleanup of AEBaseTileBlock#onBlockActivated()
This commit is contained in:
yueh 2016-10-31 17:48:49 +01:00 committed by yueh
parent 071ee83b7a
commit b6d3be41e1

View file

@ -271,18 +271,19 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
@Override @Override
public boolean onBlockActivated( final World w, final BlockPos pos, final IBlockState state, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ ) public boolean onBlockActivated( final World w, final BlockPos pos, final IBlockState state, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{ {
if( player != null ) if( player != null && heldItem != null )
{
if( heldItem != null )
{ {
if( Platform.isWrench( player, heldItem, pos ) && player.isSneaking() ) if( Platform.isWrench( player, heldItem, pos ) && player.isSneaking() )
{ {
final IBlockState ids = w.getBlockState( pos ); final IBlockState blockState = w.getBlockState( pos );
final Block id = ids.getBlock(); final Block block = blockState.getBlock();
if( id != null )
if( block == null )
{ {
return false;
}
final AEBaseTile tile = this.getTileEntity( w, pos ); final AEBaseTile tile = this.getTileEntity( w, pos );
final ItemStack[] drops = Platform.getBlockDrops( w, pos );
if( tile == null ) if( tile == null )
{ {
@ -294,8 +295,10 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
return false; return false;
} }
final ItemStack[] itemDropCandidates = Platform.getBlockDrops( w, pos );
final ItemStack op = new ItemStack( this ); final ItemStack op = new ItemStack( this );
for( final ItemStack ol : drops )
for( final ItemStack ol : itemDropCandidates )
{ {
if( Platform.isSameItemType( ol, op ) ) if( Platform.isSameItemType( ol, op ) )
{ {
@ -307,51 +310,54 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
} }
} }
if( id.removedByPlayer( ids, w, pos, player, false ) ) if( block.removedByPlayer( blockState, w, pos, player, false ) )
{ {
final List<ItemStack> l = Lists.newArrayList( drops ); final List<ItemStack> itemsToDrop = Lists.newArrayList( itemDropCandidates );
Platform.spawnDrops( w, pos, l ); Platform.spawnDrops( w, pos, itemsToDrop );
w.setBlockToAir( pos ); w.setBlockToAir( pos );
} }
}
return false; return false;
} }
if( heldItem.getItem() instanceof IMemoryCard && !( this instanceof BlockCableBus ) ) if( heldItem.getItem() instanceof IMemoryCard && !( this instanceof BlockCableBus ) )
{ {
final IMemoryCard memoryCard = (IMemoryCard) heldItem.getItem(); final IMemoryCard memoryCard = (IMemoryCard) heldItem.getItem();
final AEBaseTile tileEntity = this.getTileEntity( w, pos );
if( tileEntity == null )
{
return false;
}
final String name = this.getUnlocalizedName();
if( player.isSneaking() ) if( player.isSneaking() )
{ {
final AEBaseTile t = this.getTileEntity( w, pos ); final NBTTagCompound data = tileEntity.downloadSettings( SettingsFrom.MEMORY_CARD );
if( t != null )
{
final String name = this.getUnlocalizedName();
final NBTTagCompound data = t.downloadSettings( SettingsFrom.MEMORY_CARD );
if( data != null ) if( data != null )
{ {
memoryCard.setMemoryCardContents( heldItem, name, data ); memoryCard.setMemoryCardContents( heldItem, name, data );
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
return true;
}
} }
} }
else else
{ {
final String name = memoryCard.getSettingsName( heldItem ); final String savedName = memoryCard.getSettingsName( heldItem );
final NBTTagCompound data = memoryCard.getData( heldItem ); final NBTTagCompound data = memoryCard.getData( heldItem );
if( this.getUnlocalizedName().equals( name ) )
if( this.getUnlocalizedName().equals( savedName ) )
{ {
final AEBaseTile t = this.getTileEntity( w, pos ); tileEntity.uploadSettings( SettingsFrom.MEMORY_CARD, data );
t.uploadSettings( SettingsFrom.MEMORY_CARD, data );
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED ); memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
} }
else else
{ {
memoryCard.notifyUser( player, MemoryCardMessages.INVALID_MACHINE ); memoryCard.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
} }
return false;
}
} }
return true;
} }
} }