MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Mob qui tire comme un pied

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    5 Messages 2 Publieurs 808 Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • FolganskyF Hors-ligne
      Folgansky Correcteurs
      dernière édition par

      Plop les gens, aujourd’hui je me disais que j’aurais pu me faire un p’tit gars qui tire comme un skeleton.

      Mon soucis c’est qu’il tire “bien” mais mal. Il tire toujours dans la même direction et pas la mienne, toujours vers le même point.

      Voici ma classe actuelle:

      package fr.powergame.modpg2.common;
      
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.IRangedAttackMob;
      import net.minecraft.entity.SharedMonsterAttributes;
      import net.minecraft.entity.ai.EntityAIArrowAttack;
      import net.minecraft.entity.ai.EntityAIAttackOnCollide;
      import net.minecraft.entity.ai.EntityAIHurtByTarget;
      import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
      import net.minecraft.entity.monster.EntityMob;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.item.EnumAction;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.world.World;
      
      public class EntityMobGangster3 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);
           private static final ItemStack defaultHeldItem;
      
          public EntityMobGangster3(World world)
          {
              super(world);
              this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
              this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
              if (world != null && !world.isRemote)
              {
                  this.setCombatTask();
              }
          }
      
          protected int getExperiencePoints(EntityPlayer p_70693_1_)
          {
              return this.experienceValue = 0;
          }
      
          public void applyEntityAttributes()
          {
              super.applyEntityAttributes();
              this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(60D);
              this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(18D);
              this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.5D);
              this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
          }
      
          protected void entityInit()
          {
              super.entityInit();
              this.dataWatcher.addObject(13, new Byte((byte)0));
          }
      
          public ItemStack getHeldItem()
          {
              return defaultHeldItem;
          }
      
          public boolean isAIEnabled()
          {
              return true;
          }
      
          protected String getHurtSound()
          {
              return "mob.skeleton.hurt";
          }
      
          protected String getDeathSound()
          {
              return "mob.skeleton.death";
          }
      
          public void setCombatTask()
          {
              this.tasks.removeTask(this.aiAttackOnCollide);
              this.tasks.removeTask(this.aiArrowAttack);
              ItemStack itemstack = this.getHeldItem();
      
              if (itemstack != null && itemstack.getItem() == ModPg2.itemSPR)
              {
                  this.tasks.addTask(4, this.aiArrowAttack);
              }
              else
              {
                  this.tasks.addTask(4, this.aiAttackOnCollide);
              }
          }
      
          @Override
          public void attackEntityWithRangedAttack(EntityLivingBase entity, float f)
          {
              EntityBulletSPR entityBulletSPR = new EntityBulletSPR(this.worldObj, this);
              this.worldObj.playSoundAtEntity(entity, "modPg2:thomson", 0.8F, 0.5F);
              this.worldObj.spawnEntityInWorld(entityBulletSPR);
      //        System.out.println(entity);
      //        System.out.println(this);
          }
      
          static
          {
              defaultHeldItem = new ItemStack(ModPg2.itemSPR, 1);
          }
      
          public void readEntityFromNBT(NBTTagCompound nbt)
          {
              super.readEntityFromNBT(nbt);
              this.setCombatTask();
          }
      
          public void writeEntityToNBT(NBTTagCompound nbt)
          {
              super.writeEntityToNBT(nbt);
          }
      }
      

      Ah et aussi faire que le mob “Aim” quand il souhaite tirer.

      1 réponse Dernière réponse Répondre Citer 0
      • AymericRedA Hors-ligne
        AymericRed
        dernière édition par

        EntityBulletSPR entityBulletSPR = new EntityBulletSPR(this.worldObj, this);
        this.worldObj.playSoundAtEntity(entity, "modPg2:thomson", 0.8F, 0.5F);
        this.worldObj.spawnEntityInWorld(entityBulletSPR);
        

        Tu ne dis à aucun moment à quel endroit (la direction) ta balle doit aller, regarde le attackEntityWithRangedAttack du skeleton, il y a bien plus de trucs donnés au constructeur de la flèche, et prends en exemple (je regarderais ce soir sinon).

        Si je vous ai aidé, n'oubliez pas d’être heureux, j'aiderai encore +

        AymericRed, moddeur expérimenté qui aide sur ce forum et qui peut accepter de faire un mod Forge rémunéré de temps en temps.

        Mes tutos : Table de craft, plugin NEI, plugin JEI, modifier l'overlay
        Je suis un membre apprécié et joueur, j'ai déjà obtenu 6 points de réputation.

        1 réponse Dernière réponse Répondre Citer 0
        • FolganskyF Hors-ligne
          Folgansky Correcteurs
          dernière édition par

          Ouais je me suis dis ça.
          du coup:

          @Override
              public void attackEntityWithRangedAttack(EntityLivingBase entity, float f)
              {
                  EntityBulletSPR entityBulletSPR = new EntityBulletSPR(this.worldObj, this, entity, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); // Ici, il me fait une belle erreur pour le constructeur du projectile
                  this.worldObj.playSoundAtEntity(entity, "modPg2:thomson", 0.8F, 0.5F);
                  this.worldObj.spawnEntityInWorld(entityBulletSPR);
              }
          

          Le soucis c’est qu’il me demande un constructeur pour mon EntityBulletSPR (le projectile donc) et j’arrive à rien en suivant les conseils d’Eclipse.
          La classe du projectile:

          package fr.powergame.modpg2.common;
          
          import net.minecraft.entity.EntityLivingBase;
          import net.minecraft.entity.projectile.EntityThrowable;
          import net.minecraft.util.DamageSource;
          import net.minecraft.util.EntityDamageSourceIndirect;
          import net.minecraft.util.MathHelper;
          import net.minecraft.util.MovingObjectPosition;
          import net.minecraft.world.World;
          
          public class EntityBulletSPR extends EntityThrowable
          {
              public float strength;
              public int ticksAlive;
              private EntityLivingBase thrower;
          
              public EntityBulletSPR(World worldIn)
              {
                  super(worldIn);
                  strength = 20F;
                  this.setSize(0.3F, 0.3F);
                  this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
              }
          
              public EntityBulletSPR(World worldIn, EntityLivingBase throwerIn)
              {
                  super(worldIn, throwerIn);
                  this.thrower = throwerIn;
                  strength = 20F;
                  this.setSize(0.3F, 0.3F);
                  this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
              }
          
              public EntityBulletSPR(World worldIn, double x, double y, double p_i1778_6_)
              {
                  super(worldIn, x, y, p_i1778_6_);
                  strength = 20F;
                  this.setSize(0.3F, 0.3F);
                  this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
              }
          
              public void setArrowHeading(double d, double d1, double d2, float spread, float speed)
              {
                  spread /= 2F;
                  float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
                  d /= f2;
                  d1 /= f2;
                  d2 /= f2;
                  d *= speed;
                  d1 *= speed;
                  d2 *= speed;
                  d += rand.nextGaussian() * spread * speed * 0.005D ;
                  d1 += rand.nextGaussian() * spread * speed * 0.005D ;
                  d2 += rand.nextGaussian() * spread * speed * 0.005D ;
                  this.motionX *= d;
                  this.motionY *= d1;
                  this.motionZ *= d2;
                  float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
                  prevRotationYaw = rotationYaw = (float) ((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
                  prevRotationPitch = rotationPitch = (float) ((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);    
              }
          
              @Override
              protected void onImpact(MovingObjectPosition mop)
              {
                  DamageSource spr = new EntityDamageSourceIndirect("SPR", this, this.thrower).setProjectile();
                  if(mop.entityHit != null)
                  {
                      float l = strength;
                      mop.entityHit.attackEntityFrom(spr, mop.entityHit instanceof EntityLivingBase /*|| mop.entityHit instanceof MonMob2*/ ? l /*+ 5*/: l);
                      setDead();
                  }
                  else
                  {
                      setDead();
                  }
              }
          
              public void onUpdate()
              {
                  if(ticksAlive++>200)
                  {
                      setDead();
                  }
                  super.onUpdate();
              }
          
              protected float getGravityVelocity()
              {
                  return 0.0F;
              }
          }
          
          1 réponse Dernière réponse Répondre Citer 0
          • AymericRedA Hors-ligne
            AymericRed
            dernière édition par

            Inspirés toi du/des constructeurs de EntityArrow, il change des trucs au niveau des valeurs qu’il donne à setThrowableHeading.
            (Dsl je peux pas te donner d’exemple tt de suite).

            Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk

            Si je vous ai aidé, n'oubliez pas d’être heureux, j'aiderai encore +

            AymericRed, moddeur expérimenté qui aide sur ce forum et qui peut accepter de faire un mod Forge rémunéré de temps en temps.

            Mes tutos : Table de craft, plugin NEI, plugin JEI, modifier l'overlay
            Je suis un membre apprécié et joueur, j'ai déjà obtenu 6 points de réputation.

            1 réponse Dernière réponse Répondre Citer 0
            • FolganskyF Hors-ligne
              Folgansky Correcteurs
              dernière édition par

              Ouki, en effet, du coup j’ai dû régler la hauteur de tir car les flèches et les balles n’ont pas la même trajectoire (pour la flèche il vise plus haut pour compenser l’action de la gravité sur la flèche)

              Mais du coup pour ce qui est donc de la trajectoire c’est bon, mon mob m’explose bien la carafe comme prévu. Merci ^^

              1 réponse Dernière réponse Répondre Citer 0
              • 1 / 1
              • Premier message
                Dernier message
              Design by Woryk
              ContactMentions Légales

              MINECRAFT FORGE FRANCE © 2024

              Powered by NodeBB