package info.u_team.u_team_test.entity;

import java.util.Random;

import info.u_team.u_team_test.init.TestEntityTypes;
import net.minecraft.client.renderer.EffectInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.attributes.AttributeModifierMap.MutableAttribute;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.network.IPacket;
import net.minecraft.potion.Effects;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.IServerWorld;
import net.minecraft.world.World;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fmllegacy.network.NetworkHooks;

public class TestLivingEntity extends ZombieEntity {
	
	public TestLivingEntity(World world) {
		this(TestEntityTypes.TEST_LIVING.get(), world);
	}
	
	public TestLivingEntity(EntityType<? extends ZombieEntity> type, World world) {
		super(type, world);
	}
	
	public static MutableAttribute registerAttributes() {
		return ZombieEntity.func_234342_eQ_() //
				.createMutableAttribute(Attributes.ATTACK_DAMAGE, 6);
	}
	
	public static boolean canSpawn(EntityType<TestLivingEntity> entityType, IServerWorld world, SpawnReason reason, BlockPos pos, Random random) {
		return canMonsterSpawn(entityType, world, reason, pos, random) && (reason == SpawnReason.SPAWNER || world.canSeeSky(pos));
	}
	
	@Override
	protected boolean shouldBurnInDay() {
		return false;
	}
	
	@Override
	protected SoundEvent getAmbientSound() {
		return SoundEvents.BLOCK_LODESTONE_PLACE;
	}
	
	@Override
	protected SoundEvent getHurtSound(DamageSource source) {
		return SoundEvents.ENTITY_ARROW_SHOOT;
	}
	
	@Override
	protected SoundEvent getDeathSound() {
		return SoundEvents.ENTITY_DONKEY_DEATH;
	}
	
	@Override
	protected SoundEvent getStepSound() {
		return SoundEvents.ENTITY_HOGLIN_HURT;
	}
	
	@Override
	public boolean attackEntityAsMob(Entity entity) {
		final boolean flag = super.attackEntityAsMob(entity);
		if (flag && getHeldItemMainhand().isEmpty() && entity instanceof LivingEntity) {
			final float localDifficulty = world.getDifficultyForLocation(getPosition()).getAdditionalDifficulty();
			((LivingEntity) entity).addPotionEffect(new EffectInstance(Effects.LEVITATION, (int) (500 * localDifficulty)));
		}
		return flag;
	}
	
	@Override
	protected boolean shouldDrown() {
		return false;
	}
	
	@Override
	protected ItemStack getSkullDrop() {
		return new ItemStack(Items.GHAST_TEAR);
	}
	
	@Override
	public IPacket<?> createSpawnPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}
}

package info.u_team.u_team_test.entity;

import java.util.Random;

import info.u_team.u_team_test.init.TestEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.Packet;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraftforge.fmllegacy.network.NetworkHooks;

public class TestLivingEntity extends Zombie {
	
	public TestLivingEntity(Level world) {
		this(TestEntityTypes.TEST_LIVING.get(), world);
	}
	
	public TestLivingEntity(EntityType<? extends Zombie> type, Level world) {
		super(type, world);
	}
	
	public static AttributeSupplier.Builder createAttributes() {
		return Zombie.createAttributes() //
				.add(Attributes.ATTACK_DAMAGE, 6);
	}
	
	public static boolean canSpawn(EntityType<TestLivingEntity> entityType, ServerLevelAccessor world, MobSpawnType reason, BlockPos pos, Random random) {
		return checkAnyLightMonsterSpawnRules(entityType, world, reason, pos, random) && (reason == MobSpawnType.SPAWNER || world.canSeeSky(pos));
	}
	
	@Override
	protected boolean isSunSensitive() {
		return false;
	}
	
	@Override
	protected SoundEvent getAmbientSound() {
		return SoundEvents.LODESTONE_PLACE;
	}
	
	@Override
	protected SoundEvent getHurtSound(DamageSource source) {
		return SoundEvents.ARROW_SHOOT;
	}
	
	@Override
	protected SoundEvent getDeathSound() {
		return SoundEvents.DONKEY_DEATH;
	}
	
	@Override
	protected SoundEvent getStepSound() {
		return SoundEvents.HOGLIN_HURT;
	}
	
	@Override
	public boolean doHurtTarget(Entity entity) {
		final boolean flag = super.doHurtTarget(entity);
		if (flag && getMainHandItem().isEmpty() && entity instanceof LivingEntity livingEntity) {
			final float localDifficulty = level.getCurrentDifficultyAt(blockPosition()).getEffectiveDifficulty();
			livingEntity.addEffect(new MobEffectInstance(MobEffects.LEVITATION, (int) (500 * localDifficulty)));
		}
		return flag;
	}
	
	@Override
	protected boolean convertsInWater() {
		return false;
	}
	
	@Override
	protected ItemStack getSkull() {
		return new ItemStack(Items.GHAST_TEAR);
	}
	
	@Override
	public Packet<?> getAddEntityPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}
}

Fix custom living entity zombie