• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu [1.12.2] Textures random pour un mob

    1.12.x
    1.12.2
    2
    14
    299
    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.
    • LaNonne
      LaNonne dernière édition par

      Bonsoir;

      J’ai un problème avec mon entité.
      A chaque fois que je fait spawner mon entité, il y a des textures differentes, jusque ici OK
      Mais toutes mes entités prennent la texture de la dernière entitée que j’ai faite spawnée.

      Vidéo si pas clair: VIDEO YOUTUBE

      Je ne vais pas mettre toute la classe de l’entité car c’est inutile mais il y a ceci:

       public static ResourceLocation[] skins;
      
         public static int currentSkin; {
      
       
      
             Random rand = new Random();
      
       
      
             currentSkin = rand.nextInt(skins.length);}  
      

      Et voici la classe du rendu:

      package fr.hugo.hostile.renders;
      
      import fr.hugo.hostile.Reference;
      import fr.hugo.hostile.entity.EntityAssassin;
      import fr.hugo.hostile.models.ModelAssassin;
      import net.minecraft.client.model.ModelBiped;
      import net.minecraft.client.renderer.entity.RenderBiped;
      import net.minecraft.client.renderer.entity.RenderManager;
      import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
      import net.minecraft.entity.Entity;
      import net.minecraft.util.ResourceLocation;
      import net.minecraftforge.fml.relauncher.SideOnly;
      
      
      public class RenderAssassin extends RenderBiped
      
      {
      
      
      	public static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/assassin1.png");
      	public static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/assassin2.png");
      	public static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/assassin3.png");
      	public static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/assassin4.png");
      	public static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/assassin5.png");
      
      
      
      
      	public RenderAssassin(RenderManager renderManagerIn)
      
      	{
      
      		super(renderManagerIn, new ModelBiped(), 0.5F);
      
      		this.addLayer(new LayerHeldItem(this));
      
      	}
      
      
      
      	static
      
      	{
      
      		EntityAssassin.skins = (new ResourceLocation[]
      
      				{
      
      					new ResourceLocation(Reference.MOD_ID + ":textures/assassin1.png"), new ResourceLocation(Reference.MOD_ID + ":textures/assassin2.png"), new ResourceLocation(Reference.MOD_ID + ":textures/assassin3.png"), new ResourceLocation(Reference.MOD_ID + ":textures/assassin4.png"), new ResourceLocation(Reference.MOD_ID + ":textures/assassin5.png")
      
      				});
      
      	}
      
      
      
      	protected ResourceLocation getAssassinTexture(EntityAssassin assassin)
      
      	{
      
      		return EntityAssassin.skins[EntityAssassin.currentSkin];
      
      	}
      
      
      
      	protected ResourceLocation getEntityTexture(Entity entity)
      
      	{
      
      		return this.getAssassinTexture((EntityAssassin)entity);
      
      	}
      
      }
      

      Je n’arrive pas à faire en sorte que mes entités aient chacunes leurs propres textures.

      Merci de l’aide 🙂

      1 réponse Dernière réponse Répondre Citer 0
      • LaNonne
        LaNonne dernière édition par robin4002

        Merci!!

        J’ai enfin réussi. Désolé pour avoir un niveau minable @robin4002 😕
        Pour ceux qui veulent avoir des textures random pour leur mobs:

        A ajouter dans la classe Entité:

        private static final DataParameter<Integer> ASSASSIN_VARIANT = EntityDataManager.<Integer>createKey(EntityAssassin.class, DataSerializers.VARINT);
           
           
           public int getVariant()
           {
        	   
               return MathHelper.clamp(((Integer)this.dataManager.get(ASSASSIN_VARIANT)).intValue(), 0, 4);
           }
           
           public void setVariant(int p_191997_1_)
           {
               this.dataManager.set(ASSASSIN_VARIANT, Integer.valueOf(p_191997_1_));
           }
        
        
           protected void entityInit()
           {
               super.entityInit();
               this.dataManager.register(ASSASSIN_VARIANT, Integer.valueOf(0));
           }
        
        @Override
        
            public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
        
               {
        
            livingdata = super.onInitialSpawn(difficulty, livingdata);
            this.setVariant(this.rand.nextInt(5));
        
            this.setEquipmentBasedOnDifficulty(difficulty);
        
            return livingdata;
        
            }
        

        Et dans la classe du Rendu:

        package fr.hugo.hostile.renders;
        
        import fr.hugo.hostile.Reference;
        import fr.hugo.hostile.entity.EntityAssassin;
        import fr.hugo.hostile.models.ModelAssassin;
        import net.minecraft.client.model.ModelBiped;
        import net.minecraft.client.renderer.entity.RenderBiped;
        import net.minecraft.client.renderer.entity.RenderLiving;
        import net.minecraft.client.renderer.entity.RenderManager;
        import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
        import net.minecraft.entity.Entity;
        import net.minecraft.entity.passive.EntityOcelot;
        import net.minecraft.entity.passive.EntityParrot;
        import net.minecraft.util.ResourceLocation;
        import net.minecraftforge.fml.relauncher.SideOnly;
        
        
        public class RenderAssassin extends RenderLiving<EntityAssassin>
        
        {
        
        	public static final ResourceLocation[] ASSASSINS_TEXTURES = new ResourceLocation[] {new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin1.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin2.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin3.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin4.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin5.png")};
        
        
        	public RenderAssassin(RenderManager renderManagerIn)
        
        	{
        
        		super(renderManagerIn, new ModelBiped(), 0.5F);
        
        		this.addLayer(new LayerHeldItem(this));
        
        	}
        
        	
        	
        	protected ResourceLocation getEntityTexture(EntityAssassin entity)
            {
                return ASSASSINS_TEXTURES[entity.getVariant()];
            }
        	
        
        
        }
        

        Merci beaucoup!

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

          Salut,

          Une variable static n’aura qu’une valeur possible sur tout le programme. C’est pour ça qu’elle est accessible partout en utlisant NomDeClass.variable.
          Une variable non static est rattaché à l’instance la classe. Il peut donc avoir différentes valeurs possibles (une par instance) en revanche comme c’est rattaché à l’instance d’une classe il faut passer par l’instance pour y accéder.

          Donc c’est complètement inapproprié d’utiliser une variable static pour ce que tu veux faire et c’est pour cela qu’actuellement toutes tes entités se retrouve avec la même texture.
          Il te faut une variable non static, la fonction getAssassinTexture a en plus déjà l’instance de l’entité en argument. Tu as donc tout ce qu’il te faut.

          robin4002 1 réponse Dernière réponse Répondre Citer 0
          • LaNonne
            LaNonne dernière édition par

            Salut @robin4002 , merci de la réponse

            Alors c’est cette ligne qui foire

            public static int currentSkin; {
            

            S’il me faut une variable non static, dois-je supprimer le “static” ? Si oui, je l’ai deja fait et cela me fait des erreurs dans la classe Render, à ce niveau:

            protected ResourceLocation getAssassinTexture(EntityAssassin assassin)
            
            	{
            
            		return EntityAssassin.skins[EntityAssassin.currentSkin];
            
            	}
            
            
            

            Si ma suggestion est fausse, alors je ne vois pas par quoi changer :S

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

              La solution se trouve à la fin de mon message :

              @robin4002 a dit dans [1.12.2] Textures random pour un mob :

              la fonction getAssassinTexture a en plus déjà l’instance de l’entité en argument. Tu as donc tout ce qu’il te faut.

              1 réponse Dernière réponse Répondre Citer 0
              • LaNonne
                LaNonne dernière édition par

                J’ai essayer plein de trucs mais je ne vois pas comment faire la 😕

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

                  La réponse est pourtant si évidente …

                      protected ResourceLocation getAssassinTexture(EntityAssassin assassin)
                      {
                           return EntityAssassin.skins[assassin.currentSkin];
                      }
                  

                  Tu as l’instance de la classe directement en argument, sous le nom de assassin. Suffit donc de l’utiliser …

                  1 réponse Dernière réponse Répondre Citer 0
                  • LaNonne
                    LaNonne dernière édition par

                    bonsoir, pendant la journée j’ai changer pas mal le code.
                    Je me suis inspiré des ocelots et j’en suis arrivé à ça:

                    Dans la classe de l’entité:

                    private static final DataParameter<Integer> ASSASSIN_VARIANT = EntityDataManager.<Integer>createKey(EntityAssassin.class, DataSerializers.VARINT);
                       
                       public int getAssassinSkin()
                       {
                           return ((Integer)this.dataManager.get(ASSASSIN_VARIANT)).intValue();
                       }
                       
                       public void setAssassinSkin(int skinId)
                       {
                           this.dataManager.set(ASSASSIN_VARIANT, Integer.valueOf(skinId));
                       }
                       
                       protected void entityInit()
                       {
                           super.entityInit();
                           this.dataManager.register(ASSASSIN_VARIANT, Integer.valueOf(0));
                       }
                    

                    Et dans la classe du rendu:

                    package fr.hugo.hostile.renders;
                    
                    import fr.hugo.hostile.Reference;
                    import fr.hugo.hostile.entity.EntityAssassin;
                    import fr.hugo.hostile.models.ModelAssassin;
                    import net.minecraft.client.model.ModelBiped;
                    import net.minecraft.client.renderer.entity.RenderBiped;
                    import net.minecraft.client.renderer.entity.RenderManager;
                    import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
                    import net.minecraft.entity.Entity;
                    import net.minecraft.entity.passive.EntityOcelot;
                    import net.minecraft.util.ResourceLocation;
                    import net.minecraftforge.fml.relauncher.SideOnly;
                    
                    
                    public class RenderAssassin extends RenderBiped
                    
                    {
                    
                    
                    	public static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin1.png");
                    	public static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin2.png");
                    	public static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin3.png");
                    	public static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin4.png");
                    	public static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin5.png");
                    
                    
                    
                    
                    	public RenderAssassin(RenderManager renderManagerIn)
                    
                    	{
                    
                    		super(renderManagerIn, new ModelBiped(), 0.5F);
                    
                    		this.addLayer(new LayerHeldItem(this));
                    
                    	}
                    
                    
                    	protected ResourceLocation getAssassinTexture(EntityAssassin assassin)
                    
                    	{
                    
                    		switch (assassin.getAssassinSkin())
                            {
                                case 0:
                                default:
                                    return ASSASSIN1_TEXTURE;
                                case 1:
                                    return ASSASSIN2_TEXTURE;
                                case 2:
                                    return ASSASSIN3_TEXTURE;
                                case 3:
                                    return ASSASSIN4_TEXTURE;
                                case 4:
                                    return ASSASSIN5_TEXTURE;
                            }
                    
                    	}
                    
                    }
                    

                    Mais j’obtiens une entité avec ce skin :

                    text alternatif

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

                      C’est parce qu’il te manque cette fonction :

                      	protected ResourceLocation getEntityTexture(Entity entity)
                      	{
                      		return this.getAssassinTexture((EntityAssassin)entity);
                      	}
                      
                      1 réponse Dernière réponse Répondre Citer 0
                      • LaNonne
                        LaNonne dernière édition par

                        @robin4002 a dit dans [1.12.2] Textures random pour un mob :

                        protected ResourceLocation getEntityTexture(Entity entity)

                        Merci de ta réponse.

                        Voici le code actuellement.

                        package fr.hugo.hostile.renders;
                        
                        import fr.hugo.hostile.Reference;
                        import fr.hugo.hostile.entity.EntityAssassin;
                        import fr.hugo.hostile.models.ModelAssassin;
                        import net.minecraft.client.model.ModelBiped;
                        import net.minecraft.client.renderer.entity.RenderBiped;
                        import net.minecraft.client.renderer.entity.RenderManager;
                        import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
                        import net.minecraft.entity.Entity;
                        import net.minecraft.entity.passive.EntityOcelot;
                        import net.minecraft.util.ResourceLocation;
                        import net.minecraftforge.fml.relauncher.SideOnly;
                        
                        
                        public class RenderAssassin extends RenderBiped
                        
                        {
                        
                        
                        	public static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin1.png");
                        	public static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin2.png");
                        	public static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin3.png");
                        	public static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin4.png");
                        	public static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin5.png");
                        
                        
                        
                        
                        	public RenderAssassin(RenderManager renderManagerIn)
                        
                        	{
                        
                        		super(renderManagerIn, new ModelBiped(), 0.5F);
                        
                        		this.addLayer(new LayerHeldItem(this));
                        
                        	}
                        
                        
                        	protected ResourceLocation getAssassinTexture(EntityAssassin assassin)
                        
                        	{
                        
                        		switch (assassin.getAssassinSkin())
                                {
                                    case 0:
                                    default:
                                        return ASSASSIN1_TEXTURE;
                                    case 1:
                                        return ASSASSIN2_TEXTURE;
                                    case 2:
                                        return ASSASSIN3_TEXTURE;
                                    case 3:
                                        return ASSASSIN4_TEXTURE;
                                    case 4:
                                        return ASSASSIN5_TEXTURE;
                                }
                        
                        	}
                        	
                        	protected ResourceLocation getEntityTexture(Entity entity)
                        
                        	{
                        
                        		return this.getAssassinTexture((EntityAssassin)entity);
                        
                        	}
                        
                        }
                        

                        Je n’ai plus le problème que j’ai rencontré sur la vidéo.
                        Cependant, j’ai beau faire spawner autant d’entités que je veux, toute les entités ont la meme texture (la 1ere texture pour etre exact)

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

                          Car le default est mal placé dans ton code.
                          Il devrait être à la fin.

                          1 réponse Dernière réponse Répondre Citer 0
                          • LaNonne
                            LaNonne dernière édition par

                            Ce message a été supprimé !
                            1 réponse Dernière réponse Répondre Citer 0
                            • LaNonne
                              LaNonne dernière édition par

                              @robin4002 J’ai fait comme tu as dit. J’ai mit le default a la fin. Mais comme à la fin il y avait la dernière texture (texture 5). Mes mobs avaient tous la 5e texture.

                              J’ai essayé en prenant modèle sur les perroquets.
                              Ca donne ça dans la classe de l’entité:

                              private static final DataParameter<Integer> ASSASSIN_VARIANT = EntityDataManager.<Integer>createKey(EntityAssassin.class, DataSerializers.VARINT);
                                 
                                 
                                 public int getVariant()
                                 {
                                     return MathHelper.clamp(((Integer)this.dataManager.get(ASSASSIN_VARIANT)).intValue(), 0, 5);
                                 }
                              
                                 protected void entityInit()
                                 {
                                     super.entityInit();
                                     this.dataManager.register(ASSASSIN_VARIANT, Integer.valueOf(0));
                                 }
                              

                              Et sa donne ça dans la classe du rendu:

                              package fr.hugo.hostile.renders;
                              
                              import fr.hugo.hostile.Reference;
                              import fr.hugo.hostile.entity.EntityAssassin;
                              import fr.hugo.hostile.models.ModelAssassin;
                              import net.minecraft.client.model.ModelBiped;
                              import net.minecraft.client.renderer.entity.RenderBiped;
                              import net.minecraft.client.renderer.entity.RenderLiving;
                              import net.minecraft.client.renderer.entity.RenderManager;
                              import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
                              import net.minecraft.entity.Entity;
                              import net.minecraft.entity.passive.EntityOcelot;
                              import net.minecraft.entity.passive.EntityParrot;
                              import net.minecraft.util.ResourceLocation;
                              import net.minecraftforge.fml.relauncher.SideOnly;
                              
                              
                              public class RenderAssassin extends RenderLiving<EntityAssassin>
                              
                              {
                              
                              	public static final ResourceLocation[] ASSASSINS_TEXTURES = new ResourceLocation[] {new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin1.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin2.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin3.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin4.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin5.png")};
                              
                              
                              	public RenderAssassin(RenderManager renderManagerIn)
                              
                              	{
                              
                              		super(renderManagerIn, new ModelBiped(), 0.5F);
                              
                              		this.addLayer(new LayerHeldItem(this));
                              
                              	}
                              
                              	
                              	
                              	protected ResourceLocation getEntityTexture(EntityAssassin entity)
                                  {
                                      return ASSASSINS_TEXTURES[entity.getVariant()];
                                  }
                              	
                              
                              
                              }
                              

                              Avec ce code, j’obtient toujours des mobs avec la première texture 😕

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

                                En fait le problème là c’est que tu n’as plus aucun random de fait, donc entity.getVariant() renvoie toujours la même valeur.

                                1 réponse Dernière réponse Répondre Citer 0
                                • LaNonne
                                  LaNonne dernière édition par robin4002

                                  Merci!!

                                  J’ai enfin réussi. Désolé pour avoir un niveau minable @robin4002 😕
                                  Pour ceux qui veulent avoir des textures random pour leur mobs:

                                  A ajouter dans la classe Entité:

                                  private static final DataParameter<Integer> ASSASSIN_VARIANT = EntityDataManager.<Integer>createKey(EntityAssassin.class, DataSerializers.VARINT);
                                     
                                     
                                     public int getVariant()
                                     {
                                  	   
                                         return MathHelper.clamp(((Integer)this.dataManager.get(ASSASSIN_VARIANT)).intValue(), 0, 4);
                                     }
                                     
                                     public void setVariant(int p_191997_1_)
                                     {
                                         this.dataManager.set(ASSASSIN_VARIANT, Integer.valueOf(p_191997_1_));
                                     }
                                  
                                  
                                     protected void entityInit()
                                     {
                                         super.entityInit();
                                         this.dataManager.register(ASSASSIN_VARIANT, Integer.valueOf(0));
                                     }
                                  
                                  @Override
                                  
                                      public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
                                  
                                         {
                                  
                                      livingdata = super.onInitialSpawn(difficulty, livingdata);
                                      this.setVariant(this.rand.nextInt(5));
                                  
                                      this.setEquipmentBasedOnDifficulty(difficulty);
                                  
                                      return livingdata;
                                  
                                      }
                                  

                                  Et dans la classe du Rendu:

                                  package fr.hugo.hostile.renders;
                                  
                                  import fr.hugo.hostile.Reference;
                                  import fr.hugo.hostile.entity.EntityAssassin;
                                  import fr.hugo.hostile.models.ModelAssassin;
                                  import net.minecraft.client.model.ModelBiped;
                                  import net.minecraft.client.renderer.entity.RenderBiped;
                                  import net.minecraft.client.renderer.entity.RenderLiving;
                                  import net.minecraft.client.renderer.entity.RenderManager;
                                  import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
                                  import net.minecraft.entity.Entity;
                                  import net.minecraft.entity.passive.EntityOcelot;
                                  import net.minecraft.entity.passive.EntityParrot;
                                  import net.minecraft.util.ResourceLocation;
                                  import net.minecraftforge.fml.relauncher.SideOnly;
                                  
                                  
                                  public class RenderAssassin extends RenderLiving<EntityAssassin>
                                  
                                  {
                                  
                                  	public static final ResourceLocation[] ASSASSINS_TEXTURES = new ResourceLocation[] {new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin1.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin2.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin3.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin4.png"), new ResourceLocation(Reference.MOD_ID + ":textures/humans/assassin5.png")};
                                  
                                  
                                  	public RenderAssassin(RenderManager renderManagerIn)
                                  
                                  	{
                                  
                                  		super(renderManagerIn, new ModelBiped(), 0.5F);
                                  
                                  		this.addLayer(new LayerHeldItem(this));
                                  
                                  	}
                                  
                                  	
                                  	
                                  	protected ResourceLocation getEntityTexture(EntityAssassin entity)
                                      {
                                          return ASSASSINS_TEXTURES[entity.getVariant()];
                                      }
                                  	
                                  
                                  
                                  }
                                  

                                  Merci beaucoup!

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

                                  MINECRAFT FORGE FRANCE © 2018

                                  Powered by NodeBB