Crash de mon mode de tp


  • Moddeurs confirmés Modérateurs

    Salut a tous j'ai créer un petit mode de cimetière qui quand on appuie sur le bouton respawn on est tp au biome sky le plus proche.
    Mais malheureusement j'ai un crash que je ne comprend pas…

    la classe cimetière:

    
    package CoeCemetery;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.util.ChunkCoordinates;
    import net.minecraft.world.World;
    import net.minecraft.world.biome.BiomeGenBase;
    import net.minecraftforge.event.ForgeSubscribe;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    
    public class CemeteryZone
    {
    
    private ChunkCoordinates findClosestBlockOfBiome(Entity e, BiomeGenBase b, double radius)
    {
    World w = e.worldObj;
    double min = Double.POSITIVE_INFINITY;
    ChunkCoordinates current = null;
    for(double x = -radius; x <= radius; x += 0.5)
    {
    for(double z = -radius; z <= radius; z += 0.5)
    {
    double dist = Math.sqrt(Math.pow((e.posX - (int)Math.floor(x + e.posX)), 2) + Math.pow((e.posZ - (int)Math.floor(z + e.posZ)), 2));
    if(w.getBiomeGenForCoords((int)Math.floor(x + e.posX), (int)Math.floor(z + e.posZ)) == b && dist <= radius && min > dist)
    {
    min = dist;
    current = new ChunkCoordinates((int)Math.floor(x + e.posX), 0, (int)Math.floor(z + e.posZ));
    }
    }
    }
    return current;
    }
    
    @ForgeSubscribe
    public void onRespawn(EntityJoinWorldEvent event)
    {
    System.out.println("CemeteryZone");
    System.out.println();
    EntityLivingBase entity = (EntityLivingBase)event.entity;
    if(GuiDeath.mort == true)
    {
    if(entity instanceof EntityPlayer)
    {
    
    if(((EntityPlayer)entity).capabilities.isCreativeMode == true)
    {
    return;
    }
    
    else if(((EntityPlayer)entity).capabilities.isCreativeMode == false)
    {
    BiomeGenBase location = event.entity.worldObj.getBiomeGenForCoords((int)event.entity.posX, (int)event.entity.posZ);
    
    System.out.println("testrespawn");
    System.out.println(GuiDeath.mort);
    ChunkCoordinates biomeLocation = findClosestBlockOfBiome(((EntityPlayer)entity), BiomeGenBase.sky, 100);
    entity.setLocationAndAngles(biomeLocation.posX, 250, biomeLocation.posZ, entity.rotationYaw, entity.rotationPitch);
    System.out.println("GuiDeath tp Cemetery");
    }
    }
    }
    }
    }
    
    

    l'appuis du bouton (GuiDeath):

    
    if(par1GuiButton.id == 1)
    {
    this.mc.thePlayer.respawnPlayer();
    this.mc.displayGuiScreen((GuiScreen)null);
    mort = true;
    
    }
    
    

    le crash report:

    
    ---- Minecraft Crash Report ----
    // I feel sad now :(
    
    Time: 06/05/14 11:10
    Description: Exception in world tick
    
    java.lang.NullPointerException
    at CoeCemetery.CemeteryZone.onRespawn(CemeteryZone.java:58)
    at net.minecraftforge.event.ASMEventHandler_7_CemeteryZone_onRespawn_EntityJoinWorldEvent.invoke(.dynamic)
    at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
    at net.minecraftforge.event.EventBus.post(EventBus.java:108)
    at net.minecraft.world.World.spawnEntityInWorld(World.java:1573)
    at net.minecraft.client.multiplayer.WorldClient.spawnEntityInWorld(WorldClient.java:184)
    at net.minecraft.client.Minecraft.setDimensionAndSpawnPlayer(Minecraft.java:2217)
    at net.minecraft.client.multiplayer.NetClientHandler.handleRespawn(NetClientHandler.java:1106)
    at net.minecraft.network.packet.Packet9Respawn.processPacket(Packet9Respawn.java:39)
    at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
    at net.minecraft.client.multiplayer.NetClientHandler.processReadPackets(NetClientHandler.java:282)
    at net.minecraft.client.multiplayer.WorldClient.tick(WorldClient.java:99)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1930)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)
    at net.minecraft.client.Minecraft.run(Minecraft.java:838)
    at net.minecraft.client.main.Main.main(Main.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
    
    A detailed walkthrough of the error, its code path and all known details is as follows:
    ---------------------------------------------------------------------------------------
    
    -- Head --
    Stacktrace:
    at CoeCemetery.CemeteryZone.onRespawn(CemeteryZone.java:58)
    at net.minecraftforge.event.ASMEventHandler_7_CemeteryZone_onRespawn_EntityJoinWorldEvent.invoke(.dynamic)
    at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
    at net.minecraftforge.event.EventBus.post(EventBus.java:108)
    at net.minecraft.world.World.spawnEntityInWorld(World.java:1573)
    at net.minecraft.client.multiplayer.WorldClient.spawnEntityInWorld(WorldClient.java:184)
    at net.minecraft.client.Minecraft.setDimensionAndSpawnPlayer(Minecraft.java:2217)
    at net.minecraft.client.multiplayer.NetClientHandler.handleRespawn(NetClientHandler.java:1106)
    at net.minecraft.network.packet.Packet9Respawn.processPacket(Packet9Respawn.java:39)
    at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
    at net.minecraft.client.multiplayer.NetClientHandler.processReadPackets(NetClientHandler.java:282)
    
    -- Affected level --
    Details:
    Level name: MpServer
    All players: 1 total; [EntityClientPlayerMP['isador34'/14753, l='MpServer', x=8,50, y=66,62, z=8,50]]
    Chunk stats: MultiplayerChunkCache: 0
    Level seed: 0
    Level generator: ID 01 - flat, ver 0\. Features enabled: false
    Level generator options:
    Level spawn location: World: (8,64,8), Chunk: (at 8,4,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 238918 game time, 2009 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
    Forced entities: 1 total; [EntityClientPlayerMP['isador34'/0, l='MpServer', x=1149,23, y=4,62, z=231,25]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
    Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1943)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)
    at net.minecraft.client.Minecraft.run(Minecraft.java:838)
    at net.minecraft.client.main.Main.main(Main.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
    
    – Affected level --
    Details:
    Level name: MpServer
    All players: 1 total; [EntityClientPlayerMP['isador34'/14753, l='MpServer', x=8,50, y=66,62, z=8,50]]
    Chunk stats: MultiplayerChunkCache: 0
    Level seed: 0
    Level generator: ID 01 - flat, ver 0\. Features enabled: false
    Level generator options:
    Level spawn location: World: (8,64,8), Chunk: (at 8,4,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 238921 game time, 2012 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
    Forced entities: 1 total; [EntityClientPlayerMP['isador34'/0, l='MpServer', x=1149,23, y=4,62, z=231,25]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
    
    – System Details --
    Details:
    Minecraft Version: 1.6.4
    Operating System: Windows 7 (amd64) version 6.1
    Java Version: 1.7.0_45, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 860710688 bytes (820 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    AABB Pool Size: 7251 (406056 bytes; 0 MB) allocated, 3 (168 bytes; 0 MB) used
    Suspicious classes: FML and Forge are installed
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP v8.11 FML v6.4.45.953 Minecraft Forge 9.11.1.953 13 mods loaded, 13 mods active
    mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    FML{6.4.45.953} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Forge{9.11.1.953} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coeblock{1.0.0} [Coe Block] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coebordure{1.0.0} [Coe Bordure] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coecemetery{1.0.0} [CoeCemetery] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coecore{1.0.0} [CoeCore] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coelevel{1.0.0} [CoeLevel] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coemob{1.0.0} [Coemob] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    coespell{1.0.0} [CoeSpell] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    crusadegui{2.0.0} [COE gui] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    mineralherb{1.0.1} [Mineralherb] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    PM{V.1.0.0} [Portal WoW] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Launched Version: 1.6
    LWJGL: 2.9.0
    OpenGL: Intel(R) HD Graphics GL version 3.1.0 - Build 9.17.10.3347, Intel
    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Pack: Default
    Current Language: English (US)
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 260 (14560 bytes; 0 MB) allocated, 16 (896 bytes; 0 MB) used
    
    

  • Moddeurs confirmés Rédacteurs Administrateurs

    EntityLivingBase entity = (EntityLivingBase)event.entity;
    Déjà la c'est pas bon, tu vas avoir un CastException si l'entité n'est pas une EntityLivingBase.

    @ForgeSubscribe
    public void onRespawn(EntityJoinWorldEvent event)
    {
    System.out.println("CemeteryZone");
    System.out.println();
    if(GuiDeath.mort == true)
    {
    if(entity instanceof EntityPlayer)
    {
    EntityPlayer player = (EntityPlayer)event.entity;
    if(player .capabilities.isCreativeMode)
    {
    return;
    }
    
    else if(!player.capabilities.isCreativeMode)
    {
    BiomeGenBase location = event.entity.worldObj.getBiomeGenForCoords((int)event.entity.posX, (int)event.entity.posZ);
    
    System.out.println("testrespawn");
    System.out.println(GuiDeath.mort);
    ChunkCoordinates biomeLocation = findClosestBlockOfBiome(player), BiomeGenBase.sky, 100);
    player.setLocationAndAngles(biomeLocation.posX, 250, biomeLocation.posZ, player.rotationYaw, player.rotationPitch);
    System.out.println("GuiDeath tp Cemetery");
    }
    }
    }
    }
    }
    

    C'est déjà plus propre comme ça.
    Après tu as un NPE, donc a mon avis il n'a trouvé le biome voulu dans la fonction findClosestBlockOfBiome.


Log in to reply