Résolu NPE / méthode onUpdate
-
Un NPE que je n’arrive pas à résoudre, pourtant je ne vois qu’un nullcheck à mettre, il y est et ça crash quand même ^^’
:::
package fr.powergame.modpg2.common; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class ItemPistolet extends Item { public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { if(stack.getTagCompound() == null) stack.setTagCompound(new NBTTagCompound()); if (stack.getTagCompound().getInteger("coolDown") == 0 && player.inventory.hasItem(ModPg2.itemBullet2)) { stack.getTagCompound().setInteger("coolDown", 40); EntityBulletThomson entityBulletThomson = new EntityBulletThomson(player.worldObj, player); player.worldObj.playSoundAtEntity(player, "modPg2:thomson", 0.5F, 1.5F); if(!player.capabilities.isCreativeMode) { player.inventory.consumeInventoryItem(ModPg2.itemBullet2); } if (!player.worldObj.isRemote) { player.worldObj.spawnEntityInWorld(entityBulletThomson); } } } public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { return stack; } public int getMaxItemUseDuration(ItemStack stack) { return 100; } public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { return true; } public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) { return true; } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); return stack; } public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean b) { int coolDown = stack.getTagCompound().getInteger("coolDown"); if(stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } if(stack.getTagCompound().getInteger("coolDown") > 0) { –coolDown; stack.getTagCompound().setInteger("coolDown", coolDown); } } public void writeToNBT(NBTTagCompound nbt) { nbt.setBoolean("onUse", false); nbt.setInteger("cooldDown", 0); } public void readFromNBT(NBTTagCompound nbt) { nbt.getBoolean("onUse"); nbt.getInteger("cooldDown"); } }
:::
:::
---- Minecraft Crash Report ---- // Everything's going to plan. No, really, that was supposed to happen. Time: 29/02/16 11:10 Description: Ticking player java.lang.NullPointerException: Ticking player at fr.powergame.modpg2.common.ItemPistolet.onUpdate(ItemPistolet.java:61) at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) 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.ItemPistolet.onUpdate(ItemPistolet.java:61) at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 45 Entity Name: Folgansky Entity's Exact location: 939,50, 4,00, 124,50 Entity's Block location: World: (939,4,124), Chunk: (at 11,0,12 in 58,7; contains blocks 928,0,112 to 943,255,127), Region: (1,0; contains chunks 32,0 to 63,31, blocks 512,0,0 to 1023,255,511) Entity's Momentum: 0,00, -0,08, 0,00 Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@4912cfe7 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) 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: 522391288 bytes (498 MB) / 635437056 bytes (606 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: 1 / 8; [EntityPlayerMP['Folgansky'/45, l='New World', x=939,50, y=4,00, z=124,50]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
:::
Je ne vois pas ce que le player vient faire là dedans surtout
-
public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean b) { if(!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } if(stack.getTagCompound().getInteger("coolDown") > 0) { stack.getTagCompound().setInteger("coolDown", stack.getTagCompound().getInteger("coolDown") - 1); } }
ça fonctionnera mieux comme ça.
-
Ah oui, merci robin.
Je tâcherai de retenir ce genre d’erreur…