Plusieurs texture pour UNE entité.
-
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
-
Il me semble que les classes Render sont de type Singleton, du coup instanciées qu’une seule fois. Il est donc normal, que ta variable currentSkin prendra toujours la même valeur pour n’importe quel instance d’entité dans le monde, jusqu’au prochaine redémarrage de mc.
-
Je suis pas sur, mais pourquoi pas s’inspirer de ce code ?
@Override public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) { livingdata = super.onInitialSpawn(difficulty, livingdata); this.setEquipmentBasedOnDifficulty(difficulty); return livingdata; } -
Le constructeur serait + approprié
-
Les skins changent bien en jeu
Mais quand je fais spawner un mob, il y a sa texture, OK .
Quand j’en fait spawner un deuxieme, sa texture change.Le seul soucis c’est que quand le deuxieme spawn, tout les mobs (du meme type) prennent le meme skin et donc tout mes mobs ont le meme skin.
Classe de l’entité:
package fr.hard.mod.Entity; import java.util.Random; import fr.hard.mod.EntityAIAttackMelee; import fr.hard.mod.HSoundEvents; import net.minecraft.block.material.Material; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityIronGolem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.monster.EntityPolarBear; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.passive.EntityPig; import net.minecraft.entity.passive.EntityRabbit; import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; public class EntityAssassin extends EntityMob { public static ItemStack equippedItems[]; public int currentItem; { currentItem = rand.nextInt(equippedItems.length);} public static ResourceLocation[] skins; public static int currentSkin; { Random rand = new Random(); currentSkin = rand.nextInt(skins.length);} public EntityAssassin(World worldIn) { super(worldIn); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.applyEntityAI(); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(12.0D); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.39000000417232513D); this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D); } protected void applyEntityAI() { this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityPlayer.class})); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBandit.class, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCreeper.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityPirate.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityRogue.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityRogueArcher.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityShadow.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityZombie.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCreeper.class, true)); } protected SoundEvent getHurtSound() { return HSoundEvents.ENTITY_HURT; } protected SoundEvent getDeathSound() { return HSoundEvents.ENTITY_NEUTRAL_DEATH; } public void dropFewItems(boolean b, int looting) { this.dropItem(Items.GOLD_INGOT, 2); this.dropItem(Items.REDSTONE, 1); } static { equippedItems = (new ItemStack[] { new ItemStack(Items.WOODEN_PICKAXE, 1), new ItemStack(Items.WOODEN_SWORD, 1), new ItemStack(Items.BRICK, 1), new ItemStack(Items.IRON_AXE, 1), new ItemStack(Items.GOLDEN_AXE, 1), new ItemStack(Items.IRON_HOE, 1), new ItemStack(Items.DIAMOND_SWORD, 1), new ItemStack(Items.IRON_SWORD, 1), new ItemStack(Items.GOLDEN_SWORD, 1), new ItemStack(Items.IRON_PICKAXE, 1) }); } public ItemStack getHeldItem() { return equippedItems[currentItem]; } public void writeEntityToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("equippedItem", currentItem); super.writeEntityToNBT(nbttagcompound);; } public void readEntityFromNBT(NBTTagCompound nbttagcompound) { currentItem = nbttagcompound.getInteger("equippedItem"); super.readEntityFromNBT(nbttagcompound); } @Override public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) { livingdata = super.onInitialSpawn(difficulty, livingdata); this.setEquipmentBasedOnDifficulty(difficulty); return livingdata; } @Override protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) { super.setEquipmentBasedOnDifficulty(difficulty); this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, equippedItems[currentItem]); } @Override protected boolean canDespawn() { return true; } }Classe du rendu:
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.IEntityLivingData; import net.minecraft.entity.monster.EntityEnderman; 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.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 { 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 { EntityAssassin.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 EntityAssassin.skins[EntityAssassin.currentSkin]; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getAssassinTexture((EntityAssassin)entity); } } -
Salut, dans RenderAssassin#getAssassinTexture(EntityAssassin ), tu accèdes à une variable currentSkin qui est static, donc normal que toutes tes instances partagent une même et unique valeur. Ce field ne devrait pas être static, juste public, de manière à y accéder avec ton paramètre “assassin”.
-
Merci, tout marche correctement. J’ai plus qu’a appliquer ça pour tout mes mobs!
Sa a été une grosse bataille lol -
C’est comme ça qu’on progresse ^^