Plusieurs texture pour UNE entité.
-
Oui
J’ai uniquement la quatrieme possibilité 
package fr.hard.mod.Render; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelZombie; import net.minecraft.client.renderer.OpenGlHelper; 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.monster.EntityEnderman; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.Side; import java.util.Random; import org.lwjgl.opengl.GL11; import fr.hard.mod.Entity.EntityAssassin; import fr.hard.mod.Models.ModelAssassin; import fr.hard.mod.Models.ModelHerobrine; @SideOnly(Side.CLIENT) public class RenderAssassin extends RenderBiped { public static ResourceLocation[] skins; public int currentSkin; { Random rand = new Random(); currentSkin = rand.nextInt(skins.length);} public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); this.addLayer(new LayerHeldItem(this)); } static { skins = (new ResourceLocation[] { new ResourceLocation("hard", "textures/humans/assassin1.png"), new ResourceLocation("hard", "textures/humans/assassin2.png"), new ResourceLocation("hard", "textures/humans/assassin2.png"), new ResourceLocation("hard", "textures/humans/assassin3.png"), new ResourceLocation("hard", "textures/humans/assassin4.png"), new ResourceLocation("hard", "textures/humans/assassin5.png") }); } protected ResourceLocation getAssassinTexture(EntityAssassin assassin) { return skins[currentSkin]; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getAssassinTexture((EntityAssassin)entity); } } -
Les nbt sont à mettre dans la classe de l’entité et la variable aléatoire est à mettre au même endroit. Tu peux ensuite y accéder depuis ton rendu comme tu as l’entité en argument de la fonction getEntityTexture
-
J’ai rajouter ceci dans ma Classe de l’entité, c’est correct ?
//Textures public static ResourceLocation[] skins; public int currentSkin; { Random rand = new Random(); currentSkin = rand.nextInt(skins.length);} public void writeEntityToNBT2(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("skins", currentSkin); super.writeEntityToNBT(nbttagcompound);; } public void readEntityFromNBT2(NBTTagCompound nbttagcompound) { currentSkin = nbttagcompound.getInteger("skins"); super.readEntityFromNBT(nbttagcompound); } -
Utilise les balises java, plutôt que les balises code, ce sera + lisible.
Le tableau de ResourceLocation a + à voir avec la classe render que entity. Si tu souhaites avoir de la persistance dans la sélection de la texture pour chaque instance de ton entity, alors oui go NBTTag + DataWatcher pour synchroniser l’indexe
-
Bon, je m’avoue un peu dépasser, c’est un peu hors de mes compétences.
il n’y a pas plus simple ? Comme le rendu des lapins, et des ocelots ?
-
Non, c’est d’ailleurs ce qu’utilisent les lapins/ocelots apprivoisés
-
Justement , je pourrais peut etre me servir de ça ?
-
Oui, c’est la seule manière simple de synchroniser le serveur (l’index du skin) avec tous les clients connectés (permettant de rendre le bon).
Inspire toi des classes cités au-dessus, et reviens si tu as des questions. -
Prendre exemple sur le rendu des Ocelots est le plus simple.
Ma seule question est par quoi remplacer: switch (entity.getTameSkin())
package net.minecraft.client.renderer.entity; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderOcelot extends RenderLiving <entityocelot>{ private static final ResourceLocation BLACK_OCELOT_TEXTURES = new ResourceLocation("textures/entity/cat/black.png"); private static final ResourceLocation OCELOT_TEXTURES = new ResourceLocation("textures/entity/cat/ocelot.png"); private static final ResourceLocation RED_OCELOT_TEXTURES = new ResourceLocation("textures/entity/cat/red.png"); private static final ResourceLocation SIAMESE_OCELOT_TEXTURES = new ResourceLocation("textures/entity/cat/siamese.png"); public RenderOcelot(RenderManager renderManagerIn, ModelBase modelBaseIn, float shadowSizeIn) { super(renderManagerIn, modelBaseIn, shadowSizeIn); } /** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(EntityOcelot entity) { switch (entity.getTameSkin()) { case 0: default: return OCELOT_TEXTURES; case 1: return BLACK_OCELOT_TEXTURES; case 2: return RED_OCELOT_TEXTURES; case 3: return SIAMESE_OCELOT_TEXTURES; } }
J’arrive à tout remplacer ce qui faut mais comme j’ai dit il y a la ligne: switch (entity.getTameSkin())
Je sais pas par quoi le remplacer pour ce ça marche avec mon mob. De type Humain , Biped :/</entityocelot>
-
La méthode getTameSkin renvoie un int représentant l’index de la texture à bind, du coup à toi de faire ta propre méthode.
-
J’ai fait quelques changements 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(); }Et la classe Render:
package fr.hard.mod.Render; import fr.hard.mod.Entity.EntityAssassin; import fr.hard.mod.Models.ModelAssassin; import fr.hard.mod.Models.ModelBandit; import fr.hard.mod.Models.ModelRogue; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.GlStateManager; 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.passive.EntityOcelot; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderAssassin extends RenderBiped { private static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin1.png"); private static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin2.png"); private static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin3.png"); private static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin4.png"); private static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin5.png"); public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); this.addLayer(new LayerHeldItem(this)); } protected ResourceLocation getEntityTexture(EntityAssassin entity) { switch (entity.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; } } }Et j’obtiens maintenant ceci:
</integer></integer> -
Une de tes textures est probablement bugguée
-
Bon je vois pas le problème. je verrai ça demain.
-
Je dirais plutôt que la méthode getEntityTexture n’est jamais appelée. Il faut que tu overrode la méthode getEntityTexture qui prends Entity en argument et que dedans, tu appelle getEntityTexture qui prends EntityAssassin en aguments. (Ou alors que tu garde qu’une fonction mais tu met Entity en argument et tu fait un cast pour pouvoir appeler getAssassinSkin)
-
J’arrive pas a mettre un @Override, il me dit de l’enlever a chaque fois.
J’ai creer une méthode getEntityTexture comme tu l’a dit.
package fr.hard.mod.Render; import fr.hard.mod.Entity.EntityAssassin; import fr.hard.mod.Entity.EntityRogue; import fr.hard.mod.Models.ModelAssassin; import fr.hard.mod.Models.ModelBandit; import fr.hard.mod.Models.ModelRogue; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.GlStateManager; 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.minecraft.util.text.TextFormatting; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderAssassin extends RenderBiped { private static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin1.png"); private static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin2.png"); private static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin3.png"); private static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin4.png"); private static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin5.png"); public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); this.addLayer(new LayerHeldItem(this)); } protected ResourceLocation getEntityTexture(EntityAssassin entity) { switch (entity.getAssassinSkin()) { case 0: default: return ASSASSIN1_TEXTURE; case 1: return ASSASSIN2_TEXTURE; case 2: return ASSASSIN3_TEXTURE; case 3: return ASSASSIN4_TEXTURE; } } protected ResourceLocation getEntityTexture(Entity entity) { return this.getEntityTexture((EntityAssassin)entity); } }Mais j’en arrive au point ou il n’arrive pas a faire le rendu de l’entité

[23:46:56] [Client thread/ERROR]: Couldn't render entity java.lang.NullPointerException at net.minecraft.network.datasync.EntityDataManager.get(EntityDataManager.java:149) ~[EntityDataManager.class:?] at fr.hard.mod.Entity.EntityAssassin.getAssassinSkin(EntityAssassin.java:161) ~[EntityAssassin.class:?] at fr.hard.mod.Render.RenderAssassin.getEntityTexture(RenderAssassin.java:40) ~[RenderAssassin.class:?] at fr.hard.mod.Render.RenderAssassin.getEntityTexture(RenderAssassin.java:56) ~[RenderAssassin.class:?] at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:113) ~[Render.class:?] at net.minecraft.client.renderer.entity.RenderLivingBase.renderModel(RenderLivingBase.java:253) ~[RenderLivingBase.class:?] at net.minecraft.client.renderer.entity.RenderLivingBase.doRender(RenderLivingBase.java:185) [RenderLivingBase.class:?] at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:51) [RenderLiving.class:?] at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:16) [RenderLiving.class:?] at net.minecraft.client.renderer.entity.RenderManager.doRenderEntity(RenderManager.java:372) [RenderManager.class:?] at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:356) [RenderManager.class:?] at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:651) [RenderGlobal.class:?] at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1368) [EntityRenderer.class:?] at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1282) [EntityRenderer.class:?] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1091) [EntityRenderer.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1139) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:406) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] -
Je ne connais pas trop les DataWatcher, mais dans ce cas, je ne vois pas trop à quoi il sert (si la valeur est défie à la création de l’entitée, puis n’est pas changée).
Sinon, je pense que tu n’as pas “register” ton DataWatcher ou alors tu ne l’as pas initialisée (mais, là, je ne m’y connais pas, donc je peux pas trop t’aider). -
Les DataManagers sont obligés comme il compte save dans les NBT
-
Bonne nouvelle , les skins changent. Mais que quand je relance le jeu.
package fr.hard.mod.Render; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelZombie; import net.minecraft.client.renderer.OpenGlHelper; 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.monster.EntityEnderman; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.Side; import java.util.Random; import org.lwjgl.opengl.GL11; import fr.hard.mod.Entity.EntityAssassin; import fr.hard.mod.Entity.EntityRogue; import fr.hard.mod.Models.ModelAssassin; import fr.hard.mod.Models.ModelHerobrine; import fr.hard.mod.Models.ModelRogue; @SideOnly(Side.CLIENT) public class RenderAssassin extends RenderBiped { public static ResourceLocation[] skins; public int currentSkin; { Random rand = new Random(); currentSkin = rand.nextInt(skins.length);} private static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin1.png"); private static final ResourceLocation ASSASSIN2_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin2.png"); private static final ResourceLocation ASSASSIN3_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin3.png"); private static final ResourceLocation ASSASSIN4_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin4.png"); private static final ResourceLocation ASSASSIN5_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin5.png"); public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); this.addLayer(new LayerHeldItem(this)); } static { skins = (new ResourceLocation[] { new ResourceLocation("hard", "textures/humans/assassin1.png"), new ResourceLocation("hard", "textures/humans/assassin2.png"), new ResourceLocation("hard", "textures/humans/assassin2.png"), new ResourceLocation("hard", "textures/humans/assassin3.png"), new ResourceLocation("hard", "textures/humans/assassin4.png"), new ResourceLocation("hard", "textures/humans/assassin5.png") }); } protected ResourceLocation getAssassinTexture(EntityAssassin assassin) { return skins[currentSkin]; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getAssassinTexture((EntityAssassin)entity); } } -
Qu’est-ce que cela veut dire “que quand je relance mon jeu” ?
Au contraire si tu saves dans les NBT, il y aura de la persistance dans le monde généré, donc les skins une fois définis, ne changeront plus.EDIT: Vu l’état actuel de ton code, tu n’utilise pas du tout la structure NBT.
-
Le skin de mon mob change quand je relance le jeu.
Quand j’utilise les oeufs , sa fait spawner que la meme texture. Je dois relancer le jeu pour avoir une autre texture.
Je vais essayer de mettre des NBT