和煦樱
本帖最后由 和煦樱 于 2020-7-22 18:11 编辑

生成出来时还是会射箭,但重启服务器或者单人游戏退出游戏重进后 它就失去了远程攻击AI,有什么好的方法解决吗..
  1. public class EntityGaiaCentaur extends EntityMob implements IRangedAttackMob {

  2.         private EntityAIArrowAttack AIArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
  3.         private EntityAIAttackOnCollide AIAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
  4.         
  5.         public EntityGaiaCentaur(World par1World) {
  6.                 super(par1World);
  7.                 stepHeight = 1.0F;
  8.                 //浮在水上的AI
  9.                 tasks.addTask(2, new EntityAISwimming(this));
  10.                 //在周围漫步走动的AI
  11.                 tasks.addTask(2, new EntityAIWander(this, 0.5D));
  12.                 //看玩家的AI
  13.                 tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  14.                 tasks.addTask(3, new EntityAILookIdle(this));
  15.                 //会攻击周围玩家的AI
  16.                 targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
  17.             if(par1World != null && !par1World.isRemote) {
  18.                     setCombatTask();
  19.             }
  20.         }
  21.         
  22.         protected void applyEntityAttributes() {
  23.                 super.applyEntityAttributes();
  24.                 this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(35.0D);
  25.                 this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35D);
  26.         }
  27.         
  28.         //射箭代码优化
  29.         public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) {
  30.                 EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.ordinal() * 4));
  31.                 entityarrow.setDamage((double)(par2 * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.difficultySetting.ordinal() * 0.11F));
  32.                 entityarrow.setKnockbackStrength(1);
  33.                 playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
  34.                 worldObj.spawnEntityInWorld(entityarrow);
  35.         }

  36.         public boolean isAIEnabled() {
  37.                 return true;
  38.         }

  39.         protected String getLivingSound() {
  40.                 return "gaia:assist_say";
  41.         }

  42.         protected String getHurtSound() {
  43.                 return "gaia:assist_hurt";
  44.         }

  45.         protected String getDeathSound() {
  46.                 return "gaia:assist_death";
  47.         }

  48.         protected void playStepSound(int par1, int par2, int par3, int par4) {
  49.                 this.playSound("mob.pig.step", 0.15F, 1.0F);
  50.         }
  51.         
  52.         public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1IEntityLivingData) {
  53.                 par1IEntityLivingData = super.onSpawnWithEgg(par1IEntityLivingData);
  54.                 setCurrentItemOrArmor(0, new ItemStack(Items.bow));
  55.                 return par1IEntityLivingData;
  56.         }

  57.         
  58.         public void setCombatTask() {
  59.                 tasks.removeTask(AIAttackOnCollide);
  60.                 tasks.removeTask(AIArrowAttack);
  61.             ItemStack MainWeapon = getHeldItem();
  62.             if(MainWeapon != null && MainWeapon.getItem() == Items.bow) {
  63.                     tasks.addTask(1, AIArrowAttack);
  64.             } else {
  65.                     tasks.addTask(1, AIAttackOnCollide);
  66.             }
  67.         }
  68.         
  69.         public void setCurrentItemOrArmor(int p_70062_1_, ItemStack MainWeapon) {
  70.             super.setCurrentItemOrArmor(p_70062_1_, MainWeapon);
  71.             if(!worldObj.isRemote && p_70062_1_ == 0) {
  72.                     setCombatTask();
  73.             }
  74.         }

  75. }
复制代码



寒霜夜影
看不懂。。。。。。。。。

和煦樱
  1.         public void readEntityFromNBT(NBTTagCompound p_70037_1_) {
  2.                 super.readEntityFromNBT(p_70037_1_);
  3.             setCombatTask();
  4.         }
复制代码

第一页 上一页 下一页 最后一页