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.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      J’aurai plutôt fait comme ça :

      public class TutoEventEmo
      {
          private BlockPos death; //Position joueur mort
          private ItemStack inventory[]; //Le tableau
      
          @SubscribeEvent
          public void whenDeath(LivingDeathEvent e)
          {
              if(e.entity instanceof EntityPlayer)
              {
                  EntityPlayer player = (EntityPlayer)e.entity;
                  death = player.getPosition();
      
      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
              }
          }
      
          @SubscribeEvent
          public void whenSpawn(Clone e)
          {
              if(e.wasDeath == true) //Si joueur est mort
              {
                  for(int i = 0; i <= 5; i++)
                  {
                      if(i == 5)
                      {
                          EntityPlayer player = e.entityPlayer;
                          World world = player.worldObj;
                          EntityScorpion scorpion = new EntityScorpion(world);
      
                          scorpion.setPosition(death.getX(), death.getY(), death.getZ());
                          world.spawnEntityInWorld(scorpion);
      
                          if(scorpion.isDead) //Si scorpion est mort
                          {
                              for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
                              {
                                  player.dropItem(inventory*, true, false); //Drop item du tableau au joueur
                              }
                          }
                      }
                  }
              }
          }
      }
      

      ça fonctionnera un peu mieux …
      Et la encore le code est perfectible, il faudrait mettre le tableau dans mob en question, sinon il va y avoir des problèmes.

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

        j’ ai modifier le code car j avait des erreur a BlockPos et dans le dropItem mais ça fonctionne toujours pas et le mob spawn sur le joueur seulement quand il respawn T_T j’ai une idée pour corriger le spawn du mob par contre il drop toujours pas mon tableau

        private ItemStack inventory[]; //Le tableau
        
        @SubscribeEvent
        public void whenDeath(LivingDeathEvent e)
        {
        if(e.entity instanceof EntityPlayer)
        {
        EntityPlayer player = (EntityPlayer)e.entity;
        
        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.clearInventory(null, -1); //Clear inventaire tout les item ingnore les metadata
        }
        }
        
        @SubscribeEvent
        public void whenSpawn(Clone e)
        {
        if(e.wasDeath == true) //Si joueur est mort
        {
        for(int i = 0; i <= 5; i++)
        {
        if(i == 5)
        {
        EntityPlayer player = e.entityPlayer;
        World world = player.worldObj;
        //spawn entityReaper
        EntityReaper var2 = new EntityReaper(e.entityLiving.worldObj);
        var2.setLocationAndAngles(e.entityLiving.posX, e.entityLiving.posY, e.entityLiving.posZ, e.entityLiving.rotationYaw, e.entityLiving.rotationPitch);
        e.entityLiving.worldObj.spawnEntityInWorld(var2);
        
        if(var2.isDead) //Si scorpion est mort
        {
        for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
        {
        player.entityDropItem(inventory*, 0); //Drop item du tableau au joueur
        }
        }
        }
        }
        }
        }
        }
        

        et quand j’utilise le DropItem() il me dit que les arguments son DropItem(Item, int) et considère que le tableau n’est pas un item

        “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
        • EmotionFoxE Hors-ligne
          EmotionFox
          dernière édition par

          Ah oui effectivement t’es pas en 1.8 je viens de remarquer seulement ça maintenant, du coup je sais pas désolé mon code est fonctionnelle chez moi mais si on a pas la même version tu m’étonne, mais l’important est quand même là, tu connais les bases et sais comment tu doit faire. Essaye de te renseigner sur ce qui pose problème genre tuto, doc etc…

          Ps: Si le monstre pop au joueur c’est parce que t’a pas gardé la pos lors de sa mort et que t’a pas changé les positions pour le spawn du monstre ,)

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

            Pour le mob j ai déjà solutionné le problème mais pour le tableau ça marche pas T_T je comprend pas a quoi sert la float dans entityDropItem après le itemStack ;S

            pour la fonction DropItem(Item,int) je sait que c’est Item, Nombre

            je pense pas a une metadata en Float ce serait plutôt étrange ;S
            peut être un probabilité de loot j’avoue que avec tout ces field ça me rend dingue U_u

              if(var2.isDead) //Si Reaper est mort
                               {
                                System.out.println("lel");
                                   for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
                                   {
                                       player.entityDropItem(inventory*, 110); //Drop item du tableau au joueur
                                       System.out.println(inventory*);
                                   }
                               }
            

            ne s’execute carrément pas a la mort du mob je creuse un peu on est pret du but

            “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
            • SCAREXS Hors-ligne
              SCAREX
              dernière édition par

              Le float est un offset sur l’axe Y, met celui-ci à 0 çà devrait fonctionner.

              Site web contenant mes scripts : http://SCAREXgaming.github.io

              Pas de demandes de support par MP ni par skype SVP.
              Je n'accepte sur skype que l…

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

                if(var2.isDead) //Si Reaper est mort
                {
                System.out.println("lel");
                for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
                {
                player.entityDropItem(inventory*, 110); //Drop item du tableau au joueur
                System.out.println(inventory*);
                }
                }
                

                ce code a l’air de ne pas s’executer la mort du Mob :S

                “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
                • SCAREXS Hors-ligne
                  SCAREX
                  dernière édition par

                  Explique moi clairement dans l’ordre des choses ce que tu veux qu’il se passe car je comprends pas trop, voici comment je le comprends :

                  1. Le joueur meurt
                  2. Une nouvelle entité est créée
                  3. L’inventaire du joueur est transféré dans celui du mob

                  Site web contenant mes scripts : http://SCAREXgaming.github.io

                  Pas de demandes de support par MP ni par skype SVP.
                  Je n'accepte sur skype que l…

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

                    Il a était clair au début je trouve :

                    1. Quand le joueur meurt un monstre apparait sur sa dépouille
                    2. Quand le joueur respawn et tue le monstre il récupère tout sont inventaire précédemment perdue et non dropé au sol (pour donner un effet de, c’est le monstre qui a tout mangé)

                    Essaye

                    if(var2.getHealth() == 0) //Si vie monstre = 0
                    

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

                      j’y avait pas pensez au gethealth j’essaye de-suite

                      ca fonctionne pas je me demande si le if was dead y est pas pour quelque choses puisque le joueur respawn la condition est rompue le joueur est vivant donc pas moyen d’exécuter le code en desous
                      Edit: j’ai fait des test et a la condition if(var2.isdead ou var2.getHealth == 0) la condition ne s exécute jamais même si je la déplace en dehors du if wasDead je vais essaye de réécrire différemment le truc pour voir si ça marche

                             if(e.wasDeath == true) //Si joueur est mort
                             {
                                 for(int i = 0; i <= 5; i++)
                                 {
                                     if(i == 5)
                                     {
                                         EntityPlayer player = e.entityPlayer;
                                         World world = player.worldObj;
                      
                      EntityReaper var2 = new EntityReaper(e.entityLiving.worldObj);
                             var2.setLocationAndAngles(e.entityLiving.posX, e.entityLiving.posY, e.entityLiving.posZ, e.entityLiving.rotationYaw, e.entityLiving.rotationPitch);
                             e.entityLiving.worldObj.spawnEntityInWorld(var2);
                      
                                         if(var2.getHealth() == 0) //Si Reaper est mort
                                         {
                                          System.out.println("lel");
                                             for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
                                             {
                                                 player.entityDropItem(inventory*, 110); //Drop item du tableau au joueur
                                                 System.out.println(inventory*);
                                             }
                                         }
                                     }
                                 }
                             }
                      

                      “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

                        j ai essayer ça toujours rien

                        if(e.entityLiving instanceof EntityReaper) //Si Reaper est mort
                        {
                        if(!e.entityLiving.worldObj.isRemote){
                        System.out.println("lel");
                        for(int j = 0; j < inventory.length; j++) //Selon taille du tableau
                        {
                        player.entityDropItem(inventory*, 0); //Drop item du tableau au joueur
                        System.out.println(inventory*);
                        }
                        }}
                        

                        je pense que le Clone event ne va pas avec T_T et si je le met dans un LivingDeadEvent j ai un cannot cast EntityReaper to EntityPlayer

                        “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
                        • EmotionFoxE Hors-ligne
                          EmotionFox
                          dernière édition par

                          En faite je me rend compte du probléme, dans le “LivingDeathEvent” en dehors de :

                          if(e.entity instanceof EntityPlayer}
                          

                          Tape une nouvelle condition :

                          if(e.entity instanceof EntityReaper)
                          {
                          if(var2.isDead)
                          {}
                          

                          Et tout le reste à l’intérieur en oubliant pas de déplacer

                          private EntityReaper var2
                          

                          Tout en haut puis de le définir au final à sont endroit initial dans la condition if(e.entity instanceof EntityReaper) :

                          var2 = new EntityReaper(e.entityLiving.worldObj);
                          

                          1 réponse Dernière réponse Répondre Citer 0
                          • 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
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB