MFF

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

    Probleme avec un mob

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    38 Messages 5 Publieurs 7.4k 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.
    • EmotionFoxE Hors-ligne
      EmotionFox
      dernière édition par

      En faite je suis désolé l’erreur viens de “moi”, aucun besoin d’utiliser l’event du respawn juste (j’ai fais l’erreur en pensant que le spawn du mob devait ce faire au spawn du joueur) :

      public class EmoBaseEvent
      {
         private ItemStack inventory[] = {}; // Le tableau
      
         @SubscribeEvent
         public void whenDeath(LivingDeathEvent e)
         {
             EntityPlayer player = (EntityPlayer)e.entity;
             World world = player.worldObj;
             EntityScorpion scorpion = new EntityScorpion(world);
             BlockPos death = player.getPosition();
      
             if(e.entity instanceof EntityPlayer)
             {
                 inventory =  new ItemStack[player.inventory.getSizeInventory()];
      
                 for(int i = 0; i < player.inventory.getSizeInventory(); i++)
                 {
                     if(player.inventory.getStackInSlot(i) != null)
                     {
                         inventory* = player.inventory.getStackInSlot(i); // Ajouter tableau chaque item
                     }
                 }
      
                 player.inventory.clear(); // Clear inventaire
                 scorpion.setPosition(death.getX(), death.getY(), death.getZ());
                 world.spawnEntityInWorld(scorpion);
             }
      
             if(e.entity instanceof EntityReaper)
             {
                 for(int j = 0; j < inventory.length; j++) // Selon taille du tableau
                 {
                     player.dropItem(inventory*, true, false); // Drop item du tableau au joueur
                 }
             }
         }
      }
      

      Après si tu compte faire pop régulièrement des monstres “Reaper” il serait préférable d’ajouter une condition avec une boolean.

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002R Hors-ligne
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
        dernière édition par

        Il reste des problèmes avec ce code. Le tableau n’est pas vidé. Si plusieurs joueurs meurt, le contenu de l’un va effacer celui de l’autre.
        Il faudrait tout stocker dans l’entité, envoie-moi un zip ou un 7z de ton dossier src je vais regarder de mon côté demain.

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

          Mon Mod fait plus de 850 classe et je doit avouer que c est pas ultra bien ranger après si tu veut je peut cloner la partie du mob avec l évent citer au dessus je peut le mettre dans un mod plus petit histoire qu tu puisse travailler dessus

          Après si tu compte faire pop régulièrement des monstres “Reaper” il serait préférable d’ajouter une condition avec une boolean.

          pas besoin le mob sera unique et spawn uniquement a la place du joueur il n’auras pas de spawn naturel
          dans mon cas c est pour simuler les zombification du joueur a sa mort

          le code fonctionne toujours pas ;c
          :::

          –-- Minecraft Crash Report ----
          // Oops.
          
          Time: 10/06/15 00:16
          Description: Ticking memory connection
          
          java.lang.ClassCastException: virusz.mob.agressive.EntityReaper cannot be cast to net.minecraft.entity.player.EntityPlayer
          at virusz.event.StoreStuffEvent.whenDeath(StoreStuffEvent.java:17)
          at cpw.mods.fml.common.eventhandler.ASMEventHandler_16_StoreStuffEvent_whenDeath_LivingDeathEvent.invoke(.dynamic)
          at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
          at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
          at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:305)
          at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:982)
          at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:940)
          at net.minecraft.entity.monster.EntityMob.attackEntityFrom(EntityMob.java:84)
          at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1386)
          at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:881)
          at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51)
          at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69)
          at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
          at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
          at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
          at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
          at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
          at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
          at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
          
          A detailed walkthrough of the error, its code path and all known details is as follows:
          ---------------------------------------------------------------------------------------
          
          -- Head --
          Stacktrace:
          at virusz.event.StoreStuffEvent.whenDeath(StoreStuffEvent.java:17)
          at cpw.mods.fml.common.eventhandler.ASMEventHandler_16_StoreStuffEvent_whenDeath_LivingDeathEvent.invoke(.dynamic)
          at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
          at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
          at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:305)
          at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:982)
          at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:940)
          at net.minecraft.entity.monster.EntityMob.attackEntityFrom(EntityMob.java:84)
          at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1386)
          at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:881)
          at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51)
          at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69)
          at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
          
          -- Ticking connection --
          Details:
          Connection: net.minecraft.network.NetworkManager@16a446c0
          Stacktrace:
          at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
          at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
          at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
          at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
          at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
          at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
          
          -- System Details --
          Details:
          Minecraft Version: 1.7.10
          Operating System: Windows 7 (amd64) version 6.1
          Java Version: 1.8.0_45, Oracle Corporation
          Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
          Memory: 905937736 bytes (863 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
          JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
          AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
          IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
          FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active
          mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
          FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
          Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
          VirusZ{indev-0.1} [VirusZ] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
          Profiler Position: N/A (disabled)
          Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
          Player Count: 1 / 8; [EntityPlayerMP['Player469'/92, l='New World', x=587,50, y=1,00, z=358,74]]
          Type: Integrated Server (map_client.txt)
          Is Modded: Definitely; Client brand changed to 'fml,forge'
          

          :::

          “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

          1 réponse Dernière réponse Répondre Citer 0
          • jglrxavpokJ Hors-ligne
            jglrxavpok Modérateurs
            dernière édition par

            Tout au début de la méthode, vérifie si l’entité est bien un joueur:

            if(e.entity instanceof EntityPlayer)
            

            Sent from my GT-I9000 using Tapatalk 2

            Modérateur sur MFF. 
            Mon Github: http://github.com/jglrxavpok
            Mon compte Steam si vous voulez jouer à CS:GO ou TF2 avec moi: https://steamcommunity.com/id/jglrxavpok/

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

              toujours la même erreur quand je tue le mob

              “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

                @‘robin4002’:

                Il reste des problèmes avec ce code. Le tableau n’est pas vidé. Si plusieurs joueurs meurt, le contenu de l’un va effacer celui de l’autre.
                Il faudrait tout stocker dans l’entité, envoie-moi un zip ou un 7z de ton dossier src je vais regarder de mon côté demain.

                voici les sources amaigri du mod: http://puu.sh/ijs6i/f378add889.rar

                “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

                1 réponse Dernière réponse Répondre Citer 0
                • robin4002R Hors-ligne
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                  dernière édition par

                  J’adore le concept de ton mob, c’est juste excellent 😛
                  Le seule problème c’est si ton point de respawn est loin, le mob risque de disparaître.

                  Voila le code fonctionnel :

                  ​package virusz.mob.agressive;
                  
                  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.EntityAINearestAttackableTarget;
                  import net.minecraft.entity.ai.EntityAISwimming;
                  import net.minecraft.entity.ai.EntityAIWander;
                  import net.minecraft.entity.monster.EntityMob;
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.item.Item;
                  import net.minecraft.item.ItemStack;
                  import net.minecraft.nbt.NBTTagCompound;
                  import net.minecraft.nbt.NBTTagList;
                  import net.minecraft.world.World;
                  import virusz.animations.Reaper.AnimationHandlerReaper;
                  import virusz.api.MCACommonLibrary.IMCAnimatedEntity;
                  import virusz.api.MCACommonLibrary.animation.AnimationHandler;
                  
                  public class EntityReaper extends EntityMob implements IMCAnimatedEntity
                  {
                      protected AnimationHandler animHandler = new AnimationHandlerReaper(this);
                  
                      private ItemStack[] inventory = new ItemStack[40]; // le tableau de l'inventaire
                  
                      public EntityReaper(World world)
                      {
                          super(world);
                          this.tasks.addTask(0, new EntityAISwimming(this));
                          this.tasks.addTask(1, new EntityAIWander(this, 1D));
                          this.tasks.addTask(3, new EntityAILookIdle(this));
                          this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, true));
                  
                          this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, false));
                  
                          this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
                  
                          this.isImmuneToFire = true;
                      }
                  
                      @Override
                      protected void applyEntityAttributes()
                      {
                          super.applyEntityAttributes();
                          this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D);
                          this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.33000000417232513D);
                          this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0D);
                      }
                  
                      @Override
                      protected void entityInit()
                      {
                          super.entityInit();
                      }
                  
                      @Override
                      public AnimationHandler getAnimationHandler()
                      {
                          return animHandler;
                      }
                  
                      @Override
                      protected boolean isAIEnabled()
                      {
                          return true;
                      }
                  
                      @Override
                      public void onUpdate()
                      {
                          super.onUpdate();
                      }
                  
                      @Override
                      public void readEntityFromNBT(NBTTagCompound nbttagcompound) // lit l'inventaire depuis le tab nbt
                      {
                          super.readEntityFromNBT(nbttagcompound);
                          NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
                          this.inventory = new ItemStack[40];
                  
                          for(int i = 0; i < nbttaglist.tagCount(); ++i)
                          {
                              NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                              int j = nbttagcompound1.getByte("Slot") & 255;
                  
                              if(j >= 0 && j < this.inventory.length)
                              {
                                  this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                              }
                          }
                      }
                  
                      @Override
                      public void writeEntityToNBT(NBTTagCompound nbttagcompound) // enregistre l'inventaire dans le tag nbt
                      {
                          super.writeEntityToNBT(nbttagcompound);
                          NBTTagList nbttaglist = new NBTTagList();
                  
                          for(int i = 0; i < this.inventory.length; ++i)
                          {
                              if(this.inventory* != null)
                              {
                                  NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                                  nbttagcompound1.setByte("Slot", (byte)i);
                                  this.inventory*.writeToNBT(nbttagcompound1);
                                  nbttaglist.appendTag(nbttagcompound1);
                              }
                          }
                          nbttagcompound.setTag("Items", nbttaglist);
                      }
                  
                      @Override
                      protected void dropFewItems(boolean recentHit, int looting)
                      {
                          for(ItemStack stack : this.inventory) // parcourt tout l'inventaire
                          {
                              if(stack != null)
                              {
                                  this.entityDropItem(stack, 0.0F); // drop l'item
                              }
                          }
                      }
                  
                      public ItemStack[] getInventory()
                      {
                          return inventory;
                      }
                  }
                  

                  Et la classe d’event :

                  ​package virusz.event;
                  
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.item.ItemStack;
                  import net.minecraft.world.World;
                  import net.minecraftforge.event.entity.living.LivingDeathEvent;
                  import net.minecraftforge.event.entity.player.PlayerEvent.Clone;
                  import virusz.mob.agressive.EntityReaper;
                  import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                  
                  public class StoreStuffEvent
                  {
                  
                      @SubscribeEvent
                      public void whenDeath(LivingDeathEvent e)
                      {
                          if(e.entity instanceof EntityPlayer)
                          {
                              EntityPlayer player = (EntityPlayer)e.entity;
                              EntityReaper scorpion = new EntityReaper(player.worldObj);
                  
                              for(int i = 0; i < player.inventory.getSizeInventory(); i++)
                              {
                                  if(player.inventory.getStackInSlot(i) != null)
                                  {
                                      scorpion.getInventory()* = player.inventory.getStackInSlot(i); // enregistre l'inventaire dans le tableau du mob
                                  }
                              }
                              player.inventory.clearInventory(null, -1); // Clear inventaire
                              scorpion.setPosition(e.entity.posX, e.entity.posY, e.entity.posZ);
                              player.worldObj.spawnEntityInWorld(scorpion); // fait spawner le reaper
                          }
                      }
                  }
                  
                  1 réponse Dernière réponse Répondre Citer 0
                  • P Hors-ligne
                    PlagueZ
                    dernière édition par

                    Le seule problème c’est si ton point de respawn est loin, le mob risque de disparaître.

                    ça c’est un problème qui reste de l’ordre des limitation de minecraft :S
                    Mais ca fonctionne parfaitement si on oublie le despawn merci pour tout les mec

                    “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

                    1 réponse Dernière réponse Répondre Citer 0
                    • jglrxavpokJ Hors-ligne
                      jglrxavpok Modérateurs
                      dernière édition par

                      @‘VirusZ’:

                      Le seule problème c’est si ton point de respawn est loin, le mob risque de disparaître.

                      ça c’est un problème qui reste de l’ordre des limitation de minecraft :S
                      Mais ca fonctionne parfaitement si on oublie le despawn merci pour tout les mec

                      En théorie, tu peux éviter cela. Regarde dans le code des loups et des ocelots, je crois que c’est faisable 😉

                      Sent from my GT-I9000 using Tapatalk 2

                      Modérateur sur MFF. 
                      Mon Github: http://github.com/jglrxavpok
                      Mon compte Steam si vous voulez jouer à CS:GO ou TF2 avec moi: https://steamcommunity.com/id/jglrxavpok/

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

                        @‘jglrxavpok’:

                        @‘VirusZ’:

                        Le seule problème c’est si ton point de respawn est loin, le mob risque de disparaître.

                        ça c’est un problème qui reste de l’ordre des limitation de minecraft :S
                        Mais ca fonctionne parfaitement si on oublie le despawn merci pour tout les mec

                        En théorie, tu peux éviter cela. Regarde dans le code des loups et des ocelots, je crois que c’est faisable 😉

                        Sent from my GT-I9000 using Tapatalk 2

                        Yep c’est fesable comme ca ca devrait marcher mais j’ai pas tester

                        
                           private boolean persistenceRequired = true;
                        
                        @Override
                           protected void despawnEntity()
                           {
                               Result result = null;
                               if (this.persistenceRequired)
                               {
                                   this.entityAge = 0;
                               }
                               else if ((this.entityAge & 0x1F) == 0x1F && (result = ForgeEventFactory.canEntityDespawn(this)) != Result.DEFAULT)
                               {
                                   if (result == Result.DENY)
                                   {
                                       this.entityAge = 0;
                                   }
                               }
                               else
                               {
                                   EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, -1.0D);
                        
                                   if (entityplayer != null)
                                   {
                                       double d0 = entityplayer.posX - this.posX;
                                       double d1 = entityplayer.posY - this.posY;
                                       double d2 = entityplayer.posZ - this.posZ;
                                       double d3 = d0 * d0 + d1 * d1 + d2 * d2;
                        
                                       if (this.canDespawn() && d3 > 16384.0D)
                                       {
                                           this.entityAge = 0;
                                       }
                        
                                       if (this.entityAge > 600 && this.rand.nextInt(800) == 0 && d3 > 1024.0D)
                                       {
                                           this.entityAge = 0;
                                       }
                                       else if (d3 < 1024.0D)
                                       {
                                           this.entityAge = 0;
                                       }
                                   }
                               }
                           }
                        

                        la en théorie ça despawn pas du tout même si tu t éloigne de 40000000000 de block mais ça reste a confirmer le code est absolument pas propre c’est juste fait rapidement au cas ou quelqu’un regarde le topic et se demande si ya moyen d’empêcher de despawn 😃 libre a lui de le modifier 😜

                        “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R Hors-ligne
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                          dernière édition par

                          Ou alors tu ajoutes juste :

                          ​public boolean canDespawn()
                          {
                             return false;
                          }
                          

                          ça peut aussi le faire.

                          EDIT : en effet ça devrait fonctionner, les villageois ont ça.

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

                          MINECRAFT FORGE FRANCE © 2024

                          Powered by NodeBB