Skip to main content
1 of 3
WildWeazel
  • 306
  • 1
  • 10

I'm going to assume you're using the Forge API, given the parameters you listed.

EntityLiving is an abstract type representing living entities like players and mobs. When it is passed into your block break event, it indicates the entity which broke the block. It's not guaranteed to be a player, so you need to try to cast it to the subtype that represents a player:

EntityPlayer player = (EntityPlayer) par7EntityLiving;
if( player != null ) {
  player.addExperience(-1);
  // OR
  player.addExperienceLevel(-1);
}

If player is null, then the cast failed because EntityPlayer did not represent a EntityPlayer object and the block break was caused by something else.

WildWeazel
  • 306
  • 1
  • 10