[+/- Résolu]Faire lancer une boule de feu par une entité
-
Tout d’abord, je pense que la NPE est lancée parce qu’il n’y a pas de joueur aux environs.
Essaie comme cela, ça devrait marcher:
package com.flareheat.mineventure.entity.boss; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import net.minecraft.world.World; public class EntityVlad extends EntityMob { private short timerEntity; private int explosionStrength = 1; public EntityVlad(World world) { super(world); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } @Override public void attackEntity(Entity entity, float value) { if (this.timerEntity == 0) { double xPos = entity.posX - posX; double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); double zPos = entity.posZ - posZ; float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); EntityLargeFireball fireball = new EntityLargeFireball(worldObj, this, xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); fireball.posY = posY + (height / 2.0F) + 0.5D; fireball.field_92057_e = explosionStrength; worldObj.spawnEntityInWorld(fireball); } } protected void updateEntityActionState() { timerEntity++; if (timerEntity == 160) { timerEntity = 0; } } } -
… implements IRangedAttackMob //plutôt simple non ?Je dis ça, je dis rien

(Je te laisse mijoter un peu) -
toss, ça ne marcheras pas, car il semble que TheGamer9112 ne veux pas utiliser les AI (selon son code), or la méthode attackEntityWithRangedAttack(…) est appelée dans la classe EntityAIArrowAttack, il faudrait donc activer l’AI pour l’utiliser. De plus pour cela il faudrait faire une nouvelle classe d’AI pour les boules de feu, tu compliques vraiment les choses

-
AlphaSwittleTeam avec ton code le jeu ne crash pas mais les EntityVlad ne lance pas de boules de feus

Il faut peut être leur mettre une ai pour qu’il attaque le joueur car la il ne se dirige même pas vers moi -
D’accord, une seconde je corrige

Edit: après tests, il s’avère que le mob lance bien des boules de feu, il suffisait d’attendre

Je remets le code au cas où:
import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class EntityVlad extends EntityMob { private short timerEntity; private int explosionStrength = 1; public EntityVlad(World world) { super(world); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } @Override public void attackEntity(Entity entity, float value) { if (this.timerEntity == 0) { double xPos = entity.posX - posX; double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); double zPos = entity.posZ - posZ; float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); EntityLargeFireball fireball = new EntityLargeFireball(worldObj, this, xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); fireball.posY = posY + (height / 2.0F) + 0.5D; fireball.field_92057_e = explosionStrength; worldObj.spawnEntityInWorld(fireball); } } protected void updateEntityActionState() { super.updateEntityActionState(); timerEntity++; if (timerEntity == 50) { timerEntity = 0; } } } -
je vais manger je te dis si ça fonctionne des que je reviens.
-
Et moi entre temps je dois sortir, je verrais le sujet quand je reviendrais, sur ce bonne chance

-
Ok ça fonctionne perfect merci beaucoup de ton aide et j’ai une dernière question si jamais j’utilise cet entity:
package mrplaigon.psccraft.minesagasmod.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityGiantZombie; import net.minecraft.entity.monster.EntitySpider; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class EntityBalleGun extends EntityThrowable { public EntityBalleGun(World par1World) { super(par1World); } public EntityBalleGun(World par1World, EntityLivingBase par2EntityLivingBase) { super(par1World, par2EntityLivingBase); } public EntityBalleGun(World par1World, double par2, double par4, double par6) { super(par1World, par2, par4, par6); } @Override protected void onImpact(MovingObjectPosition par1MovingObjectPosition) { if (par1MovingObjectPosition.entityHit != null) { byte degat = 100; //par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), degat); /**if (!this.worldObj.isRemote) { worldObj.newExplosion(null, par1MovingObjectPosition.entityHit.posX, par1MovingObjectPosition.entityHit.posY, par1MovingObjectPosition.entityHit.posZ, 2.0F, false, true); }*/ //par1MovingObjectPosition.entityHit.setFire(10);//l'argument int de la méthode est la durée en seconde /**EntityLivingBase entitylivingbase = (EntityLivingBase) par1MovingObjectPosition.entityHit; entitylivingbase.addPotionEffect(new PotionEffect(Potion.poison.id, 6 * 20, 10));//2eme argument en int c'est la durée , 3ème argument c'est la puissance de l'effet*/ /** worldObj.addWeatherEffect(new EntityLightningBolt(Minecraft.getMinecraft().theWorld, par1MovingObjectPosition.entityHit.posX, par1MovingObjectPosition.entityHit.posY, par1MovingObjectPosition.entityHit.posZ)); par1MovingObjectPosition.entityHit.setDead();*/ /**EntityGiantZombie entityGiantZombie = new EntityGiantZombie (worldObj); entityGiantZombie.setLocationAndAngles(this.lastTickPosX, this.lastTickPosY, this.lastTickPosZ, this.rotationYaw, this.rotationPitch); worldObj.spawnEntityInWorld(entityGiantZombie);*/ /** A REVOIR SIU TU PEUX worldObj.setThunderStrength(10.5F);*/ } for (int i = 0; i < 1; ++i) { //this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); /**if (!this.worldObj.isRemote) { worldObj.newExplosion(null, par1MovingObjectPosition.blockX, par1MovingObjectPosition.blockY, par1MovingObjectPosition.blockZ, 3.5F, false, true); }*/ /**this.worldObj(par1MovingObjectPosition.blockX, par1MovingObjectPosition.blockY + 1, par1MovingObjectPosition.blockZ, Blocks.fire); this.worldObj.setBlock(par1MovingObjectPosition.blockX, par1MovingObjectPosition.blockY + 1, par1MovingObjectPosition.blockZ + 1, Blocks.fire);*/ } if (!this.worldObj.isRemote) { this.setDead(); } } }a la place de l’entityfireball ça peut fonctionner a ton avis??
-
Ok merci ça fonctionne très bien!!
ais je voulais mettre un peu plus de code dans cette entity donc j’ai essayé de faire qu’elle voit le joueur de moins loin voila le code que j’ai fait:package fr.minecraftforgefrance.mogame.common; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class EntityVlad extends EntityMob { private short timerEntity; private int explosionStrength = 1; private Entity currentTarget; public EntityVlad(World world) { super(world); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } @Override public void attackEntity(Entity entity, float value) { if (this.timerEntity == 0) { double xPos = entity.posX - posX; double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); double zPos = entity.posZ - posZ; float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); EntityLargeFireball fireball = new EntityLargeFireball(worldObj, this, xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); fireball.posY = posY + (height / 2.0F) + 0.5D; fireball.field_92057_e = explosionStrength; worldObj.spawnEntityInWorld(fireball); } } protected void updateEntityActionState() { super.updateEntityActionState(); timerEntity++; if (timerEntity == 50) { timerEntity = 0; float f = 1.0F; if (this.rand.nextFloat() < 0.02F) { EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, (double)f); if (entityplayer != null) { this.currentTarget = entityplayer; this.numTicksToChaseTarget = 10 + this.rand.nextInt(20); } else { this.randomYawVelocity = (this.rand.nextFloat() - 0.5F) * 20.0F; } } if (this.currentTarget != null) { this.faceEntity(this.currentTarget, 10.0F, (float)this.getVerticalFaceSpeed()); if (this.numTicksToChaseTarget– <= 0 || this.currentTarget.isDead || this.currentTarget.getDistanceSqToEntity(this) > (double)(f * f)) { this.currentTarget = null; } } else { if (this.rand.nextFloat() < 0.05F) { this.randomYawVelocity = (this.rand.nextFloat() - 0.5F) * 20.0F; } this.rotationYaw += this.randomYawVelocity; this.rotationPitch = this.defaultPitch; } } } }Mais le Problème c’est que j’ai l’impression que ça fonctionne pas

Encore une fois c’est surement du a mon manque de connaissance en modding. -
Je vais tester et te dire

Edit:
package com.flareheat.mineventure.entity.boss; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class EntityVlad extends EntityMob implements IBossDisplayData { private short timerEntity; private final int explosionStrength; private final double distance; public EntityVlad(World world) { super(world); timerEntity = 0; explosionStrength = 1; distance = 8D; } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D); getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } @Override public void attackEntity(Entity entity, float value) { if (timerEntity == 0) { final double xPos = entity.posX - posX; final double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); final double zPos = entity.posZ - posZ; final float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); final EntityLargeFireball fireball = new EntityLargeFireball(worldObj, this, xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); fireball.posY = posY + (height / 2.0F) + 0.5D; fireball.field_92057_e = explosionStrength; worldObj.spawnEntityInWorld(fireball); } } @Override protected void updateEntityActionState() { super.updateEntityActionState(); timerEntity++; if (timerEntity == 50) { timerEntity = 0; } } @Override public Entity findPlayerToAttack() { final EntityPlayer entityplayer = worldObj.getClosestVulnerablePlayerToEntity(this, distance); if (entityplayer != null) { return entityplayer; } else { return null; } } @Override public boolean attackEntityFrom(DamageSource damagesource, float f) { return super.attackEntityFrom(damagesource, f); } @Override protected boolean canDespawn() { return false; } @Override protected void updateArmSwingProgress() { super.updateArmSwingProgress(); } } -
Ok je viens de tester ça fonctionne très bien mais le problème c’est que une fois qu’il nous a vu il ne nous lâche plus…
Et je sais pas comment faire qu’il nous lâche plus tôt. -
je dis sa comme sa mais de base dans minecraft aucun mob te lache sauf si tu sors de son champ de vision donc a priori t’a juste a tracer et il te lachera
sinon faut réduire son champ de vision ( je ne sais pas comment sa marche par contre ) -
Essaye ça:
package com.flareheat.mineventure.entity.boss; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class EntityVlad extends EntityMob implements IBossDisplayData { private short timerEntity; private final int explosionStrength; private final double distance; public EntityVlad(World world) { super(world); timerEntity = 0; explosionStrength = 1; distance = 8D; } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0?D); getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } @Override public void attackEntity(Entity entity, float value) { if (timerEntity == 0) { final double xPos = entity.posX - posX; final double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); final double zPos = entity.posZ - posZ; final float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); final EntityLargeFireball fireball = new EntityLargeFireball(worldObj, this, xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); fireball.posY = posY + (height / 2.0F) + 0.5D; fireball.field_92057_e = explosionStrength; worldObj.spawnEntityInWorld(fireball); } } @Override protected void updateEntityActionState() { super.updateEntityActionState(); timerEntity++; if (timerEntity == 50) { timerEntity = 0; } } @Override public Entity findPlayerToAttack() { final EntityPlayer entityplayer = worldObj.getClosestVulnerablePlayerToEntity(this, distance); if (entityplayer != null && canEntityBeSeen(entityplayer)) { return entityplayer; } else { setTarget(null); return null; } } } -
Ok mais dsl je viens de comprendre mon erreur en fait ce que je voulais dire c’est qu’elle arrête de lancer des boules de feus mais il suffit de rajouter && canEntityBeSeen(entityplayer) dans la condition du timer.
-
donc ton problème est résolu ?
-
nana j’ai rien c’est bon ça fonctionne.
Je passe le sujet en résolu merci a tous!! -
EntityPlayer entityPlayer = EntityPlayer.thePlayer je crois que c’est ca
-
Je pense pas perso quand je n’ai pas d’argument entityplayer je met Minecraft.getMinecraft().thePlayer;
-
Dernier Probleme je voudrais faire lancer une entity de mon mod mais ca ne fonctionne pas.
package fr.minecraftforgefrance.mogame.common; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityLargeFireball; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class EntityNeige extends EntityMob { private short timerEntity; public EntityNeige(World world) { super(world); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); } @Override protected void updateEntityActionState() { super.updateEntityActionState(); timerEntity++; if (timerEntity == 50) { timerEntity = 0; } } @Override public void attackEntity(Entity entity, float value) { if ( timerEntity == 0) { final double xPos = entity.posX - posX; final double yPos = (entity.boundingBox.minY + (entity.height / 2.0F)) - (posY + (height / 2.0F)); final double zPos = entity.posZ - posZ; final float sqrt = MathHelper.sqrt_float(value) * 0.5F; worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) posX, (int) posY, (int) posZ, 0); EntityVladAmmo entityVladAmmo = new EntityVladAmmo(worldObj,xPos + (rand.nextGaussian() * sqrt), yPos, zPos + (rand.nextGaussian() * sqrt)); entityVladAmmo.posY = posY + (height / 2.0F) + 0.5D; worldObj.spawnEntityInWorld(entityVladAmmo); } } }et la classe de l’entity qui doit etre lance
package fr.minecraftforgefrance.mogame.common; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityBlaze; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.util.DamageSource; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class EntityVladAmmo extends EntityThrowable { public EntityVladAmmo(World par1World) { super(par1World); } public EntityVladAmmo(World par1World, EntityLivingBase par2EntityLivingBase) { super(par1World, par2EntityLivingBase); } public EntityVladAmmo(World par1World, double par2, double par4, double par6) { super(par1World, par2, par4, par6); } @Override protected void onImpact(MovingObjectPosition movingObjectPosition) { if (movingObjectPosition.entityHit != null) { byte damage = 1; movingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)damage); worldObj.newExplosion(null, movingObjectPosition.entityHit.posX, movingObjectPosition.entityHit.posY, movingObjectPosition.entityHit.posZ, 2.0F, true, true); } for (int i = 0; i < 8; ++i) { this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); } if (!this.worldObj.isRemote) { this.setDead(); } } } -
Ton entité a bien un rendu ? Ton entité est bien enregistré ?