Résolu Crash / Cannot Cast
-
Un crash surprenant qui n’arrive pas systématiquement.
–-- Minecraft Crash Report ---- // You're mean. Time: 01/03/16 09:42 Description: Ticking entity java.lang.ClassCastException: net.minecraft.entity.monster.EntityZombie cannot be cast to net.minecraft.entity.player.EntityPlayer at fr.powergame.modpg2.common.LivingEventHandler.onEntityKilled(LivingEventHandler.java:31) at cpw.mods.fml.common.eventhandler.ASMEventHandler_8_LivingEventHandler_onEntityKilled_LivingDeathEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:305) at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:982) at net.minecraft.entity.passive.EntityVillager.onDeath(EntityVillager.java:371) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:940) at net.minecraft.entity.monster.EntityMob.attackEntityAsMob(EntityMob.java:140) at net.minecraft.entity.monster.EntityZombie.attackEntityAsMob(EntityZombie.java:340) at net.minecraft.entity.ai.EntityAIAttackOnCollide.updateTask(EntityAIAttackOnCollide.java:167) at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:125) at net.minecraft.entity.EntityLiving.updateAITasks(EntityLiving.java:613) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1983) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.monster.EntityZombie.onLivingUpdate(EntityZombie.java:243) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.entity.monster.EntityZombie.onUpdate(EntityZombie.java:335) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:684) at net.minecraft.world.World.updateEntity(World.java:2258) at net.minecraft.world.World.updateEntities(World.java:2108) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at fr.powergame.modpg2.common.LivingEventHandler.onEntityKilled(LivingEventHandler.java:31) at cpw.mods.fml.common.eventhandler.ASMEventHandler_8_LivingEventHandler_onEntityKilled_LivingDeathEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:305) at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:982) at net.minecraft.entity.passive.EntityVillager.onDeath(EntityVillager.java:371) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:940) at net.minecraft.entity.monster.EntityMob.attackEntityAsMob(EntityMob.java:140) at net.minecraft.entity.monster.EntityZombie.attackEntityAsMob(EntityZombie.java:340) at net.minecraft.entity.ai.EntityAIAttackOnCollide.updateTask(EntityAIAttackOnCollide.java:167) at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:125) at net.minecraft.entity.EntityLiving.updateAITasks(EntityLiving.java:613) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1983) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.monster.EntityZombie.onLivingUpdate(EntityZombie.java:243) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.entity.monster.EntityZombie.onUpdate(EntityZombie.java:335) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:684) at net.minecraft.world.World.updateEntity(World.java:2258) -- Entity being ticked -- Details: Entity Type: Zombie (net.minecraft.entity.monster.EntityZombie) Entity ID: 130 Entity Name: Zombie Entity's Exact location: -1291,00, 5,00, -246,10 Entity's Block location: World: (-1292,5,-247), Chunk: (at 4,0,9 in -81,-16; contains blocks -1296,0,-256 to -1281,255,-241), Region: (-3,-1; contains chunks -96,-32 to -65,-1, blocks -1536,0,-512 to -1025,255,-1) Entity's Momentum: 0,01, -0,08, -0,01 Stacktrace: at net.minecraft.world.World.updateEntities(World.java:2108) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) -- Affected level -- Details: Level name: New World All players: 0 total; [] Chunk stats: ServerChunkCache: 625 Drop: 0 Level seed: -2260587672458567962 Level generator: ID 01 - flat, ver 0\. Features enabled: true Level generator options: Level spawn location: World: (-1278,4,-137), Chunk: (at 2,0,7 in -80,-9; contains blocks -1280,0,-144 to -1265,255,-129), Region: (-3,-1; contains chunks -96,-32 to -65,-1, blocks -1536,0,-512 to -1025,255,-1) Level time: 2517 game time, 2517 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 30192 (now: false), thunder time: 165504 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.8.0_73, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 299107280 bytes (285 MB) / 627572736 bytes (598 MB) up to 1379926016 bytes (1316 MB) JVM Flags: 0 total; AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1448 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) UCHIJAAAA Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) UCHIJAAAA modpg2{1.2.2} [Mod Power Game 2] (bin) GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
Alors à la ligne indiquée j’ai
EntityPlayer player = (EntityPlayer) event.source.getEntity();
Qui fait partie de:
@SubscribeEvent public void onEntityKilled(LivingDeathEvent event) { EntityPlayer player = (EntityPlayer) event.source.getEntity(); Random rand = new Random(); ItemStack stack1 = new ItemStack(ModPg2.itemRandomMunition, 1); ItemStack stack2 = new ItemStack(ModPg2.itemMetadata, 1, 0); //Insigne ItemStack stack3 = new ItemStack(ModPg2.itemMetadata, 1, 1); //Dent ItemStack stack4 = new ItemStack(ModPg2.itemMetadata, 1, 2); //Collier if(!event.entityLiving.worldObj.isRemote && event.entityLiving instanceof EntityMobGangster) { int randInt = rand.nextInt(100); for(int j = 0 ; j < 2; ++j) { if (randInt <= 5) { // 5/100 event.entityLiving.entityDropItem(stack2, 1); } if (randInt > 5 && randInt <= 15) { // 10/100 event.entityLiving.entityDropItem(stack4, 1); } if (randInt > 15) { // 84/100 event.entityLiving.entityDropItem(stack1, 1); } } if(player != null) { int killG1 = player.getEntityData().getInteger("killG1"); if(!player.worldObj.isRemote) { killG1++; player.getEntityData().setInteger("killG1", killG1); } if(killG1 == 50) { player.triggerAchievement(ModPg2.achievementKillG1a); } if(killG1 == 200) { player.triggerAchievement(ModPg2.achievementKillG1b); } if(killG1 == 1000) { player.triggerAchievement(ModPg2.achievementKillG1c); } if(killG1 == 5000) { player.triggerAchievement(ModPg2.achievementKillG1d); } } } if(!event.entityLiving.worldObj.isRemote && event.entityLiving instanceof EntityMobGangster2) { int randInt = rand.nextInt(100); for(int j = 0 ; j < 2; ++j) { if (randInt == 0) { // 1/100 event.entityLiving.entityDropItem(stack3, 1); if(player != null) { player.triggerAchievement(ModPg2.achievementDentOr); } } if (randInt > 0 && randInt <= 10) { // 10/100 event.entityLiving.entityDropItem(stack2, 1); } if (randInt > 5 && randInt <= 15) { // 10/100 event.entityLiving.entityDropItem(stack4, 1); } if (randInt > 15) { // 79/100 event.entityLiving.entityDropItem(stack1, 1); } } if(player != null) { int killG2 = player.getEntityData().getInteger("killG2"); if(!player.worldObj.isRemote) { killG2++; player.getEntityData().setInteger("killG2", killG2); } if(killG2 == 25) { player.triggerAchievement(ModPg2.achievementKillG2a); } if(killG2 == 100) { player.triggerAchievement(ModPg2.achievementKillG2b); } if(killG2 == 500) { player.triggerAchievement(ModPg2.achievementKillG2c); } if(killG2 == 1000) { player.triggerAchievement(ModPg2.achievementKillG2d); } } } if(!event.entityLiving.worldObj.isRemote && event.entityLiving instanceof EntityMobGangster3) { int randInt = rand.nextInt(100); for(int j = 0 ; j < 2; ++j) { if (randInt <= 2) { // 3/100 event.entityLiving.entityDropItem(stack3, 1); if(player != null) { player.triggerAchievement(ModPg2.achievementDentOr); } } if (randInt > 2 && randInt <= 12) { // 10/100 event.entityLiving.entityDropItem(stack2, 1); } if (randInt > 12 && randInt <= 17) { // 5/100 event.entityLiving.entityDropItem(stack4, 1); } if (randInt > 17) { // 82/100 event.entityLiving.entityDropItem(stack1, 1); } } } if(player != null) { int killG3 = player.getEntityData().getInteger("killG3"); if(!player.worldObj.isRemote) { killG3++; player.getEntityData().setInteger("killG3", killG3); } if(killG3 == 10) { player.triggerAchievement(ModPg2.achievementKillG3a); } if(killG3 == 40) { player.triggerAchievement(ModPg2.achievementKillG3b); } if(killG3 == 200) { player.triggerAchievement(ModPg2.achievementKillG3c); } if(killG3 == 400) { player.triggerAchievement(ModPg2.achievementKillG3d); } } }
Qui me permet de comptabiliser les kills pour mes succès et de gérer les loots lâchés par mes mobs.
(Petit clin d’oeil à Elias qui malgré lui m’a lancé dans la folie des succès en tout genre)
-
il faut mettre tout le code dans un bloc if(event.source.getEntity() instanceof EntityPlayer)
-
Qui te dis que c’est un joueur qui a tué le mob en question ?
Rajoute une condition event.source.getEntity() instanceof EntityPlayer. -
Ouki merci les gens, je ne connais pas le fonctionnement du cast alors j’ai cru que ça équivalait au Instanceof.
Voilà (et merci pour le déplacement de sujet, j’étais pas sûr que ce soit lié au modding)