Résolu Erreur lors du cassage de blocs
-
Bonjour j’ai un problème très bizarre puisque dés que je casse une tête de squelette au sol, le jeu crash avec cette erreur:
http://pastebin.com/9zMr72ZeEt voici le code qui correspond je pense!:
[font=Courier New@SubscribeEvent ]public void smeltBlockWithFirePickaxe(BlockEvent.HarvestDropsEvent event) { int quantityMultiplier%(#cc7832)[; ] EntityPlayer entityPlayer = event.harvester%(#cc7832)[; ] Block block = event.block%(#cc7832)[; ] if(entityPlayer.inventory.hasItem(IceNFire.*wandExtendCapture*) || entityPlayer.inventory.hasItem(IceNFire.*wandOfCapture*)) quantityMultiplier = 2%(#cc7832)[; ]%(#cc7832)[ else ] quantityMultiplier = 1%(#cc7832)[; ] if(entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.*firePickaxe*) { if(block == Blocks.*iron_ore*) { event.drops.remove(0)%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*iron_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*gold_ore*) { event.drops.remove(0)%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*gold_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*fireOre*) { event.drops.remove(0)%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*fireIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*iceOre*) { event.drops.remove(0)%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*iceIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*stone *|| block == Blocks.*cobblestone*) { event.drops.remove(0)%(#cc7832)[; ] event.drops.add(new ItemStack(Blocks.*stone*, 1))%(#cc7832)[; ] } } }
-
dès que je casse une tête de squelette ou dès que tu casse n’importe quel bloc sans avoir d’item en main ?
La ligne 28 de ta classe je suppose que celle-ci :
if(entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.firePickaxe)
?
Il te manque un null check, entityPlayer.inventory.getCurrentItem() est null si le joueur n’a rien en main donc faire un .getItem() cause un NPE (NullPointerException)
Solution :
if(entityPlayer.inventory.getCurrentItem() != null && entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.firePickaxe) -
Merci pour la réponse, à la ligne 28 j’ai:
%(#a9b7c6)[[font=Courier New]if](entityPlayer.%(#9876aa)[inventory].hasItem(IceNFire.%(#9876aa)[*wandExtendCapture*]) || entityPlayer.%(#9876aa)[inventory].hasItem(IceNFire.%(#9876aa)[*wandOfCapture*]))
et j’ai modifié
%(#a9b7c6)[[font=Courier New]if](entityPlayer.%(#9876aa)[inventory].getCurrentItem().getItem() == IceNFire.%(#9876aa)[*firePickaxe*])
en
%(#a9b7c6)[[font=Courier New]if](entityPlayer.%(#9876aa)[inventory].getCurrentItem() != %(#cc7832)[null ]&& entityPlayer.%(#9876aa)[inventory].getCurrentItem().getItem() == IceNFire.%(#9876aa)[*firePickaxe*])
Mais ça n’a rien changé
Et seulement quand je casse une tête de squelette avec ou rien en main c’est pareil
Et je remarque que ça me fait pareille si je casse le bloc en dessous d’une herbe ou d’un panneau. -
Dans ce cas le NPE est sur la ligne :
if(entityPlayer.inventory.hasItem(IceNFire.wandExtendCapture) || entityPlayer.inventory.hasItem(IceNFire.wandOfCapture))
Maintenant faut trouver quel objet est null.
Modifies ton code comme ça :if(entityPlayer. inventory. hasItem(IceNFire. wandExtendCapture) || entityPlayer. inventory. hasItem(IceNFire. wandOfCapture))
Et dit moi sur quelle ligne exactement il y a le NPE avec cette modification.
-
essaye de faire drops.clear() au lieu du remove j ai eu des NPE aussi avec cette methode
-
Voici mon nouveau code:
java.lang.NullPointerException: Ticking memory connection at com.plasmania.icenfire.events.FMLEventHandler.smeltBlockWithFirePickaxe(FMLEventHandler.java:28) at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_FMLEventHandler_smeltBlockWithFirePickaxe_HarvestDropsEvent.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.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:155) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockSkull.onBlockHarvested(BlockSkull.java:155) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:269) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:263) at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:304) at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:168) at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:523) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94) 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)
-
Le code ne correspond pas : ligne 28 tu n’as aucune référence à un objet, même si entityPlayer est null, le problème serai à la ligne 29.
Renvoi la fonction entière et le crash report correspondant.
-
Voici le code de la ligne 1 à la ligne 67(sur mon IDE)
[font=Courier Newpackage ]com.plasmania.icenfire.events%(#cc7832)[; ] import com.plasmania.icenfire.IceNFire%(#cc7832)[; ]import cpw.mods.fml.common.eventhandler.SubscribeEvent%(#cc7832)[; ]import cpw.mods.fml.common.gameevent.PlayerEvent%(#cc7832)[; ]import net.minecraft.block.Block%(#cc7832)[; ]import net.minecraft.entity.player.EntityPlayer%(#cc7832)[; ]import net.minecraft.init.Blocks%(#cc7832)[; ]import net.minecraft.init.Items%(#cc7832)[; ]import net.minecraft.item.Item%(#cc7832)[; ]import net.minecraft.item.ItemStack%(#cc7832)[; ]import net.minecraft.item.crafting.FurnaceRecipes%(#cc7832)[; ]import net.minecraftforge.event.world.BlockEvent%(#cc7832)[; ] %(#629755)[*/** *]%(#629755)[* * ProjectName: Ice N' Fire *]%(#629755)[* * Created by PlasMania on 29/07/2015 at 15:08. *]%(#629755)[* */ *]public class FMLEventHandler { %(#bbb529)[@SubscribeEvent ] public void smeltBlockWithFirePickaxe(BlockEvent.HarvestDropsEvent event) { int quantityMultiplier%(#cc7832)[; ] EntityPlayer entityPlayer = event.harvester%(#cc7832)[; ] Block block = event.block%(#cc7832)[; ] if(entityPlayer. inventory. hasItem(IceNFire. *wandExtendCapture*) || entityPlayer .inventory. hasItem(IceNFire. *wandOfCapture*)) quantityMultiplier = 2%(#cc7832)[; ]%(#cc7832)[ else ] quantityMultiplier = 1%(#cc7832)[; ] if(entityPlayer.inventory.getCurrentItem() != null && entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.*firePickaxe*) { if(block == Blocks.*iron_ore*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*iron_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*gold_ore*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*gold_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*fireOre*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*fireIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*iceOre*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*iceIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*stone *|| block == Blocks.*cobblestone*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Blocks.*stone*, 1))%(#cc7832)[; ] } } }
Et voici le crash report entier:
–-- Minecraft Crash Report ---- // Would you like a cupcake? Time: 01/08/15 23:31 Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at com.plasmania.icenfire.events.FMLEventHandler.smeltBlockWithFirePickaxe(FMLEventHandler.java:28) at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_FMLEventHandler_smeltBlockWithFirePickaxe_HarvestDropsEvent.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.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:155) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockSkull.onBlockHarvested(BlockSkull.java:155) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:269) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:263) at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:304) at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:168) at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:523) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94) 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 com.plasmania.icenfire.events.FMLEventHandler.smeltBlockWithFirePickaxe(FMLEventHandler.java:28) at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_FMLEventHandler_smeltBlockWithFirePickaxe_HarvestDropsEvent.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.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:155) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockSkull.onBlockHarvested(BlockSkull.java:155) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:269) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:263) at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:304) at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:168) at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:523) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@2527b509 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.7.0_80, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 724877920 bytes (691 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M 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 icenfire{1.0} [Ice N' Fire] (Ice N' Fire) 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['Player469'/25, l='New World', x=-562,50, y=4,00, z=-1026,50]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
-
Mets les points sur une nouvelle ligne (avec la variable) comme ceci :
entityplayer
.inventoryet renvoi le crash report donné.
-
–-- Minecraft Crash Report ---- // Daisy, daisy... Time: 01/08/15 23:38 Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at com.plasmania.icenfire.events.FMLEventHandler.smeltBlockWithFirePickaxe(FMLEventHandler.java:28) at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_FMLEventHandler_smeltBlockWithFirePickaxe_HarvestDropsEvent.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.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:155) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockSkull.onBlockHarvested(BlockSkull.java:155) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:269) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:263) at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:304) at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:168) at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:523) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94) 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 com.plasmania.icenfire.events.FMLEventHandler.smeltBlockWithFirePickaxe(FMLEventHandler.java:28) at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_FMLEventHandler_smeltBlockWithFirePickaxe_HarvestDropsEvent.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.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:155) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockSkull.onBlockHarvested(BlockSkull.java:155) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:269) at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:263) at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:304) at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:168) at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:523) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61) at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@451780fc 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.7.0_80, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 715461376 bytes (682 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M 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 icenfire{1.0} [Ice N' Fire] (Ice N' Fire) 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['Player80'/25, l='New World', x=-562,50, y=4,00, z=-1026,50]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
-
J’ai essayé de retirer la condition du coup j’obtient ce code:
Cependant j’obtient toujours une erreur à la ligne n°28.[font=Courier Newpackage ]com.plasmania.icenfire.events%(#cc7832)[; ] import com.plasmania.icenfire.IceNFire%(#cc7832)[; ]import cpw.mods.fml.common.eventhandler.SubscribeEvent%(#cc7832)[; ]import cpw.mods.fml.common.gameevent.PlayerEvent%(#cc7832)[; ]import net.minecraft.block.Block%(#cc7832)[; ]import net.minecraft.entity.player.EntityPlayer%(#cc7832)[; ]import net.minecraft.init.Blocks%(#cc7832)[; ]import net.minecraft.init.Items%(#cc7832)[; ]import net.minecraft.item.Item%(#cc7832)[; ]import net.minecraft.item.ItemStack%(#cc7832)[; ]import net.minecraft.item.crafting.FurnaceRecipes%(#cc7832)[; ]import net.minecraftforge.event.world.BlockEvent%(#cc7832)[; ] %(#629755)[*/** *]%(#629755)[* * ProjectName: Ice N' Fire *]%(#629755)[* * Created by PlasMania on 29/07/2015 at 15:08. *]%(#629755)[* */ *]public class FMLEventHandler { %(#bbb529)[@SubscribeEvent ] public void smeltBlockWithFirePickaxe(BlockEvent.HarvestDropsEvent event) { int quantityMultiplier = 1%(#cc7832)[; ] EntityPlayer entityPlayer = event.harvester%(#cc7832)[; ] Block block = event.block%(#cc7832)[; ] if(entityPlayer.inventory.getCurrentItem() != null && entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.*firePickaxe*) { if(block == Blocks.*iron_ore*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*iron_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*gold_ore*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Items.*gold_ingot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*fireOre*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*fireIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == IceNFire.*iceOre*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(IceNFire.*iceIngot*, 1 * quantityMultiplier))%(#cc7832)[; ] } else if(block == Blocks.*stone *|| block == Blocks.*cobblestone*) { event.drops.clear()%(#cc7832)[; ] event.drops.add(new ItemStack(Blocks.*stone*, 1))%(#cc7832)[; ] } }[font=Courier New}]
-
Ta variable entityPlayer semble être null.
Donc event.harvester l’est aussi, je fais regarder vite fait. -
Eh bien, j’ai rajouter un
if(entityPlayer != null)Et ca s’emble marché
-
Ok parfait. Mais c’est quand même étrange que le joueur est null.
-
robin, je me permet de rebondir, car j’ai remarquer un bug similaire sur les condition du type :
if(entityPlayer.inventory.getCurrentItem() != null && entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.firePickaxe)
J’ai personnellement était constamment obliger de séparer en deux condition distincte (d’abord vérifier si c’est null, et si ça ne l’est pas faire un second bloque condition avec la bonne condition) :
if(entityPlayer.inventory.getCurrentItem() != null) { if(entityPlayer.inventory.getCurrentItem().getItem() == IceNFire.firePickaxe) { // ici les fonction } }
-
Les deux reviennent au même.
-
A l’exception que j’avais systématique un crash avec la premier méthode… Eclipse semblais effectuer les deux opérations séparement, puis vérifier le “ET” après, du coup il plantais comme il tentai de vérifier une variable null.
Ça pourra peu être dépanner quelqu’un si il ont un crash similaire ^^
-
Normalement non. Le code une fois compilé est sous la forme d’instructions qui se suivent, dans une condition s’il n’y a que des && et que la première condition est fausse, il passe directement à la suite.