Résolu Condition pour une Entité Vivante
-
Salut à tous et à toutes et mon problème d’aujourd’hui est le plus spécial que je n’aie jamais eu :
J’ai crée une nouvelle entité et j’y ai mis un code dans la fonction
protected Entity findPlayerToAttack()
Et j’y ai mis ce code et cette condition :
{ /**if (this.isEntityAlive()) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0])); this.playSound("modminekingdomhearts:informationSE", this.getSoundVolume(), this.getSoundPitch()); return entityplayer != null && this.canEntityBeSeen(entityplayer) ? entityplayer : null; } return null; }
Mais le problème c’est que avant que je mette cette condition lorsque je mourrai mon jeu crashai à cause de ces deux lignes
entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0]));
Je pense que lorsqu’on est mort on est considérés comme toujours vivant et donc lorsqu’on est mort on ne peut pas écrire de message d’où le crash c’est aussi pour cela qu’avec la condition cela crash toujours une solution?Il faudrait une condition qui dise si le joueur est vivant (ou est dans le monde) et n’est pas mort alors il fait le message. Un condition qui dise si le joueur n’est pas mort mais quel est cette condition qui dit le joueur est (ou n’est pas) mort ? Essayez de me la trouver svp (je cherche aussi de mon côté depuis hier ^^)
-
Regarde du côté des Events.
-
Salut,
Envoie les codes en entité + le rapport de crash. -
@‘robin4002’:
Salut,
Envoie les codes en entité + le rapport de crash.Voici la class de l’entité :
package mods.maxiworldcraft.mineKingdomHeartsmod.common; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIAvoidEntity; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; public class EntityReflet extends EntityMob { private int stareTimer; private boolean isAggressive; public EntityReflet(World par1World) { super(par1World); this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityEffrayeur.class, 6.0F, 0.45D, 0.45D)); this.tasks.addTask(5, new EntityAIWander(this, 0.45D)); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 0.70D, false)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true)); } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return false; } /** * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking * (Animals, Spiders at day, peaceful PigZombies). */ protected Entity findPlayerToAttack() { if (this.isEntityAlive()) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); //entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1" , new Object[0])); //ça marche pas : this.worldObj.playRecord("modminekingdomhearts:records.similiMusic", (int)posX, (int)posY, (int)posZ); //ça marche : entityplayer.playSound("modminekingdomhearts:informationSE", 0.5F, 0.4F); //ça marche : this.playSound("modminekingdomhearts:records.similiMusic", this.getSoundVolume(), this.getSoundPitch()); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0])); this.playSound("modminekingdomhearts:informationSE", this.getSoundVolume(), this.getSoundPitch()); return entityplayer != null && this.canEntityBeSeen(entityplayer) ? entityplayer : null; } return null; } protected String getLivingSound() { return null; //"modminekingdomhearts:similiMusic"; } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(24D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(4D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.67D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.5D); } }
Voici le crash-report :
–-- Minecraft Crash Report ---- // Why is it breaking :( Time: 24/05/14 13:51 Description: Ticking entity java.lang.NullPointerException: Ticking entity at mods.maxiworldcraft.mineKingdomHeartsmod.common.EntityReflet.findPlayerToAttack(EntityReflet.java:58) at net.minecraft.entity.EntityCreature.updateEntityActionState(EntityCreature.java:64) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1993) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697) at net.minecraft.world.World.updateEntity(World.java:2214) at net.minecraft.world.World.updateEntities(World.java:2064) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:693) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at mods.maxiworldcraft.mineKingdomHeartsmod.common.EntityReflet.findPlayerToAttack(EntityReflet.java:58) at net.minecraft.entity.EntityCreature.updateEntityActionState(EntityCreature.java:64) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1993) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697) at net.minecraft.world.World.updateEntity(World.java:2214) -- Entity being ticked -- Details: Entity Type: reflet (mods.maxiworldcraft.mineKingdomHeartsmod.common.EntityReflet) Entity ID: 199776 Entity Name: Reflet Entity's Exact location: -1630,41, 56,00, -1082,71 Entity's Block location: World: (-1631,56,-1083), Chunk: (at 1,3,5 in -102,-68; contains blocks -1632,0,-1088 to -1617,255,-1073), Region: (-4,-3; contains chunks -128,-96 to -97,-65, blocks -2048,0,-1536 to -1537,255,-1025) Entity's Momentum: -0,02, -0,08, 0,06 Stacktrace: at net.minecraft.world.World.updateEntities(World.java:2064) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528) -- Affected level -- Details: Level name: New World All players: 1 total; [EntityPlayerMP['Julot10085'/152583, l='New World', x=-1630,16, y=56,00, z=-1083,41]] Chunk stats: ServerChunkCache: 562 Drop: 0 Level seed: 2573386486296553879 Level generator: ID 01 - flat, ver 0\. Features enabled: true Level generator options: 2;7,3x1,52x24;2; Level spawn location: World: (-1641,4,-1050), Chunk: (at 7,0,6 in -103,-66; contains blocks -1648,0,-1056 to -1633,255,-1041), Region: (-4,-3; contains chunks -128,-96 to -97,-65, blocks -2048,0,-1536 to -1537,255,-1025) Level time: 2696 game time, 2696 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 113857 (now: false), thunder time: 70816 (now: false) Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:693) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) – System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows XP (x86) version 5.1 Java Version: 1.7.0_55, Oracle Corporation Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation Memory: 793934464 bytes (757 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 106 (5936 bytes; 0 MB) allocated, 3 (168 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.01-pre FML v7.2.156.1061 Minecraft Forge 10.12.1.1061 4 mods loaded, 4 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available FML{7.2.156.1061} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.1.1061.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available Forge{10.12.1.1061} [Minecraft Forge] (forgeSrc-1.7.2-10.12.1.1061.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available modminekingdomhearts{1.0} [Mod MineKingdom Hearts] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 28 (1568 bytes; 0 MB) allocated, 1 (56 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Julot10085'/152583, l='New World', x=-1630,16, y=56,00, z=-1083,41]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
PS = Après que le jeu ait crashé si je me suis fait tué par mon mob , plus possible de retourner sur la map elle crash directe
-
if(entityplayer != null) { entityplayer.addChatComponentMessage(…. }
-
@‘robin4002’:
if(entityplayer != null) { entityplayer.addChatComponentMessage(…. }
J’ai essayé ta condition mais c’est encore pire qu’avant car maintenant il ne joue plus aucune fonction même pas l’affichage dans le tchat et mon mob est passé neutre mais au moins il n’y a plus de crash ^^
Y aurait-il une autre fonction? Et aussi pour que le gamemode 1 ne crash pas lorsque l’on fait spawn ce mob ??? -
renvoie toute ta fonction findPlayerToAttack actuel.
-
@‘robin4002’:
renvoie toute ta fonction findPlayerToAttack actuel.
la voici :
protected Entity findPlayerToAttack() { if (this.getHealth() > 0.0F) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0])); this.playSound("modminekingdomhearts:informationSE", this.getSoundVolume(), this.getSoundPitch()); return entityplayer != null && this.canEntityBeSeen(entityplayer) ? entityplayer : null; } return null; }
Sinon j’avais penséà la condition qui fait que si le joueur meurt alors il droppe tous ses items (son inventaire) et un gui s’ouvre je pourrais prendre cette condition mais je ne la trouve pas cette class avec sa condition ?
-
protected Entity findPlayerToAttack() { if (this.getHealth() > 0.0F) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); if(entityplayer != null && this.canEntityBeSeen(entityplayer)) { entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0])); this.playSound("modminekingdomhearts:informationSE", this.getSoundVolume(), this.getSoundPitch()); return entityplayer; } } return null; }
J’aurai fait comme ça.
-
@‘robin4002’:
protected Entity findPlayerToAttack() { if (this.getHealth() > 0.0F) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); if(entityplayer != null && this.canEntityBeSeen(entityplayer)) { entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.seifer.voleur1", new Object[0])); entityplayer.addChatComponentMessage(new ChatComponentTranslation("tile.reflet.informationVoleur1", new Object[0])); this.playSound("modminekingdomhearts:informationSE", this.getSoundVolume(), this.getSoundPitch()); return entityplayer; } } return null; }
J’aurai fait comme ça.
Ca marche un grand merci à toi Robin