本帖最后由 和煦樱 于 2020-7-22 18:11 编辑
复制代码
生成出来时还是会射箭,但重启服务器或者单人游戏退出游戏重进后 它就失去了远程攻击AI,有什么好的方法解决吗..
- public class EntityGaiaCentaur extends EntityMob implements IRangedAttackMob {
- private EntityAIArrowAttack AIArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
- private EntityAIAttackOnCollide AIAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
-
- public EntityGaiaCentaur(World par1World) {
- super(par1World);
- stepHeight = 1.0F;
- //浮在水上的AI
- tasks.addTask(2, new EntityAISwimming(this));
- //在周围漫步走动的AI
- tasks.addTask(2, new EntityAIWander(this, 0.5D));
- //看玩家的AI
- tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
- tasks.addTask(3, new EntityAILookIdle(this));
- //会攻击周围玩家的AI
- targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
- if(par1World != null && !par1World.isRemote) {
- setCombatTask();
- }
- }
-
- protected void applyEntityAttributes() {
- super.applyEntityAttributes();
- this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(35.0D);
- this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35D);
- }
-
- //射箭代码优化
- public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) {
- EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.ordinal() * 4));
- entityarrow.setDamage((double)(par2 * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.difficultySetting.ordinal() * 0.11F));
- entityarrow.setKnockbackStrength(1);
- playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
- worldObj.spawnEntityInWorld(entityarrow);
- }
- public boolean isAIEnabled() {
- return true;
- }
- protected String getLivingSound() {
- return "gaia:assist_say";
- }
- protected String getHurtSound() {
- return "gaia:assist_hurt";
- }
- protected String getDeathSound() {
- return "gaia:assist_death";
- }
- protected void playStepSound(int par1, int par2, int par3, int par4) {
- this.playSound("mob.pig.step", 0.15F, 1.0F);
- }
-
- public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1IEntityLivingData) {
- par1IEntityLivingData = super.onSpawnWithEgg(par1IEntityLivingData);
- setCurrentItemOrArmor(0, new ItemStack(Items.bow));
- return par1IEntityLivingData;
- }
-
- public void setCombatTask() {
- tasks.removeTask(AIAttackOnCollide);
- tasks.removeTask(AIArrowAttack);
- ItemStack MainWeapon = getHeldItem();
- if(MainWeapon != null && MainWeapon.getItem() == Items.bow) {
- tasks.addTask(1, AIArrowAttack);
- } else {
- tasks.addTask(1, AIAttackOnCollide);
- }
- }
-
- public void setCurrentItemOrArmor(int p_70062_1_, ItemStack MainWeapon) {
- super.setCurrentItemOrArmor(p_70062_1_, MainWeapon);
- if(!worldObj.isRemote && p_70062_1_ == 0) {
- setCombatTask();
- }
- }
- }
看不懂。。。。。。。。。
- public void readEntityFromNBT(NBTTagCompound p_70037_1_) {
- super.readEntityFromNBT(p_70037_1_);
- setCombatTask();
- }