Jump to content

[SOLVED][1.7.10] How to check if entity is a zombie or spider etc ?


MrAlexan14

Recommended Posts

Hi guys.

I'm learning modding and I want to check, in the event AttackEntityEvent, if the target is a Zombie or any munster else.

Here's my code :

package com.mralexan.sapphiremod;

import ibxm.Player;

import com.mralexan.sapphiremod.initializers.SapphireItems;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent.Start;

public class SapphireEventHandler
{
@SubscribeEvent
public void checkUpdate(PlayerEvent.PlayerLoggedInEvent event)
{
	System.out.println(event.player.getDisplayName() + " just joined the game !");
}

@SubscribeEvent
public void playerAttackZombie(AttackEntityEvent event)
{	
	if(event.entityPlayer.getHeldItem().getItem().equals(SapphireItems.sapphireSceptre))
	{
		if(event.target.isCreatureType(EnumCreatureType.monster, false))
		{
			System.out.println("Target is a munster: " + EnumCreatureType.monster.getCreatureClass().getTypeName() + "!");
			event.target.setFire(10);
		}
		else if(event.target.isCreatureType(EnumCreatureType.creature, false))
		{
			System.out.println("Target is a créature: " + EnumCreatureType.monster.getCreatureClass().getTypeName() + "!");
		}
	}
	else if(event.entityPlayer.getHeldItem().getItem().equals(SapphireItems.sapphireSword))
	{
	}
}
}

As you can read, my code just say if the target is a munster or a creature (animal I think).

So, do you know how I can check if the target is a NPC or a zombie etc ?

 

 

Tahnks

Link to comment
Share on other sites

Thanks a lot, it works. I don't remember about intanceof.

But I've another problem with this event...

I'm checking if the player has a specific item in hand but when I'm hitting a sheepp, it crashs... Here's my code

@SubscribeEvent
   public void playerAttackMob(AttackEntityEvent event)
   {   
      if(event.entityPlayer.getHeldItem().getItem().equals(new ItemStack(SapphireItems.sapphireSceptre)))
      {
         System.out.println("Test");
      }
   }

And the crash log :

[19:26:24] [main/INFO] [GradleStart]: Extra: []
[19:26:24] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --assetsDir, C:/Users/Alexandre/.gradle/caches/minecraft/assets, --assetIndex, 1.7.10, --accessToken, {REDACTED}, --version, 1.7.10, --tweakClass, cpw.mods.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker]
[19:26:24] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker
[19:26:24] [main/INFO] [FML]: Forge Mod Loader version 7.10.85.1230 for Minecraft 1.7.10 loading
[19:26:24] [main/INFO] [FML]: Java is Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_25, running on Windows 7:amd64:6.1, installed at C:\Program Files\Java\jre1.8.0_25
[19:26:24] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
[19:26:24] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker
[19:26:24] [main/INFO] [GradleStart]: Injecting location in coremod cpw.mods.fml.relauncher.FMLCorePlugin
[19:26:24] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin
[19:26:24] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[19:26:24] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
[19:26:24] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
[19:26:26] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
[19:26:26] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
[19:26:26] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLDeobfTweaker
[19:26:27] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.TerminalTweaker
[19:26:27] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.TerminalTweaker
[19:26:27] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
[19:26:27] [main/INFO]: Setting user: Player260
[19:26:28] [Client thread/INFO]: LWJGL Version: 2.9.1
[19:26:29] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization
[19:26:29] [Client thread/INFO] [FML]: MinecraftForge v10.13.2.1230 Initialized
[19:26:29] [Client thread/INFO] [FML]: Replaced 182 ore recipies
[19:26:29] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization
[19:26:29] [Client thread/INFO] [FML]: Searching C:\Users\Alexandre\Documents\Programmation\Java\Modding minecraft\SaphirMod\eclipse\mods for mods
[19:26:31] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load
[19:26:31] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, sapphiremod] at CLIENT
[19:26:31] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, sapphiremod] at SERVER
[19:26:32] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Sapphire Mod
[19:26:32] [Client thread/INFO] [FML]: Processing ObjectHolder annotations
[19:26:32] [Client thread/INFO] [FML]: Found 341 ObjectHolder annotations
[19:26:32] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
[19:26:32] [Client thread/INFO] [sTDOUT]: [com.mralexan.sapphiremod.Sapphire:preInit:58]: [sAPPHIREMOD] Side : CLIENT
[19:26:32] [Client thread/INFO] [FML]: Applying holder lookups
[19:26:32] [Client thread/INFO] [FML]: Holder lookups applied
[19:26:32] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:32] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem...
[19:26:32] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL
[19:26:32] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[19:26:32] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.
[19:26:33] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:33] [sound Library Loader/INFO]: Sound engine started
[19:26:34] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas
[19:26:34] [Client thread/INFO]: Created: 256x256 textures/items-atlas
[19:26:34] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 4 mods
[19:26:34] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Sapphire Mod
[19:26:35] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas
[19:26:35] [Client thread/INFO]: Created: 256x256 textures/items-atlas
[19:26:35] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:35] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: SoundSystem shutting down...
[19:26:35] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:importantMessage:90]:     Author: Paul Lamb, www.paulscode.com
[19:26:35] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:35] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:35] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem...
[19:26:35] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL
[19:26:35] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[19:26:35] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.
[19:26:36] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
[19:26:36] [sound Library Loader/INFO]: Sound engine started
[19:26:39] [server thread/INFO]: Starting integrated minecraft server version 1.7.10
[19:26:39] [server thread/INFO]: Generating keypair
[19:26:39] [server thread/INFO] [FML]: Injecting existing block and item data into this server instance
[19:26:39] [server thread/INFO] [FML]: Applying holder lookups
[19:26:39] [server thread/INFO] [FML]: Holder lookups applied
[19:26:39] [server thread/INFO] [FML]: Loading dimension 0 (Copie de Copie de Copie de Nouve) (net.minecraft.server.integrated.IntegratedServer@13af51b4)
[19:26:39] [server thread/INFO] [FML]: Loading dimension 1 (Copie de Copie de Copie de Nouve) (net.minecraft.server.integrated.IntegratedServer@13af51b4)
[19:26:39] [server thread/INFO] [FML]: Loading dimension -1 (Copie de Copie de Copie de Nouve) (net.minecraft.server.integrated.IntegratedServer@13af51b4)
[19:26:39] [server thread/INFO]: Preparing start region for level 0
[19:26:40] [server thread/INFO]: Changing view distance to 12, from 10
[19:26:41] [Netty Client IO #0/INFO] [FML]: Server protocol version 1
[19:26:41] [Netty IO #1/INFO] [FML]: Client protocol version 1
[19:26:41] [Netty IO #1/INFO] [FML]: Client attempting to join with 4 mods : [email protected],[email protected],[email protected],[email protected]
[19:26:41] [Netty IO #1/INFO] [FML]: Attempting connection with missing mods [] at CLIENT
[19:26:41] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [] at SERVER
[19:26:41] [Client thread/INFO] [FML]: [Client thread] Client side modded connection established
[19:26:41] [server thread/INFO] [FML]: [server thread] Server side modded connection established
[19:26:41] [server thread/INFO]: Player260[local:E:1d4d01ca] logged in with entity id 84 at (-33.414536546438924, 70.0, 334.03863472101443)
[19:26:41] [server thread/INFO]: Player260 a rejoint la partie
[19:26:41] [server thread/INFO] [sTDOUT]: [com.mralexan.sapphiremod.events.SapphireEventHandler:checkUpdate:31]: Player260 just joined the game !
[19:26:43] [Client thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.player.AttackEntityEvent@130901fd:
java.lang.NullPointerException
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37) ~[sapphireEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.invoke(.dynamic) ~[?:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?]
    at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339) [EntityPlayer.class:?]
    at net.minecraft.client.multiplayer.PlayerControllerMP.attackEntity(PlayerControllerMP.java:462) [PlayerControllerMP.class:?]
    at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1464) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:2028) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
    at GradleStart.main(GradleStart.java:45) [start/:?]
[19:26:43] [Client thread/ERROR] [FML]: Index: 1 Listeners:
[19:26:43] [Client thread/ERROR] [FML]: 0: NORMAL
[19:26:43] [Client thread/ERROR] [FML]: 1: ASM: com.mralexan.sapphiremod.events.SapphireEventHandler@17fa25f1 playerAttackMob(Lnet/minecraftforge/event/entity/player/AttackEntityEvent;)V
[19:26:43] [server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.player.AttackEntityEvent@7220dcf3:
java.lang.NullPointerException
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37) ~[sapphireEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.invoke(.dynamic) ~[?:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?]
    at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339) [EntityPlayer.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:881) [NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51) [C02PacketUseEntity.class:?]
    at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69) [C02PacketUseEntity.class:?]
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
[19:26:43] [server thread/ERROR] [FML]: Index: 1 Listeners:
[19:26:43] [server thread/ERROR] [FML]: 0: NORMAL
[19:26:43] [server thread/ERROR] [FML]: 1: ASM: com.mralexan.sapphiremod.events.SapphireEventHandler@17fa25f1 playerAttackMob(Lnet/minecraftforge/event/entity/player/AttackEntityEvent;)V
[19:26:43] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking memory connection
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37) ~[sapphireEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.invoke(.dynamic) ~[?:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]
    at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339) ~[EntityPlayer.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:881) ~[NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51) ~[C02PacketUseEntity.class:?]
    at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69) ~[C02PacketUseEntity.class:?]
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?]
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
    ... 5 more
[19:26:43] [server thread/ERROR]: This crash report has been saved to: C:\Users\Alexandre\Documents\Programmation\Java\Modding minecraft\SaphirMod\eclipse\.\crash-reports\crash-2015-01-28_19.26.43-server.txt
[19:26:43] [server thread/INFO]: Stopping server
[19:26:43] [server thread/INFO]: Saving players
[19:26:43] [server thread/INFO]: Saving worlds
[19:26:43] [server thread/INFO]: Saving chunks for level 'Copie de Copie de Copie de Nouve'/Overworld
[19:26:43] [server thread/INFO]: Saving chunks for level 'Copie de Copie de Copie de Nouve'/Nether
[19:26:43] [server thread/INFO]: Saving chunks for level 'Copie de Copie de Copie de Nouve'/The End
[19:26:43] [server thread/INFO] [FML]: Unloading dimension 0
[19:26:43] [server thread/INFO] [FML]: Unloading dimension -1
[19:26:43] [server thread/INFO] [FML]: Unloading dimension 1
[19:26:43] [server thread/INFO] [FML]: Applying holder lookups
[19:26:43] [server thread/INFO] [FML]: Holder lookups applied
[19:26:43] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[19:26:44] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37) ~[sapphireEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.invoke(.dynamic) ~[?:?]
    at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
    at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]
    at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339) ~[EntityPlayer.class:?]
    at net.minecraft.client.multiplayer.PlayerControllerMP.attackEntity(PlayerControllerMP.java:462) ~[PlayerControllerMP.class:?]
    at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1464) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:2028) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
    at GradleStart.main(GradleStart.java:45) [start/:?]
[19:26:44] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----
// On the bright side, I bought you a teddy bear!

Time: 28/01/15 19:26
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37)
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.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.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339)
    at net.minecraft.client.multiplayer.PlayerControllerMP.attackEntity(PlayerControllerMP.java:462)
    at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1464)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:2028)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)
    at net.minecraft.client.Minecraft.run(Minecraft.java:951)
    at net.minecraft.client.main.Main.main(Main.java:164)
    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:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
    at GradleStart.main(GradleStart.java:45)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
    at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:37)
    at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.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.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1339)
    at net.minecraft.client.multiplayer.PlayerControllerMP.attackEntity(PlayerControllerMP.java:462)
    at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1464)

-- Affected level --
Details:
    Level name: MpServer
    All players: 1 total; [EntityClientPlayerMP['Player260'/84, l='MpServer', x=-33,41, y=71,62, z=334,04]]
    Chunk stats: MultiplayerChunkCache: 165, 165
    Level seed: 0
    Level generator: ID 00 - default, ver 1. Features enabled: false
    Level generator options: 
    Level spawn location: World: (244,64,252), Chunk: (at 4,4,12 in 15,15; contains blocks 240,0,240 to 255,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 53361 game time, 53361 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: 96 total; [EntitySkeleton['Squelette'/128, l='MpServer', x=-79,06, y=11,10, z=281,53], EntityCreeper['Creeper'/129, l='MpServer', x=-7,38, y=21,10, z=281,78], EntityCreeper['Creeper'/130, l='MpServer', x=-4,31, y=20,10, z=280,25], EntityCreeper['Creeper'/131, l='MpServer', x=-4,88, y=20,10, z=279,31], EntitySkeleton['Squelette'/132, l='MpServer', x=-3,94, y=21,10, z=282,53], EntitySkeleton['Squelette'/133, l='MpServer', x=10,69, y=35,10, z=296,44], EntitySkeleton['Squelette'/134, l='MpServer', x=10,09, y=34,10, z=297,31], EntityZombie['Zombie'/135, l='MpServer', x=16,00, y=45,10, z=292,53], EntityBat['Chauve-souris'/136, l='MpServer', x=33,48, y=21,50, z=331,72], EntityZombie['Zombie'/137, l='MpServer', x=-32,40, y=49,84, z=394,85], EntityCreeper['Creeper'/138, l='MpServer', x=-59,00, y=37,10, z=393,00], EntityCreeper['Creeper'/139, l='MpServer', x=-108,91, y=9,10, z=343,31], EntityZombie['Zombie'/140, l='MpServer', x=-103,78, y=19,10, z=344,66], EntityZombie['Zombie'/141, l='MpServer', x=-111,50, y=18,10, z=339,50], EntitySkeleton['Squelette'/142, l='MpServer', x=-110,53, y=26,10, z=349,88], EntityZombie['Zombie'/143, l='MpServer', x=-110,03, y=20,10, z=343,50], EntitySheep['Mouton'/144, l='MpServer', x=-25,47, y=26,10, z=264,13], EntityBat['Chauve-souris'/145, l='MpServer', x=-22,84, y=17,97, z=260,01], EntityCreeper['Creeper'/146, l='MpServer', x=-20,72, y=51,10, z=262,84], EntitySheep['Mouton'/147, l='MpServer', x=-21,81, y=67,10, z=264,84], EntitySkeleton['Squelette'/148, l='MpServer', x=26,09, y=18,10, z=316,47], EntityBat['Chauve-souris'/149, l='MpServer', x=19,50, y=20,10, z=346,13], EntityBat['Chauve-souris'/150, l='MpServer', x=29,98, y=25,89, z=351,60], EntityCow['Vache'/151, l='MpServer', x=29,97, y=65,10, z=347,53], EntityCreeper['Creeper'/152, l='MpServer', x=-28,97, y=48,10, z=391,69], EntityZombie['Zombie'/153, l='MpServer', x=-30,28, y=48,10, z=389,78], EntityBat['Chauve-souris'/154, l='MpServer', x=-80,25, y=17,10, z=285,75], EntitySquid['Poulpe'/155, l='MpServer', x=-95,92, y=49,21, z=287,32], EntitySkeleton['Squelette'/156, l='MpServer', x=6,97, y=46,10, z=282,69], EntityBat['Chauve-souris'/157, l='MpServer', x=4,90, y=16,61, z=378,32], EntitySquid['Poulpe'/158, l='MpServer', x=-77,84, y=53,76, z=393,75], EntityBat['Chauve-souris'/159, l='MpServer', x=-108,25, y=14,10, z=357,75], EntitySkeleton['Squelette'/160, l='MpServer', x=-110,61, y=36,80, z=356,69], EntitySkeleton['Squelette'/161, l='MpServer', x=-107,50, y=35,10, z=360,22], EntitySpider['Araignée'/162, l='MpServer', x=-111,40, y=36,73, z=355,14], EntitySkeleton['Squelette'/165, l='MpServer', x=30,31, y=22,10, z=295,63], EntityZombie['Zombie'/166, l='MpServer', x=24,41, y=45,10, z=290,00], EntityZombie['Zombie'/167, l='MpServer', x=16,94, y=45,10, z=293,25], EntityBat['Chauve-souris'/168, l='MpServer', x=24,52, y=16,95, z=362,04], EntityBat['Chauve-souris'/169, l='MpServer', x=29,47, y=15,81, z=366,86], EntityCow['Vache'/170, l='MpServer', x=24,03, y=66,10, z=362,88], EntitySquid['Poulpe'/171, l='MpServer', x=-87,41, y=47,30, z=395,58], EntitySquid['Poulpe'/172, l='MpServer', x=-91,06, y=47,31, z=399,63], EntitySquid['Poulpe'/173, l='MpServer', x=-91,25, y=50,95, z=393,87], EntitySquid['Poulpe'/174, l='MpServer', x=-83,90, y=55,42, z=394,27], EntitySquid['Poulpe'/175, l='MpServer', x=-88,27, y=52,36, z=396,47], EntityClientPlayerMP['Player260'/84, l='MpServer', x=-33,41, y=71,62, z=334,04], EntitySquid['Poulpe'/176, l='MpServer', x=-81,85, y=49,14, z=394,43], EntitySquid['Poulpe'/177, l='MpServer', x=-83,23, y=53,03, z=391,42], EntityCreeper['Creeper'/178, l='MpServer', x=-104,50, y=22,10, z=279,50], EntitySquid['Poulpe'/185, l='MpServer', x=-97,75, y=50,31, z=283,18], EntityZombie['Zombie'/187, l='MpServer', x=29,50, y=31,10, z=272,50], EntitySkeleton['Squelette'/188, l='MpServer', x=34,31, y=18,10, z=328,25], EntityPig['Cochon'/85, l='MpServer', x=-37,84, y=69,00, z=329,59], EntitySheep['Mouton'/86, l='MpServer', x=-35,03, y=69,00, z=331,34], EntityCreeper['Creeper'/87, l='MpServer', x=-58,30, y=9,42, z=328,30], EntitySkeleton['Squelette'/88, l='MpServer', x=-60,50, y=20,00, z=335,50], EntityChicken['Poule'/89, l='MpServer', x=-58,56, y=67,82, z=325,31], EntityBat['Chauve-souris'/90, l='MpServer', x=-39,72, y=56,10, z=304,25], EntitySkeleton['Squelette'/91, l='MpServer', x=-35,50, y=52,00, z=312,56], EntitySkeleton['Squelette'/92, l='MpServer', x=-38,69, y=53,00, z=308,06], EntityZombie['Zombie'/93, l='MpServer', x=-32,26, y=52,71, z=317,17], EntityChicken['Poule'/94, l='MpServer', x=-38,16, y=65,00, z=311,72], EntityCow['Vache'/95, l='MpServer', x=-39,50, y=65,00, z=316,50], EntityPig['Cochon'/96, l='MpServer', x=-49,44, y=63,03, z=338,31], EntityCreeper['Creeper'/97, l='MpServer', x=-59,53, y=61,00, z=320,00], EntitySheep['Mouton'/98, l='MpServer', x=-50,81, y=63,03, z=305,84], EntityPig['Cochon'/99, l='MpServer', x=-57,03, y=67,03, z=312,97], EntitySheep['Mouton'/100, l='MpServer', x=-29,09, y=66,03, z=306,13], EntityXPOrb['Orbe d'expérience'/101, l='MpServer', x=-31,78, y=63,56, z=342,78], EntityPig['Cochon'/102, l='MpServer', x=-72,50, y=66,03, z=325,75], EntityChicken['Poule'/103, l='MpServer', x=-73,06, y=65,81, z=328,16], EntitySkeleton['Squelette'/104, l='MpServer', x=-38,56, y=53,10, z=303,88], EntityBat['Chauve-souris'/105, l='MpServer', x=-37,38, y=58,10, z=303,16], EntityBat['Chauve-souris'/106, l='MpServer', x=-58,56, y=13,58, z=356,33], EntityCreeper['Creeper'/107, l='MpServer', x=-52,53, y=32,10, z=363,66], EntitySkeleton['Squelette'/108, l='MpServer', x=-70,50, y=25,10, z=343,50], EntitySkeleton['Squelette'/109, l='MpServer', x=-75,22, y=25,10, z=346,69], EntityCreeper['Creeper'/110, l='MpServer', x=-74,69, y=33,10, z=315,69], EntitySpider['Araignée'/111, l='MpServer', x=-70,06, y=35,10, z=311,00], EntityChicken['Poule'/112, l='MpServer', x=-54,44, y=62,83, z=294,36], EntitySheep['Mouton'/113, l='MpServer', x=-26,81, y=37,10, z=293,75], EntitySheep['Mouton'/114, l='MpServer', x=-29,53, y=37,10, z=293,38], EntityZombie['Zombie'/115, l='MpServer', x=-3,50, y=41,10, z=305,50], EntitySkeleton['Squelette'/116, l='MpServer', x=-11,31, y=23,95, z=292,69], EntityZombie['Zombie'/117, l='MpServer', x=-89,50, y=37,10, z=324,50], EntityZombie['Zombie'/118, l='MpServer', x=-37,50, y=15,10, z=275,50], EntityPig['Cochon'/119, l='MpServer', x=-56,75, y=61,10, z=371,09], EntitySkeleton['Squelette'/120, l='MpServer', x=-80,69, y=23,46, z=351,69], EntityCreeper['Creeper'/121, l='MpServer', x=-60,59, y=52,10, z=282,22], EntitySheep['Mouton'/122, l='MpServer', x=-17,47, y=34,10, z=281,56], EntityBat['Chauve-souris'/123, l='MpServer', x=-23,75, y=47,10, z=279,97], EntityCreeper['Creeper'/124, l='MpServer', x=-16,50, y=43,10, z=274,53], EntitySpider['Araignée'/125, l='MpServer', x=-28,72, y=36,78, z=279,03], EntityCow['Vache'/126, l='MpServer', x=4,69, y=63,10, z=341,50], EntitySquid['Poulpe'/127, l='MpServer', x=-88,03, y=53,34, z=289,31]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)
    at net.minecraft.client.Minecraft.run(Minecraft.java:980)
    at net.minecraft.client.main.Main.main(Main.java:164)
    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:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
    at GradleStart.main(GradleStart.java:45)

-- System Details --
Details:
    Minecraft Version: 1.7.10
    Operating System: Windows 7 (amd64) version 6.1
    Java Version: 1.8.0_25, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 754720872 bytes (719 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: 13, tallocated: 95
    FML: MCP v9.05 FML v7.10.85.1230 Minecraft Forge 10.13.2.1230 4 mods loaded, 4 mods active
    mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    FML{7.10.85.1230} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Forge{10.13.2.1230} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    sapphiremod{1.0} [sapphire Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Launched Version: 1.7.10
    LWJGL: 2.9.1
    OpenGL: AMD Radeon HD 7800 Series GL version 4.4.13283 Compatibility Profile Context 14.501.1003.0, ATI Technologies Inc.
    GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Packs: []
    Current Language: Français (France)
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    Anisotropic Filtering: Off (1)
[19:26:44] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:398]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\Alexandre\Documents\Programmation\Java\Modding minecraft\SaphirMod\eclipse\.\crash-reports\crash-2015-01-28_19.26.44-client.txt
AL lib: (EE) alc_cleanup: 1 device not closed
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

Link to comment
Share on other sites

Couple problems:

 

What happens if the player isn't holding anything (

event.entityPlayer.getHeldItem()

will be null and you're trying to access it)

Secondly, that's not how you compare items.  You get the Item from the ItemStack and then compare it to an ItemStack.  That will never be true.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes, I tried to add ItemStack (I was thinking that I could make a mistake of reading, but I checked for an item before :

if(event.entityPlayer.getHeldItem().getItem().equals(SapphireItems.sapphireSceptre))

and it was not a reading mistake)

So, you're right, the game crash when I'm holding nothing... But how can I check if the player's hand is empty ?

Link to comment
Share on other sites

if(event.entityPlayer.getHeldItem() == null)

 

Duh

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oh yes... Of course, it's child's play.

 

Yes, yes it is.  Standard null check.

 

Thanks a lot and have a nice week

 

You too.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.