Hello fellow coders,
I am writing a mod for Minecraft in 1.8 and have come across a pesky NullPointerException
with my throwable. In the code below, the EntityThrowable
uses an outer class to get the results of what will happen when thrown and the BlockPos
passed is from the getBlockPos()
method. This position is passed to the outer class where it transformed into x, y and z coords. However, whenever I throw the throwable, it throws an exception for these coordinates.
The difference between this question and the question of what is a NullPointerException is that the return value of what I am getting from the mov.getBlockPos()
(from a MovingObjectPosition
) is unknown. The MovingObjectPosition
assigns the coords of the BlockPos from a random class and the coder of the Throwable gets the results. I am using the results for the outer class. These results in the ints cause the game to crash from unknown coords. If you have any idea of how to get the end pos of the throwable, that would be appreciated.
Here's the code:
Throwable:
@Override
protected void onImpact(MovingObjectPosition mov) {
LuckyPotionItems lpi = new LuckyPotionItems();
EntityPlayer player = this.getThrower() instanceof EntityPlayer ? (EntityPlayer) this.getThrower() : null;
if(!worldObj.isRemote)
lpi.chooseUnluckyDrink(worldObj, player, mov.getBlockPos());
this.setDead();
}
Outer Class:
public void chooseUnluckyDrink(World w, EntityPlayer p, BlockPos pos){
Random r = w.rand;
int number = r.nextInt(13);
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
System.out.println("Unlucky Number = " + number);
Thanks for any help.