Résolu Crash GUI + mob
-
Salut a tous je reviens quémander votre aide.
En effet, je veux que quand je tien un certain item dans la main ça ouvre un GUI et quand je n’est pas cet item, ça en ouvre un autre.
Comme vous vous en doutez j’ai un problème:
le jeu crash rien que quand je n’est pas l’item.
mes code:La méthode interract:
public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem(); EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer; if(this.isEntityAlive()) { if(!this.worldObj.isRemote) { if(player.getHeldItem().getItem() == CoeMobMain.quest) { FMLNetworkHandler.openGui(player, CoeMobMain.instance, 2, player.worldObj, (int)Math.floor(player.posX), (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); } if(player.getHeldItem().getItem() != CoeMobMain.quest || player.getHeldItem().getItem() == null) { FMLNetworkHandler.openGui(player, CoeMobMain.instance, 1, player.worldObj, (int)Math.floor(player.posX), (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); } } return true; } else { return super.interact(par1EntityPlayer); } }
Le GuiHandler:
public class GuiHandlerMob implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(ID) { case 1: return new GuiQuest(); case 2: return new GuiQuestAdmin(); default: return null; } } }
Le crash:
–-- Minecraft Crash Report ---- // Uh... Did I do that? Time: 18/05/14 17:00 Description: Ticking memory connection java.lang.NullPointerException at CoeMob.Mob.MobtestEntity.interact(MobtestEntity.java:45) at net.minecraft.entity.EntityLiving.interactFirst(EntityLiving.java:1158) at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1248) at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:846) at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:57) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at CoeMob.Mob.MobtestEntity.interact(MobtestEntity.java:45) at net.minecraft.entity.EntityLiving.interactFirst(EntityLiving.java:1158) at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1248) at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:846) at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:57) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) -- Ticking connection -- Details: Connection: net.minecraft.network.NetServerHandler@313ab540 Stacktrace: at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) -- System Details -- Details: Minecraft Version: 1.6.4 Operating System: Windows 8 (amd64) version 6.2 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 789642576 bytes (753 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 266 (14896 bytes; 0 MB) allocated, 21 (1176 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 12 mods loaded, 12 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 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 Profiler Position: N/A (disabled) Vec3 Pool Size: 15 (840 bytes; 0 MB) allocated, 7 (392 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player93'/1, l='CoeMob', x=1138,78, y=4,00, z=238,23]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
-
You must insert ```java
player.getHeldItem().getItem() != null -
no crash again…
if(this.isEntityAlive() && player.getHeldItem().getItem() != null)
-
Check if getHeldItem() isn’t null also (and before .getHeldItem().getItem() )
-
c’est pourtant ce que je fait jg
-
Salut,
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
Pas bon. Tu as déjà le paramètre player …
public boolean interact(EntityPlayer par1EntityPlayer)
Suffit de renommer par1EntityPlayer par player.getHeldItem() ? c’est pour avoir le casque. getCurrentEquippedItem() plutôt. Et il faut check si l’item stack n’est pas null :
if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == CoeMobMain.quest) -
ca crash plus mais plus rien ne se passe…
public boolean interact(EntityPlayer player) { ItemStack itemstack = player.inventory.getCurrentItem(); if(this.isEntityAlive()) { if(!this.worldObj.isRemote) { if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == CoeMobMain.quest) { FMLNetworkHandler.openGui(player, CoeMobMain.instance, 2, player.worldObj, (int)Math.floor(player.posX), (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); } if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() != CoeMobMain.quest) { FMLNetworkHandler.openGui(player, CoeMobMain.instance, 1, player.worldObj, (int)Math.floor(player.posX), (int)Math.floor(player.posY), (int)Math.floor(player.posZ)); } } return true; } else { return super.interact(player); } }