Jump to content

Character Location NullPointerException


Nintolak

Recommended Posts

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.

Link to comment
Share on other sites

Upon further testing I've discovered that the issue is with the getX() and not the playerLocation. This makes no sense because playerLocation is an instance of BlockPos which extends Vec3i which has a getX() method. So if I am able to get the playerLocation I should be able to get the X coordinate of that location. Any ideas friends?

Link to comment
Share on other sites

Wait playerIn is my character because my testing was based off of changing playerIn.experienceLevel, which I was able to do successfully. So my character just has a null playerLocation... for some reason.

Link to comment
Share on other sites

My problem has been fixed. As far as I can tell the playerLocation field in the EntityPlayer class is never used at all in Minecraft. I got a BlockPos from the player by using the getPosition() method in the Entity class, and now the code runs like a charm.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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