MFF

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

    [1.12.2] Textures random pour un mob

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    14 Messages 2 Publieurs 404 Vues 3 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.
    • LaNonneL Hors-ligne
      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
      • robin4002R Hors-ligne
        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
        • LaNonneL Hors-ligne
          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
          • robin4002R Hors-ligne
            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
            • LaNonneL Hors-ligne
              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
              • robin4002R Hors-ligne
                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
                • LaNonneL Hors-ligne
                  LaNonne
                  dernière édition par

                  Ce message a été supprimé !
                  1 réponse Dernière réponse Répondre Citer 0
                  • LaNonneL Hors-ligne
                    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
                    • robin4002R Hors-ligne
                      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
                      • LaNonneL Hors-ligne
                        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
                        ContactMentions Légales

                        MINECRAFT FORGE FRANCE © 2024

                        Powered by NodeBB