Résolu Probleme: Equiper son mob d'une épée.
-
Coucou les gens,
Je suis actuellement en train de réecrire le mod Humans+.
Mais je n’arrive pas à donner un outil random à mon Mob.
package fr.hard.mod.Entity; 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.EntityAIAttackMelee; 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.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.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 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) }); } 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); } }
La classe Render:
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.entity.Entity; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.Side; 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 { private static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin1.png"); public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); } protected ResourceLocation getAssassinTexture(EntityAssassin assassin) { return ASSASSIN1_TEXTURE; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getAssassinTexture((EntityAssassin)entity); } }
J’ai suivi un tuto pour la 1.6, il n"y a pas d’erreur, alors pourquoi pas essayer xD Mais mon mon ne tient pas d’outils dans sa main
Merci!
-
Salut Hugofounda,
tout d’abord c’est très ambitieux de ta part de vouloir update un tel mod, mais à la fois très honorable de ramener à la vie de tels pièces de puzzle du modding minecraft. Pour la petite parenthèse, j’ai update il y a plusieurs mois More Creeps & Weirdos en 1.10.2, ce fut un vrai calvaire avec les .jsons, et les multitudes de créatures et leurs render, etc…
Bref, concernant ton problème, voici les méthodes à surcharger:@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]); }
-
Merci pour ton message Plaigon
J’ai rajouter ton code au mien mais mon Mob n’a pas d’items en main
package fr.hard.mod.Entity; 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.EntityAIAttackMelee; 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.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.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 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) }); } 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]); } }
-
Ah oui, pas fait gaffe, tu dois également rajouter un Layer dans le constructeur de ta classe Render, regarde comment RenderPlayer ou encore RenderZombie font.
EDIT: Songe à utiliser les balises java plutôt que les balises code -
Exceptionel! Merci 1000 fois sa marche enfin!
Je vais surement creer d’autres thread car il y a des trucs que j’arrive pas.
–-------------------------------------------------------------------------------------------------
Pour ceux qui veulent equiper leurs mobs
Classe de l’entité:
package fr.hard.mod.Entity; 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.EntityAIAttackMelee; 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.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.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 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) }); } 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]); } }
La 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.monster.EntityEnderman; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.Side; 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 { private static final ResourceLocation ASSASSIN1_TEXTURE = new ResourceLocation("hard", "textures/humans/assassin1.png"); public RenderAssassin(RenderManager renderManagerIn, ModelAssassin modelAssassin, float f) { super(renderManagerIn, new ModelBiped(), 0.5F, 1.0F); this.addLayer(new LayerHeldItem(this)); } protected ResourceLocation getAssassinTexture(EntityAssassin assassin) { return ASSASSIN1_TEXTURE; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getAssassinTexture((EntityAssassin)entity); } }
-
N’oublie pas de sélectionner la réponse qui t’as le + aidée !