Hey, guys. I hope that 1.16.2 version of Forge accepting on this site. Well I finally made my mob Render and AI. And it's succefully was spawned in my world after summon command. But when it's happends game crashed. Please , don't ignore me and help me with this problem. Here's entity code:
package com.kikoriki.orca.entity;
import java.util.UUID;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.IAngerable;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.monster.AbstractSkeletonEntity;
import net.minecraft.entity.monster.CreeperEntity;
import net.minecraft.entity.monster.DrownedEntity;
import net.minecraft.entity.monster.ElderGuardianEntity;
import net.minecraft.entity.monster.GhastEntity;
import net.minecraft.entity.monster.GuardianEntity;
import net.minecraft.entity.monster.HoglinEntity;
import net.minecraft.entity.monster.HuskEntity;
import net.minecraft.entity.monster.SkeletonEntity;
import net.minecraft.entity.monster.StrayEntity;
import net.minecraft.entity.monster.WitherSkeletonEntity;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.entity.monster.ZombifiedPiglinEntity;
import net.minecraft.entity.monster.piglin.PiglinBruteEntity;
import net.minecraft.entity.passive.FoxEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.RangedInteger;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.TickRangeConverter;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class KrashEntity extends TameableEntity implements IAngerable {
private static final DataParameter<Integer> field_234232_bz_ = EntityDataManager.createKey(KrashEntity.class, DataSerializers.VARINT);
public static final Predicate<LivingEntity> TARGET_ENTITIES = (p_213440_0_) -> {
EntityType<?> entitytype = p_213440_0_.getType();
return entitytype == EntityType.FOX || entitytype == EntityType.ZOMBIE || entitytype == EntityType.GUARDIAN;
};
private static final RangedInteger field_234230_bG_ = TickRangeConverter.func_233037_a_(20, 39);
private UUID field_234231_bH_;
public static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(Items.CARROT);
public KrashEntity(EntityType<? extends TameableEntity> type, World worldIn) {
super(type, worldIn);
this.setTamed(false);
}
protected void registerGoals() {
super.registerGoals();
this.goalSelector.addGoal(1, new SwimGoal(this));
this.goalSelector.addGoal(2, new SitGoal(this));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, TEMPTATION_ITEMS, false));
this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4F));
this.goalSelector.addGoal(5, new MeleeAttackGoal(this, 1.0D, true));
this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0D, 10.0F, 2.0F, false));
this.goalSelector.addGoal(7, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(8, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
this.goalSelector.addGoal(9, new OcelotAttackGoal(this));
this.goalSelector.addGoal(10, new LookAtGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.addGoal(10, new LookRandomlyGoal(this));
this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
this.targetSelector.addGoal(3, (new HurtByTargetGoal(this)).setCallsForHelp());
this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, 10, true, false, this::func_233680_b_));
this.targetSelector.addGoal(5, new NonTamedTargetGoal<>(this, FoxEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, ZombieEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, HuskEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, SkeletonEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, StrayEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, WitherSkeletonEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, GuardianEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, ElderGuardianEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, PiglinBruteEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, ZombifiedPiglinEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, HoglinEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(6, new NonTamedTargetGoal<>(this, DrownedEntity.class, false, TARGET_ENTITIES));
this.targetSelector.addGoal(7, new NearestAttackableTargetGoal<>(this, AbstractSkeletonEntity.class, false));
this.targetSelector.addGoal(8, new ResetAngerGoal<>(this, true));
}
public static AttributeModifierMap.MutableAttribute func_234233_eS_() {
return MobEntity.func_233666_p_().func_233815_a_(Attributes.field_233821_d_, (double) 0.3F).func_233815_a_(Attributes.field_233818_a_, 8.0D).func_233815_a_(Attributes.field_233823_f_, 2.0D);
}
protected void playStepSound(BlockPos pos, BlockState blockIn) {
this.playSound(SoundEvents.ENTITY_RABBIT_JUMP, 0.15F, 1.0F);
}
protected SoundEvent getAmbientSound() {
if (this.func_233678_J__()) {
return SoundEvents.ENTITY_WOLF_GROWL;
} else if (this.rand.nextInt(3) == 0) {
return this.isTamed() && this.getHealth() < 10.0F ? SoundEvents.ENTITY_WOLF_WHINE : SoundEvents.ENTITY_WOLF_PANT;
} else {
return SoundEvents.ENTITY_RABBIT_AMBIENT;
}
}
protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
return SoundEvents.ENTITY_RABBIT_HURT;
}
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_RABBIT_DEATH;
}
protected float getSoundVolume() {
return 0.4F;
}
public int getVerticalFaceSpeed() {
return this.func_233684_eK_() ? 20 : super.getVerticalFaceSpeed();
}
public boolean attackEntityFrom(DamageSource source, float amount) {
if (this.isInvulnerableTo(source)) {
return false;
} else {
Entity entity = source.getTrueSource();
this.func_233687_w_(false);
if (entity != null && !(entity instanceof PlayerEntity) && !(entity instanceof AbstractArrowEntity)) {
amount = (amount + 1.0F) / 2.0F;
}
return super.attackEntityFrom(source, amount);
}
}
public boolean attackEntityAsMob(Entity entityIn) {
boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float) ((int) this.func_233637_b_(Attributes.field_233823_f_)));
if (flag) {
this.applyEnchantments(this, entityIn);
}
return flag;
}
public void setTamed(boolean tamed) {
super.setTamed(tamed);
if (tamed) {
this.getAttribute(Attributes.field_233818_a_).setBaseValue(200.0D);
this.setHealth(200.0F);
} else {
this.getAttribute(Attributes.field_233818_a_).setBaseValue(8.0D);
}
this.getAttribute(Attributes.field_233823_f_).setBaseValue(4.0D);
}
public ActionResultType func_230254_b_(PlayerEntity p_230254_1_, Hand p_230254_2_) {
ItemStack itemstack = p_230254_1_.getHeldItem(p_230254_2_);
Item item = itemstack.getItem();
if (this.world.isRemote) {
boolean flag = this.isOwner(p_230254_1_) || this.isTamed() || item == Items.CARROT && !this.isTamed() && !this.func_233678_J__();
return flag ? ActionResultType.CONSUME : ActionResultType.PASS;
} else {
if (this.isTamed()) {
if (this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
if (!p_230254_1_.abilities.isCreativeMode) {
itemstack.shrink(1);
}
this.heal((float) item.getFood().getHealing());
return ActionResultType.SUCCESS;
}
} else if (item == Items.CARROT && !this.func_233678_J__()) {
if (!p_230254_1_.abilities.isCreativeMode) {
itemstack.shrink(1);
}
if (this.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, p_230254_1_)) {
this.setTamedBy(p_230254_1_);
this.navigator.clearPath();
this.setAttackTarget((LivingEntity) null);
this.func_233687_w_(true);
this.world.setEntityState(this, (byte) 7);
} else {
this.world.setEntityState(this, (byte) 6);
}
return ActionResultType.SUCCESS;
}
return super.func_230254_b_(p_230254_1_, p_230254_2_);
}
}
public int getMaxSpawnedInChunk() {
return 8;
}
public int func_230256_F__() {
return this.dataManager.get(field_234232_bz_);
}
public void func_230260_a__(int p_230260_1_) {
this.dataManager.set(field_234232_bz_, p_230260_1_);
}
public void func_230258_H__() {
this.func_230260_a__(field_234230_bG_.func_233018_a_(this.rand));
}
@Nullable
public UUID func_230257_G__() {
return this.field_234231_bH_;
}
public void func_230259_a_(@Nullable UUID p_230259_1_) {
this.field_234231_bH_ = p_230259_1_;
}
public KrashEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
return null;
}
public boolean shouldAttackEntity(LivingEntity target, LivingEntity owner) {
if (!(target instanceof CreeperEntity) && !(target instanceof GhastEntity)) {
if (target instanceof KrashEntity) {
KrashEntity krashentity = (KrashEntity) target;
return !krashentity.isTamed() || krashentity.getOwner() != owner;
} else if (target instanceof PlayerEntity && owner instanceof PlayerEntity && !((PlayerEntity) owner).canAttackPlayer((PlayerEntity) target)) {
return false;
} else if (target instanceof AbstractHorseEntity && ((AbstractHorseEntity) target).isTame()) {
return false;
} else {
return !(target instanceof TameableEntity) || !((TameableEntity) target).isTamed();
}
} else {
return false;
}
}
public boolean canBeLeashedTo(PlayerEntity player) {
return !this.func_233678_J__() && super.canBeLeashedTo(player);
}
@OnlyIn(Dist.CLIENT)
public Vector3d func_241205_ce_() {
return new Vector3d(0.0D, (double) (0.6F * this.getEyeHeight()), (double) (this.getWidth() * 0.4F));
}
}