Résolu Message dans le chat
-
J’avais déjà fait autrefois un sujet la dessus, ici : http://www.minecraftforgefrance.fr/showthread.php?tid=215, le problème est qu’il ne marche plus en 1.7.2.
Erreur : The method addChatMessage(IChatComponent) in the type ICommandSender is not applicable for the arguments (String)
Code :package fr.nolancraft.onche.Mobs; import java.util.List; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import fr.nolancraft.onche.Data.Main; public class EntityHap extends EntityHapAgro { private String[] messageArray = new String[] { "première phrase", "seconde phrase", "troisième phrase", "etc …" }; @SuppressWarnings("unused") private int angerLevel; @SuppressWarnings("unused") private int randomSoundDelay; public EntityHap(World world) { super(world); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3D); } public Item getDropItem() { return Main.Hap; } protected void dropFewItems(boolean par1, int par2) { int j = this.rand.nextInt(2 + par2); int k; for (k = 0; k < j; ++k) { this.dropItem(Main.Hap, 1); } } protected void dropRareDrop(int par1) { this.dropItem(Main.cisla, 1); } protected void addRandomArmor() { this.setCurrentItemOrArmor(0, null); } public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) { if (this.isEntityInvulnerable()) { return false; } else { Entity entity = par1DamageSource.getEntity(); if (entity instanceof EntityPlayer) { @SuppressWarnings("rawtypes") List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D)); for (int i = 0; i < list.size(); ++i) { Entity entity1 = (Entity) list.get(i); if (entity1 instanceof EntityHap) { EntityHap entityHap = (EntityHap) entity1; entityHap.becomeAngryAt(entity); } } this.becomeAngryAt(entity); } return super.attackEntityFrom(par1DamageSource, par2); } } private void becomeAngryAt(Entity par1Entity) { this.entityToAttack = par1Entity; this.angerLevel = 400 + this.rand.nextInt(400); this.randomSoundDelay = this.rand.nextInt(40); } public boolean interact(EntityPlayer player) { if (!this.worldObj.isRemote) { player.addChatMessage(this.messageArray[this.worldObj.rand.nextInt(this.messageArray.length)]); return true; } return false; } }
Merci d’avance.
-
player.addChatMessage(new ChatComponentText(this.messageArray[this.worldObj.rand.nextInt(this.messageArray.length)]));
-
Merci a toi, ça marche.