Hey guys,
I managed to find chest nearby a custom entity that i had made but the problem is that sometimes it work, and sometimes it doesn't. I've been figuring out what is causing the problem but have no solution to it.
Here is the code:
public boolean findChest()
{
Vec3 vec = new Vec3(this.posX, this.posY, this.posZ);
xPos = vec.xCoord;
yPos = vec.yCoord;
zPos = vec.zCoord;
for (double x = xPos-10; x < xPos+10; x++)
{
for (double z = zPos-10; z < zPos+10; z++)
{
pos = new BlockPos(x, yPos, z);
if (this.worldObj.getBlockState(pos) == Blocks.chest.getDefaultState())
{
PathEntity path = this.getNavigator().getPathToXYZ(x, yPos, z);
this.getNavigator().setPath(path, 0.;
return true;
}
}
}
return false;
}
public void onUpdate()
{
super.onUpdate();
if(findChest())
{
System.out.println("Success!!");
}
}
It doesnt seem to go into this statement sometimes for some reason " if (this.worldObj.getBlockState(pos) == Blocks.chest.getDefaultState()) "
Any kind soul that can help?