I'm making a drone mod and I'm trying to make a console block that, when right clicked, searches for a nearby drone block. Whenever I right click the console block in game, the internal server crashes because of a null pointer exception at the first integer assignment ( int rX = playerIn.playerLocation.getX(); ). My code is as follows:
[embed=425,349] @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
BlockPos checkPos;
int rX = playerIn.playerLocation.getX();
int rY = playerIn.playerLocation.getY();
int rZ = playerIn.playerLocation.getZ();
for (int oX = -5; oX <= 5; oX++) {
for(int oY = -5; oY <= 5; oY++) {
for (int oZ = -5; oZ <= 5; oZ++) {
checkPos = new BlockPos(rX + oX,rY + oY,rZ + oZ);
if (worldIn.getBlockState(checkPos).getBlock().getMaterial()== DroneMaterials.drone)
{
playerIn.experienceLevel = 60;
return true;
}
}
}
}
return false;
}[/embed]
Stacktrace:
at nintolak.blocks.BlockConsole.func_180639_a(BlockConsole.java:37)
at net.minecraft.client.multiplayer.PlayerControllerMP.func_178890_a(PlayerControllerMP.java:381)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1483)
I have no idea why this is not working. Any help would be greatly appreciated.