package com.example.examplemod;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public class Goblin extends EntityMob {
public static int ADD_DAMAGE = 15;
public Goblin(World world) {
super(world);
setSize(0.6F, 1.98F);
}
public Goblin(World world, double x, double y, double z) {
super(world);
setSize(0.6F, 1.98F);
setPositionAndUpdate(x, y, z);
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3.0D);
this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0D);
this.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(2.0D);
}
@Override
protected void initEntityAI() {
this.tasks.addTask(0, new EntityAISwimming(this));//Плавает ли моб
this.tasks.addTask(1, new EntityAIAttackMelee(this, 1.0D, false));//Атака ближнего боя
this.tasks.addTask(2, new EntityAIWander(this, 1.0D));//Моб путешествует
this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));//Смотрит на EntityPlayer(игрок)
this.tasks.addTask(4, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[]{EntityZombie.class, EntityPlayer.class}));
}
@Override
public boolean attackEntityAsMob(Entity entityIn) {
if (super.attackEntityAsMob(entityIn)) {//Проверка на атаку
if (entityIn instanceof EntityLivingBase) {//Если это моб
((EntityLivingBase) entityIn).attackEntityAsMob(this);//Делаем последним ударившим нашего моба
entityIn.attackEntityFrom(((EntityLivingBase) entityIn).getLastDamageSource(), rand.nextInt(ADD_DAMAGE));//Наносим доп. урон
}
return true;
} else {
return false;
}
}
@Override
public int getMaxSpawnedInChunk() {
return 25;
}
}