Résolu Empêcher mon mob de m'attaquer
-
Je m’explique, cela fait maintenant 2 jours que je cherche à résoudre ce problème: Mon mob nommé programmer est sensé attaquer tout les mobs nommés bug mais pas les joueurs. Après multiples essais, mon mob attaque bien les bug mais il m’attaque dès que je me met en survival .
Auriez vous la solution à ce problème? :package com.mod.test.entity; import java.util.List; import com.mod.test.init.ItemMod; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOpenDoor; import net.minecraft.entity.ai.EntityAIRestrictOpenDoor; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.pathfinding.PathEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.ForgeModContainer; public class EntityProgrammer extends EntityMob { public EntityProgrammer(World world) { super(world); this.canAttackClass(EntityBug.class); this.getNavigator().setBreakDoors(true); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 5.0D, true)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityBug.class, 40.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, IMob.mobSelector)); this.setSize(0.6F, 1.8F); this.captureDrops = true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } public void updateEntityActionState() { List list = worldObj.getEntitiesWithinAABB(EntityBug.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1).expand(16D, 4D, 16D)); for(int i = 0; i< list.size(); i++) { Entity entity = (Entity)list.get(i); if(!list.isEmpty()) { if(!(entity instanceof EntityPlayer)) { if(!(entity instanceof EntityProgrammer)) { this.setTarget(entity); } } } } super.updateEntityActionState(); } public Item getDropItem() { return null; } public void dropFewItems(boolean b, int looting) { this.dropItem(ItemMod.informatical_code, 3); if(this.isBurning()) { this.dropItem(Items.cooked_beef, 2); } else { this.dropItem(Items.beef, 2); } } }
Je vous en serais reconnaissant .
Merci d’avance! -
Bizarre, tu ne devrais pas être attaqué, met la fonction “updateEntityActionState” en commentaire, normalement les ai suffisent.
Fais ctrl+clic sur “EntityAIHurtByTarget” et regarde dans la classe “EntityAIHurtByTarget” si il n’y a pas un autre constructeur avec une classe en paramètre, si oui, utilise ce constructeur dans ton “new EntityAIHurtByTarget(…)”. -
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, IMob.mobSelector));
↓↓↓
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, new IEntitySelector() { public boolean isEntityApplicable(Entity entity) { return entity instanceof EntityBug; } }));
-
@‘AymericRed’:
Bizarre, tu ne devrais pas être attaqué, met la fonction “updateEntityActionState” en commentaire, normalement les ai suffisent.
Fais ctrl+clic sur “EntityAIHurtByTarget” et regarde dans la classe “EntityAIHurtByTarget” si il n’y a pas un autre constructeur avec une classe en paramètre, si oui, utilise ce constructeur dans ton “new EntityAIHurtByTarget(…)”.Si je fais ça, le programmer attaquera encore les bug?
-
Si tu met EntityBug.class comme argument oui.
-
@‘AymericRed’:
Si tu met EntityBug.class comme argument oui.
ok, j’essaie
-
Mon mob n’attaque plu le bug et il m’attaque encore…
-
@‘robin4002’:
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, IMob.mobSelector));
↓↓↓
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, new IEntitySelector() { public boolean isEntityApplicable(Entity entity) { return entity instanceof EntityBug; } }));
J’ai essayer avec mais le mob m’attaque encore et n’attaque pas les bug…
-
Petit rappel: maintenant la classe de mon mob est la suivante:
package com.mod.test.entity; import java.util.List; import com.mod.test.init.ItemMod; import net.minecraft.client.Minecraft; import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOpenDoor; import net.minecraft.entity.ai.EntityAIRestrictOpenDoor; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.pathfinding.PathEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.ForgeModContainer; public class EntityProgrammer extends EntityMob { public EntityProgrammer(World world) { super(world); this.canAttackClass(EntityBug.class); this.getNavigator().setBreakDoors(true); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 5.0D, true)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityBug.class, 40.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, new IEntitySelector() { public boolean isEntityApplicable(Entity entity) { return entity instanceof EntityBug; } })); this.setSize(0.6F, 1.8F); this.captureDrops = true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } /*public void updateEntityActionState() { List list = worldObj.getEntitiesWithinAABB(EntityBug.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1).expand(16D, 4D, 16D)); for(int i = 0; i< list.size(); i++) { Entity entity = (Entity)list.get(i); if(!list.isEmpty()) { if(!(entity instanceof EntityPlayer)) { if(!(entity instanceof EntityProgrammer)) { this.setTarget(entity); } } } } super.updateEntityActionState(); }*/ public Item getDropItem() { return null; } public void dropFewItems(boolean b, int looting) { this.dropItem(ItemMod.informatical_code, 3); if(this.isBurning()) { this.dropItem(Items.cooked_beef, 2); } else { this.dropItem(Items.beef, 2); } } } ```___J'essaye comme ceci: ```java package com.mod.test.entity; import java.util.List; import com.mod.test.init.ItemMod; import net.minecraft.client.Minecraft; import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOpenDoor; import net.minecraft.entity.ai.EntityAIRestrictOpenDoor; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.pathfinding.PathEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.ForgeModContainer; public class EntityProgrammer extends EntityMob { public EntityProgrammer(World world) { super(world); this.canAttackClass(EntityBug.class); this.getNavigator().setBreakDoors(true); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 5.0D, true)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityBug.class, 40.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, new IEntitySelector() { public boolean isEntityApplicable(Entity entity) { return entity instanceof EntityBug; } })); this.setSize(0.6F, 1.8F); this.captureDrops = true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } public void updateEntityActionState() { List list = worldObj.getEntitiesWithinAABB(EntityBug.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1).expand(16D, 4D, 16D)); for(int i = 0; i< list.size(); i++) { Entity entity = (Entity)list.get(i); if(!list.isEmpty()) { if(!(entity instanceof EntityPlayer)) { if(!(entity instanceof EntityProgrammer)) { this.setTarget(entity); } } } } //super.updateEntityActionState(); } public Item getDropItem() { return null; } public void dropFewItems(boolean b, int looting) { this.dropItem(ItemMod.informatical_code, 3); if(this.isBurning()) { this.dropItem(Items.cooked_beef, 2); } else { this.dropItem(Items.beef, 2); } } }
-
Attention aux multiples post.
“new EntityAIHurtByTarget(this, false)” ==> “new EntityAIHurtByTarget(this, false, EntityBug.class)”Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk
-
@‘minantcaft’:
J’essaye comme ceci:
package com.mod.test.entity; import java.util.List; import com.mod.test.init.ItemMod; import net.minecraft.client.Minecraft; import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOpenDoor; import net.minecraft.entity.ai.EntityAIRestrictOpenDoor; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.pathfinding.PathEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.ForgeModContainer; public class EntityProgrammer extends EntityMob { public EntityProgrammer(World world) { super(world); this.canAttackClass(EntityBug.class); this.getNavigator().setBreakDoors(true); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 5.0D, true)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityBug.class, 40.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBug.class, 0, true, false, new IEntitySelector() { public boolean isEntityApplicable(Entity entity) { return entity instanceof EntityBug; } })); this.setSize(0.6F, 1.8F); this.captureDrops = true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } public void updateEntityActionState() { List list = worldObj.getEntitiesWithinAABB(EntityBug.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1).expand(16D, 4D, 16D)); for(int i = 0; i< list.size(); i++) { Entity entity = (Entity)list.get(i); if(!list.isEmpty()) { if(!(entity instanceof EntityPlayer)) { if(!(entity instanceof EntityProgrammer)) { this.setTarget(entity); } } } } //super.updateEntityActionState(); } public Item getDropItem() { return null; } public void dropFewItems(boolean b, int looting) { this.dropItem(ItemMod.informatical_code, 3); if(this.isBurning()) { this.dropItem(Items.cooked_beef, 2); } else { this.dropItem(Items.beef, 2); } } }
Le mob ne bouge plus, il ne m’attaque plus mais il n’attaque pas non-plus le bug___@‘AymericRed’:
Attention aux multiples post.
“new EntityAIHurtByTarget(this, false)” ==> “new EntityAIHurtByTarget(this, false, EntityBug.class)”Envoyé de mon RAINBOW LITE 4G en utilisant Tapata
ok il me dit que ce constructeur n’existe pas…___Le BossMax2, tu n’aurais pas une idée?
-
Y’a quoi comme constructeurs disponibles ?
-
@‘SCAREX’:
Y’a quoi comme constructeurs disponibles ?
seulement la premier je crois
-
T’es en quelle version ? (Moi je l’ai)
Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk
-
1.7.10 d’après la balise de version.
-
Ah parce qu’on voit pas sur tapatalk.
Alors je ne vois pas d’où vient ton problème.Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk
-
@‘AymericRed’:
Ah parce qu’on voit pas sur tapatalk.
Alors je ne vois pas d’où vient ton problème.Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk
A vous n’avez vraiment pas une idée? car c un peu gênant… Merci quand même d’avoir répondu aussi vite!
-
Sinon tu peux toujours re-créer l’IA en faisant un copier-coller en modifiant ce que tu veux
-
@‘SCAREX’:
Sinon tu peux toujours re-créer l’IA en faisant un copier-coller en modifiant ce que tu veux
Oui mais je n’ai pas trouvé d’IA semblable dans les fichiers du jeu
-
Tu veux attaquer les entités comment ?